ATTENTION: We're still in a very early alpha version, the API may and will change frequently. Please, use it at your own risk, until we release version 1.0.
Maven:
<dependency>
<groupId>com.github.dgroup</groupId>
<artifactId>laconic-velocity</artifactId>
</dependency>
Gradle:
dependencies {
compile 'com.github.dgroup:laconic-velocity:<version>'
}
Generate the text/sql/xml/markdown/json/etc based on Apache Velocity template.
- Define velocity template
query.sql
inselect 1 from dual #if ($flag) union select 2 from dual #end
velocity $ tree ... |-- src | |-- main | | |-- ... | | | `-- test | |-- java | | `-- ... | `-- resources | `-- velocity | |-- ... | |-- query.sql | |-- ... ...
- Define instance of velocity template using
- full path to template
See more.
@Test public void transformSql() throws TemplateException { MatcherAssert.assertThat( new Text("query.sql", "src/test/resources/velocity").compose( new ArgOf("flag", true) ), Matchers.equalTo( "select 1 from dual\nunion\nselect 2 from dual\n" ) ); }
- hierarchical search
You can also specify the multiple roots (more).
@Test public void hierarchical() throws TemplateException { MatcherAssert.assertThat( new Text("query.sql", "src/test/resources").compose( new ArgOf("flag", true) ), Matchers.equalTo( "select 1 from dual\nunion\nselect 2 from dual\n" ) ); }
- classpath template
See more.
@Test public void classpath() throws TemplateException { MatcherAssert.assertThat( new Text(new RelativePath("velocity/query.sql")).compose( new ArgOf("flag", true) ), Matchers.equalTo( "select 1 from dual\nunion\nselect 2 from dual\n" ) ); }
- full path to template