-
-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Sassine El-Asmar edited this page Apr 10, 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</version>
<executions>
<execution>
<goals>
<goal>sqlschema2java</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>
<repositories>
<repository>
<id>github</id>
<name>GitHub Packages SQLSchema2Java</name>
<url>https://maven.pkg.github.com/Sassine/sqlschema2java</url>
</repository>
</repositories>| 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:generateTo 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>${sqlschema2java-core.version}</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>github</id>
<name>GitHub Packages SQLSchema2Java</name>
<url>https://maven.pkg.github.com/Sassine/sqlschema2java</url>
</repository>
</repositories>To use the sqlschema2java generator in your code:
// package ...;
import java.io.FileNotFoundException;
import dev.sassine.api.structure.Sqlschema2Java;
public class Main {
public static void main(final String[] args) throws FileNotFoundException {
String sourceDirectory = Main.class.getResource("/demo.sql").getPath();
String packageName = "dev.sassine.api.structure.default";
boolean useAutoGenerated = false;
boolean isPostgress = false;
Sqlschema2Java.generate(sourceDirectory, isPostgress, useAutoGenerated, packageName);
}
}