Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>sqlschema2java</artifactId>
<version>1.0.0-beta1</version>
<version>1.0.0-beta</version>
<name>sqlschema2java</name>
<packaging>pom</packaging>
<groupId>dev.sassine.api</groupId>
Expand Down
60 changes: 36 additions & 24 deletions 60 sqlschema2java-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>dev.sassine.api</groupId>
<artifactId>sqlschema2java-core</artifactId>
<version>1.0.0-beta1</version>
<version>1.0.0-beta</version>
<name>sqlschema2java-core</name>

<description>Auto generate Class DTO, Entity and Repository from SQL Query. </description>
Expand All @@ -18,6 +18,19 @@
<jacoco-maven-plugin.version>0.8.8</jacoco-maven-plugin.version>
<copyright.holder>Sassine El-Asmar</copyright.holder>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<antlr4.version>4.3</antlr4.version>
<pitest.version>1.7.5</pitest.version>
<maven-resources.version>3.2.0</maven-resources.version>
<maven-compiler>3.10.1</maven-compiler>
<jax.version>2.3.1</jax.version>
<logback.version>1.2.11</logback.version>
<burningwave.version>12.47.0</burningwave.version>
<lombok.version>1.18.22</lombok.version>
<spring-jpa.version>2.6.6</spring-jpa.version>
<commons-text.version>1.9</commons-text.version>
<jackson.version>2.13.2</jackson.version>
<log4j.version>2.17.2</log4j.version>
<junit-4.version>4.13.2</junit-4.version>
</properties>

<developers>
Expand Down Expand Up @@ -64,7 +77,7 @@
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.7.5</version>
<version>${pitest.version}</version>
<configuration>
<targetClasses>
<param>dev.sassine.api.structure.export.*</param>
Expand All @@ -87,7 +100,7 @@
<plugin>
<groupId>org.antlr</groupId>
<artifactId>antlr4-maven-plugin</artifactId>
<version>4.3</version>
<version>${antlr4.version}</version>
<executions>
<execution>
<id>antlr</id>
Expand All @@ -100,19 +113,19 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<version>${maven-resources.version}</version>
<configuration>
<encoding>UTF-8</encoding>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>${maven-compiler}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>11</source>
<target>11</target>
<encoding>${project.build.sourceEncoding}</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
Expand All @@ -128,7 +141,7 @@
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
<version>${jax.version}</version>
</dependency>
</dependencies>
</plugin>
Expand Down Expand Up @@ -166,37 +179,36 @@
</plugins>
</build>


<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.3</version>
<version>${antlr4.version}</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
<version>${logback.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.burningwave</groupId>
<artifactId>core</artifactId>
<version>12.47.0</version>
<version>${burningwave.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<version>${lombok.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>2.4.2</version>
<version>${spring-jpa.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
Expand Down Expand Up @@ -236,51 +248,51 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
<version>${commons-text.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.2</version>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.2</version>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.2.2</version>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.13.2</version>
<version>${jackson.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<version>${junit-4.version}</version>
<scope>test</scope>
</dependency>


<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.17.2</version>
<version>${log4j.version}</version>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.17.2</version>
<version>${log4j.version}</version>
</dependency>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package dev.sassine.api.structure;

import static dev.sassine.api.structure.Sqlschema2Java.generate;
import static dev.sassine.api.structure.model.java.EnvironmentModel.builder;
import static java.nio.file.Paths.get;

import java.io.FileNotFoundException;

public class Main {

public static void main(final String[] args) throws FileNotFoundException {
Sqlschema2Java.generate("C:\\poc\\poc.sql", false, false,"dev.sassine.api.structure.delete");
generate(builder()
.packageName("dev.sassine.api.structure.generated")
.sourceDirectory(get("src","test","resources","default.sql").toFile().getAbsolutePath())
.build());
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,31 @@

import dev.sassine.api.structure.export.builder.ClassSourceBuilder;
import dev.sassine.api.structure.model.java.EntityModel;
import dev.sassine.api.structure.model.java.EnvironmentModel;
import dev.sassine.api.structure.model.sql.Database;
import dev.sassine.api.structure.parser.SqlImport;

public class Sqlschema2Java {

private static final Logger log = getLogger();

public static void generate(String inputFile, boolean isPostgress, boolean isAutoGenerated, String packageName) {
log.debug("preparing to read SQL file('{}') ", inputFile);
try (InputStream in = new FileInputStream(inputFile)) {
public static void generate(EnvironmentModel env) {
log.debug("preparing to read SQL file('{}') ", env.getSourceDirectory());
try (InputStream in = new FileInputStream(env.getSourceDirectory())) {
log.debug("file read successfull");
log.debug("Parameters ::: isPostgress: {} | isAutoGenerated: {} | packageName: {}", isPostgress, isAutoGenerated, packageName);
process(read(in), isPostgress, isAutoGenerated, packageName);
process(read(in), env);
log.info("Congratulations build successful [√]");
} catch (final Exception e) {
log.error(e.getMessage(), e);
}
}

private static void process(final String sqlContent, boolean isPostgress, boolean isAutoGenerated, String packageName) {
private static void process(final String sqlContent, EnvironmentModel env) {
final Database database = SqlImport.init().getDatabase(sqlContent);
convertTypeFromSQLDataBaseToEntityStore(database, isPostgress);
convertTypeFromSQLDataBaseToEntityStore(database, env.getUsePostgreSQL());
validate(database);
List<EntityModel> entityModel = convert(database);
ClassSourceBuilder.init().build(entityModel, isAutoGenerated, packageName);
ClassSourceBuilder.init().build(entityModel, env.getUseAutoIncrement(), env.getPackageName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@ public static ClassSourceBuilder init() {
return new ClassSourceBuilder();
}

public void build(List<EntityModel> entityModel, boolean isAutoGenerated, String packageName) {
log.debug("Starting build Class Source");
entityModel.forEach(e -> build(e, isAutoGenerated, packageName));
public void build(List<EntityModel> entityModel, boolean useAutoGenerated, String packageName) {
log.debug("Starting build Class Source ");
log.debug("Parameters ::: isAutoGenerated: {} | PackageName {}", useAutoGenerated, packageName);
entityModel.forEach(e -> build(e, useAutoGenerated, packageName));
}

private void build(EntityModel entityModel,boolean isAutoGenerated, String packageName) {
private void build(EntityModel entityModel,boolean useAutoGenerated, String packageName) {
String nameClass = toCamelCase(entityModel.getName(), true, CHAR);
createEntity().execute(entityModel, isAutoGenerated, nameClass, packageName);
createDTO().execute(entityModel, isAutoGenerated, nameClass, packageName);
createRepository().execute(entityModel, isAutoGenerated, nameClass, packageName);
createEntity().execute(entityModel, useAutoGenerated, nameClass, packageName);
createDTO().execute(entityModel, useAutoGenerated, nameClass, packageName);
createRepository().execute(entityModel, useAutoGenerated, nameClass, packageName);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.sassine.api.structure.model.java;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Builder
public class EnvironmentModel {

private String sourceDirectory;

private String packageName;

@Builder.Default
private Boolean usePostgreSQL = false;

@Builder.Default
private Boolean useAutoIncrement = true;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class TypeConverter {
public static final String TYPE_LOCAL_TIME = "LocalTime";

public static void convertTypeFromSQLDataBaseToEntityStore(final Database database, boolean isPostgress) {
log.debug("Parameters ::: isPostgress: {} ",isPostgress);
database.getTables().forEach(table -> {
table.getColumnByNames().values().forEach(column -> {
column.setConvertedType(convertTypeFromSQLToEntityStore(ofNullable(column.getType()).orElse(""), isPostgress));
Expand Down
12 changes: 12 additions & 0 deletions 12 sqlschema2java-core/src/test/resources/default.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE Company (
id INT NOT NULL AUTO_INCREMENT,
duns VARCHAR(9) UNIQUE,
name VARCHAR(255),
address VARCHAR(255),
zip_code VARCHAR(5) DEFAULT '',
company_creation Date DEFAULT CURRENT_TIMESTAMP,
website VARCHAR(255),
phone_number VARCHAR(255),
city VARCHAR(255),
PRIMARY KEY(id)
);
15 changes: 8 additions & 7 deletions 15 sqlschema2java-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>dev.sasine.api</groupId>
<artifactId>sqlschema2java-example</artifactId>
<version>1.0.0-beta1</version>
<version>1.0.0-beta</version>
<packaging>pom</packaging>

<developers>
Expand All @@ -22,9 +22,10 @@
</developers>

<properties>
<is.postgres>false</is.postgres>
<use.postgresDB>false</use.postgresDB>
<auto.increment.enabled>false</auto.increment.enabled>
<path.arquivo>./input.sql</path.arquivo>
<path.sqlFile>./input.sql</path.sqlFile>
<packageName>dev.sassine.generated</packageName>
</properties>


Expand All @@ -33,7 +34,7 @@
<plugin>
<groupId>dev.sassine.api</groupId>
<artifactId>sqlschema2java-maven-plugin</artifactId>
<version>1.0.0-beta1</version>
<version>1.0.0-beta</version>
<executions>
<execution>
<goals>
Expand All @@ -42,10 +43,10 @@
</execution>
</executions>
<configuration>
<isPostgres>${is.postgres}</isPostgres>
<sourceDirectory>${path.arquivo}</sourceDirectory>
<usePostgreSQL>${use.postgresDB}</usePostgreSQL>
<sourceDirectory>${path.sqlFile}</sourceDirectory>
<packageName>${packageName}</packageName>
<useAutoIncrement>${auto.increment.enabled}</useAutoIncrement>
<debugEnabled>false</debugEnabled>
</configuration>
</plugin>
</plugins>
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.