Skip to content

Getting Started

Sassine El-Asmar edited this page Apr 25, 2022 · 4 revisions

There are currently two ways to use sqlschema2java:

  1. as a maven plugin sqlschema2java-maven-plugin
  2. directly from your code (embedded) using sqlschema2java-core

You can use sqlschema2java as a Maven plugin. Try at the sample project exemple

The Maven plugin

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>

Parameters

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

Run command

mvn dev.sassine.api:sqlschema2java-maven-plugin:generate

Using sqlschema2java within your Java project (embedded)

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());
	}

}

 
Clone this wiki locally