Skip to content
gourlaysama edited this page Aug 20, 2012 · 4 revisions

Welcome to the gdmsql-maven-plugin wiki!

This plugin allows building at compile time some SQL Scripts for use by Gdms.

Usage

Configuring the pom.xml

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>  

Use it

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.

Example:

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
  }
}

Plugin Details

Available goals

The plugin exposes two available goals, entirely identical except for the default input/output folders:

  • sqlCompile: compiles SQL sources in src/main/sql and saves then in target/classes. This goal is bound by default to the compile phase.
  • testSqlCompîle: compiles SQL sources in src/test/sql and saves then in target/test-classes. This goal is bound by default to the test-compile phase.

Customize folders

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>

Custom Flags

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.

Clone this wiki locally