-
-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Sassine El-Asmar edited this page Apr 25, 2022
·
4 revisions
There are currently two ways to use sqlschema2java:
- as a maven plugin sqlschema2java-maven-plugin
- directly from your code (embedded) using sqlschema2java-core
You can use sqlschema2java as a Maven plugin. Try at the sample project exemple
edit your pom.xml
to include the following in the section:
<plugins>
<plugin>
<groupId>dev.sassine.api</groupId>
<artifactId>sqlschema2java-maven-plugin</artifactId>
<version>1.0.0-beta</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>/user/home/example.sql</sourceDirectory>
<packageName>dev.sassine.api</packageName>
<useAutoIncrement>true</useAutoIncrement>
<isPostgres>false</isPostgres>
</configuration>
</plugin>
</plugins>
Name | required | type | description |
---|---|---|---|
sourceDirectory | true | String | SQL file path |
packageName | true | String | package name with points that will be generated |
useAutoIncrement | false | Boolean | disable or enable whether the primary key will have its value generated automatically |
isPostgres | true | Boolean | disable or enable query conversion compatible with postgres database |
mvn dev.sassine.api:sqlschema2java-maven-plugin:generate
To use the sqlschema2java-core API directly from a Java application you'll need to add the sqlschema2java-core
jar to your build path.
You can obtain this by downloading the latest jar or by adding the following dependency to your Maven project:
<dependencies>
<dependency>
<groupId>dev.sassine.api</groupId>
<artifactId>sqlschema2java-core</artifactId>
<version>1.0.0-beta</version>
</dependency>
</dependencies>
To use the sqlschema2java generator in your code:
// package ...;
import static dev.sassine.api.structure.Sqlschema2Java.generate;
import static java.nio.file.Paths.get;
import java.io.FileNotFoundException;
import dev.sassine.api.structure.model.java.EnvironmentModel;
public class Main {
public static void main(final String[] args) throws FileNotFoundException {
generate(EnvironmentModel.builder()
.packageName("dev.sassine.api.structure.generated")
.sourceDirectory(get("src","test","resources","default.sql").toFile().getAbsolutePath())
.build());
}
}