SQLComments comes with maven plugin to speed-up development and to preserve type safety in Java code.
There are three goals:
- export - moves SQL statements from comments in Java sources to separate sql files
- generate - from sql files it generates result, configuration and mapper classes
- domain - generates domain, configuration and mapper classes for basic CRUD operations from database tables or views
Export goal
Moves SQL statements from comments in Java sources to separate .sql files. Each statement is placed in separate file. Statement starts with @SQLComment annotation and ends at first empty line, hence it is possible to keep more statements in one Java comments.
Configuration parameters:
Property | Description |
sourceDirectory | The directory which contains the sources you want to be parsed. Default: ${project.build.sourceDirectory} |
outputDirectory | The output directory where to generate files and java classes. Default: ${project.build.directory}/generated-sources/sqlcomments |
includes | A list of files to include. Can contain ant-style wildcards and double wildcards. Default: **/*.java |
excludes | A list of files to exclude. Can contain ant-style wildcards and double wildcards. |
compileWithTestClasses | Indicates whether to use standard or test class path for compilation of generated classes. Default: false - using standard class path. |
Generate goal
According to database model it generates result, configuration and mapper classes from SQL statements.
Configuration parameters:
Property | Description |
sourceDirectory | The directory which contains the *.sql files you want to be parsed. Default: ${project.build.directory}/generated-sources/sqlcomments |
outputDirectory | The output directory where to generate files and java classes. Default: ${project.build.directory}/generated-sources/sqlcomments |
includes | A list of files to include. Can contain ant-style wildcards and double wildcards. Default: **/*.sql |
excludes | A list of files to exclude. Can contain ant-style wildcards and double wildcards. |
compileWithTestClasses | Indicates whether to use standard or test class path for compilation of generated classes. Default: false - using standard class path. |
databaseDialect | Database dialect class used to translate database data types into Java types. Default: sk.vracon.sqlcomments.maven.DefaultDatabaseDialect |
jdbcDriverClass | JDBC driver class name. Class must be included in plugin dependendcies. |
databaseUrl | Database URL. |
dbUserName | Database credentials - username. |
dbPassword | Database credentials - password. |
Domain goal
Generates domain, configuration and mapper classes for basic CRUD operations from database tables or views. Domain class is in fact a result class of findByPK statement. Classes generated by this goal are used by AbstractSQLCommentsRepository (see Spring integration for more).
Class names are generated from table names by removing table prefix and making name camel case.
Configuration parameters:
Property | Description |
outputDirectory | The output directory where to generate files and java classes. Default: ${project.build.directory}/generated-sources/sqlcomments |
compileWithTestClasses | Indicates whether to use standard or test class path for compilation of generated classes. Default: false - using standard class path. |
tables | A list of tables to include. Map consists of pairs <table name> - <table properties>. Properties are in form Properties. Currently supported properties: - pkGenerator - sequence call or other statement to use in generated insert statements instead of PK column |
tablePrefix | A table prefix to be removed when creating domain class name. |
packageName | Target package name where generate classes. |
databaseDialect | Database dialect class used to translate database data types into Java types. Default: sk.vracon.sqlcomments.maven.DefaultDatabaseDialect |
jdbcDriverClass | JDBC driver class name. Class must be included in plugin dependendcies. |
databaseUrl | Database URL. |
dbUserName | Database credentials - username. |
dbPassword | Database credentials - password. |
Configuration for tests
Maven distinguish between main and test classpath. It is necessary to configure plugins separatelly for tests.