Barnacle is an ultra-lightweight object-relational mapping tool (ORM-tool) for Java. Based on annotated classes, it features generation of value-objects (VOs), data-access-objects (DAOs) and SQL-scripts for schema creation. Generated SQL is designed to be compatible at least with MySQL.
Barnacle uses no reflection on runtime. Generated classes can be applied without any runtime dependencies back to Barnacle. Optionally, barnacle can be referenced on runtime to take advantage of a built-in JDBC connection provider.
Under development. Applicable for restricted use cases. Simply check whether generated classes suit your requirements. Good luck!
For gradle or maven builds, Barnacle can be obtained from jitpack. In gradle builds, add jitpack to the list of your repositories and add the following dependency declaration:
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
dependencies {
implementation 'com.github.arthurpicht:Barnacle:master-SNAPSHOT'
}
Use master-SNAPSHOT
for the latest development version or v0.2.0
for the latest release.
-
Clone repository.
$ git clone git@github.com:arthurpicht/Barnacle.git
or
$ git clone https://github.com/arthurpicht/Barnacle.git
-
Build Barnacle with gradle:
$ gradle jar
Resulting JAR can be found in Barnacle/build/libs.
In order to prepare Barnacle to be used as a command line tool, build Barnacle as described and proceed the following steps.
-
By calling
$ gradle tool
all dependent JARs will be copied to Barnacle/bin/libs
-
Put
Barnacle\bin
on your PATH. -
Configure barnacle.conf, including the [generator] section.
-
In order to test call
$ barnacle --help
Based on the previous steps, Barnacle can be included into gradle build of your own project as simple as that:
task barnacle(type: Exec) {
mkdir "$buildDir/sql"
commandLine "barnacle", "generate"
}
Or a little more elaborate example:
task barnacle(type: Exec) {
inputs.dir("$rootDir/src/main/java/path/to/vof")
inputs.file("$rootDir/path/to/barnacle.conf")
outputs.dir("$rootDir/src/main/generated")
outputs.dir("$buildDir/sql")
mkdir "$buildDir/sql"
commandLine "barnacle", "--verbose", "--configfile", "$projectDir/path/to/barnacle.conf", "generate"
}
parameter | description | default |
---|---|---|
dialect | SQL dialect. One of MYSQL or H2 |
MYSQL |
src_dir | source dirctory for VOF files | src/ |
src_gen_dir | source direcory for generated files | src-gen/ |
vof_package_name | package name for VOF files | mandatory |
vo_package_name | package name for VO files | mandatory |
vob_package_name | package name for VOB files | mandatory |
dao_package_name | package name for DAO files | mandatory |
execute_on_db | create resulting schema on DB | false |
create_script | create SQL script | false |
create_script | create SQL script | false |
script_file | name of SQL script file | barnacle.sql |
encoding_db | encoding for database contents. One of ISO , UTF or DEFAULT . |
DEFAULT |
encoding_source | encoding for generated java sources. One of ISO , UTF or DEFAULT . |
ISO |
encoding_source | encoding for generated java sources. One of ISO , UTF or DEFAULT . |
ISO |
connection_manager_class | canonical class name of custom connection manager class. If not set internal class is used. | internal |
connection_exception_class | canonical class name of custom connection exception class. If not set internal class is used. | internal |
entity_not_found_exception_class | canonical class name of custom entity not found exception class. If not set internal class is used. | internal |
doa_logger_name | name of logger used in generated DAO classes. | |
omit_javadoc | Omit generation of any javadoc comment in generated classes. This can be useful if generated code is subject to tests as javadoc contains a timestamp. | false |
to be completed
Simple marker annotation. Marks class to be processed by barnacle.
The resulting VO implements the Cloneable
interface and will contain a clone
method.
No parameters.
The resulting VO implements the Serializable
interface and will contain a private constant serialVersionUID
.
Parameter:
- serialVersionUID of type long
Example:
@SerializableVo(
serialVersionUID = 42L
)
In order to make generated VO classes serializable do the following:
- Let the upper VOF class implement the
Serializable
interface - Implement a
private static final long serialVersionUID
in the VOF class - Annotate the VOF class with the
SerializableVo
annotation and give an appropriateserialVersionUID
parameter. As a result, the generated VO class will contain a corresponding attribute.
TO BE COMPLETED
The classes generated by barnacle depend on SLF4j.
If no custom connection manager class is specified, resulting files will also depend on barnacle.jar.