The SQLComments Maven plugin speeds up development and preserves type safety in Java code.
There are three goals:
- export - moves SQL statements from comments in Java sources to separate SQL files
- generate - generates result, configuration and mapper classes from SQL files
- domain - generates domain, configuration and mapper classes for basic CRUD operations from database tables or views
Export goal
It moves the SQL statements from the comments in the Java source code files into separate .sql files. Each statement is placed in a separate file. The statement starts with the @SQLComment annotation and ends at the first empty line. Therefore, it is possible to keep multiple statements within one Java comment.
Configuration parameters:
| Property | Description |
| sourceDirectory | The directory which contains the sources to be parsed. Default: ${project.build.sourceDirectory} |
| outputDirectory | The output directory for generated files and java classes. Default: ${project.build.directory}/generated-sources/sqlcomments |
| includes | A list of files to include. Ant-style wildcards and double wildcards are supported. Default: **/*.java |
| excludes | A list of files to exclude. Ant-style wildcards and double wildcards are supported. |
| compileWithTestClasses | This indicates whether the standard or test classpath should be used to compile the generated classes. Default: false - using standard classpath. |
Generate goal
According to the database model it generates result, configuration and mapper classes from the SQL statements.
Configuration parameters:
| Property | Description |
| sourceDirectory | The directory which contains the *.sql files to be parsed. Default: ${project.build.directory}/generated-sources/sqlcomments |
| outputDirectory | The output directory for generated files and java classes. Default: ${project.build.directory}/generated-sources/sqlcomments |
| includes | A list of files to include. Ant-style wildcards and double wildcards are supported. Default: **/*.sql |
| excludes | A list of files to exclude. Ant-style wildcards and double wildcards are supported. |
| compileWithTestClasses | This indicates whether the standard or test classpath should be used to compile the generated classes. Default: false - using standard classpath. |
| databaseDialect | Database dialect class used to translate database data types into Java types. Default: sk.vracon.sqlcomments.core.dialect.HSQLDialect |
| 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
It generates domain, configuration and mapper classes required for basic CRUD operations from database tables or views. The domain class is in fact the result class of the findByPK statement. The classes generated by this goal are used by the AbstractSQLCommentsRepository (see Spring integration for more).
The class name is generated from the table name by removing the table prefix and converting the name to camelCase.
Configuration parameters:
| Property | Description | ||||||||||
| outputDirectory | The output directory for generated files and java classes. Default: ${project.build.directory}/generated-sources/sqlcomments |
||||||||||
| compileWithTestClasses | This indicates whether the standard or test classpath should be used to compile the generated classes. Default: false - using standard classpath. |
||||||||||
| tables | A list of tables to include. Map consists of pairs <table name> - <table properties>. Properties can be used to create a fine-grained configuration of table columns and their mappings. Properties are in form java.util.Properties. Currently supported properties:
|
||||||||||
| mappingFiles | List of xml files containing table configurations. Content of configuration is the same as defined in the tables parameter wrapped in <sqlcomments> element. E.g.
<sqlcomments>
<USERS />
<COMPANIES>
id.type=sk.vracon.sqlcomments.types.LongType
country.type=sk.vracon.sqlcomments.types.EnumType(sk.vracon.sqlcomments.maven.ExampleEnum)
</COMPANIES>
<DOCUMENTS />
</sqlcomments>
|
||||||||||
| tablePrefix | A table prefix to be removed when creating domain class name. | ||||||||||
| packageName | Target package name for generated classes. | ||||||||||
| databaseDialect | Database dialect class used to translate database data types into Java types. Default: sk.vracon.sqlcomments.core.dialect.HSQLDialect |
||||||||||
| jdbcDriverClass | JDBC driver class name. Class must be listed in plugin dependendcies. |
||||||||||
| databaseUrl | Database URL. | ||||||||||
| dbUserName | Database credentials - username. | ||||||||||
| dbPassword | Database credentials - password. |
Configuration for tests
Maven distinguishes between main and test classpaths. It is necessary to configure the plugins separately for tests.