-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the gdmsql-maven-plugin wiki!
This plugin allows building at compile time some SQL Scripts for use by Gdms.
Add the plugin to your pom.xml:
<plugin>
<groupId>org.gdms.maven</groupId>
<artifactId>gdmsql-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<executions>
<execution>
<id>sql</id>
<goals>
<goal>sqlCompile</goal>
</goals>
</execution>
<!-- the second execution below is not necessary if you do not have sql script in your tests sources -->
<execution>
<id>test-sql</id>
<goals>
<goal>testSqlCompile</goal>
</goals>
</execution>
</executions>
</plugin>
The plugin is available from the IRSTV repository, so you will probably also need to add it as well:
<repositories>
<repository>
<id>IRSTV</id>
<name>IRSTV repository</name>
<url>http://repo.orbisgis.org</url>
</repository>
...
</repositories>
Just place SQL sources in the folders:
-
src/main/sql
for the main goal -
src/test/sql
for the test goal
The plugin will build the .sql
files it finds, and create resources with the same name but the extension .bsql
. These can then be loaded from the code without the original SQL source.
Note that the build is incremental: if there already is a target compiled script and the source is not newer than the target, it is not recompiled.
Place the script below in src/main/sql/org/hello/helloScript.sql
:
CREATE TABLE hello AS SELECT 42, 'hi!';
From your java code, do:
package org.hello;
import org.gdms.sql.engine.Engine;
import org.gdms.sql.engine.SQLScript;
public class SomeClass {
public void doSomething(DataSourceFactory dsf) {
SQLScript s = Engine.load(SomeClass.class.getResourceAsStream("helloScript.bsql"));
s.setDataSourceFactory(dsf);
s.execute();
// table 'hello' has been created
}
}
The plugin exposes two available goals, entirely identical except for the default input/output folders:
-
sqlCompile
: compiles SQL sources insrc/main/sql
and saves then intarget/classes
. This goal is bound by default to thecompile
phase. -
testSqlCompîle
: compiles SQL sources insrc/test/sql
and saves then intarget/test-classes
. This goal is bound by default to thetest-compile
phase.
Input and output folder can be changed the same way for both goals:
<configuration>
<sqlScriptsDirectory>src/my-sql-files/</sqlScriptsDirectory>
<outputDirectory>target/my-compiled-sql/</outputDirectory>
</configuration>
Gdms has several flags that can influence its behavior. You can change these flags with the engineProperties
configuration element.
For example, to enable verbose output of the parsing of file:
<configuration>
<engineProperties>
<property>
<name>output.explain</name>
<value>true</value>
</property>
</engineProperties>
</configuration>
See the full list of flags (with their default values) for details.