Skip to content
Open
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
76 changes: 65 additions & 11 deletions core/src/test/resources/generic-case/sample-assert.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@
"ordinalPosition": 4,
"isNullable": "NO"
},
{
"tableCat": "TEST",
"tableSchem": "TEST_SCHEMA",
"tableName": "TEST_TABLE_1",
"columnName": "SOME_BOOL",
"dataType": 16,
"typeName": "BOOLEAN",
"columnSize": 1,
"decimalDigits": 0,
"nullable": 1,
"charOctetLength": 1,
"ordinalPosition": 5,
"isNullable": "YES"
},
{
"isLast": true,
"tableCat": "TEST",
Expand All @@ -77,7 +91,7 @@
"decimalDigits": 6,
"nullable": 0,
"charOctetLength": 26,
"ordinalPosition": 5,
"ordinalPosition": 6,
"isNullable": "NO"
}
],
Expand All @@ -101,7 +115,7 @@
"fktableCat": "TEST",
"fktableSchem": "TEST_SCHEMA",
"fktableName": "TEST_TABLE_2",
"fkcolumnName": "SIMPLE_ID_2",
"fkcolumnName": "SIMPLE_ID_1",
"keySeq": 1,
"updateRule": 1,
"deleteRule": 1,
Expand All @@ -121,7 +135,7 @@
"keySeq": 1,
"updateRule": 1,
"deleteRule": 1,
"fkName": "CONSTRAINT_DCFE",
"fkName": "CONSTRAINT_DCFE4",
"pkName": "CONSTRAINT_D",
"deferrability": 7,
"isLast": true
Expand Down Expand Up @@ -150,6 +164,21 @@
"ordinalPosition": 1,
"isNullable": "NO"
},
{
"tableCat": "TEST",
"tableSchem": "TEST_SCHEMA",
"tableName": "TEST_TABLE_2",
"columnName": "SIMPLE_ID_1",
"dataType": 4,
"typeName": "INTEGER",
"columnSize": 32,
"decimalDigits": 0,
"numPrecRadix": 2,
"nullable": 0,
"charOctetLength": 32,
"ordinalPosition": 2,
"isNullable": "NO"
},
{
"tableCat": "TEST",
"tableSchem": "TEST_SCHEMA",
Expand All @@ -161,7 +190,7 @@
"decimalDigits": 0,
"nullable": 1,
"charOctetLength": 50,
"ordinalPosition": 2,
"ordinalPosition": 3,
"isNullable": "YES"
},
{
Expand All @@ -176,7 +205,7 @@
"numPrecRadix": 10,
"nullable": 1,
"charOctetLength": 10,
"ordinalPosition": 3,
"ordinalPosition": 4,
"isNullable": "YES"
},
{
Expand All @@ -190,7 +219,7 @@
"decimalDigits": 0,
"nullable": 1,
"charOctetLength": 10,
"ordinalPosition": 4,
"ordinalPosition": 5,
"isNullable": "YES"
},
{
Expand All @@ -205,7 +234,7 @@
"decimalDigits": 6,
"nullable": 1,
"charOctetLength": 26,
"ordinalPosition": 5,
"ordinalPosition": 6,
"isNullable": "YES"
}
],
Expand Down Expand Up @@ -233,7 +262,7 @@
"keySeq": 1,
"updateRule": 1,
"deleteRule": 1,
"fkName": "CONSTRAINT_DCFE4",
"fkName": "CONSTRAINT_DCFE4D",
"pkName": "CONSTRAINT_DC",
"deferrability": 7,
"isLast": true
Expand All @@ -250,7 +279,7 @@
"tableCat": "TEST",
"tableSchem": "TEST_SCHEMA",
"tableName": "TEST_TABLE_3",
"columnName": "SIMPLE_ID_1",
"columnName": "SIMPLE_ID_3",
"dataType": 4,
"typeName": "INTEGER",
"columnSize": 32,
Expand All @@ -261,6 +290,21 @@
"ordinalPosition": 1,
"isNullable": "NO"
},
{
"tableCat": "TEST",
"tableSchem": "TEST_SCHEMA",
"tableName": "TEST_TABLE_3",
"columnName": "SIMPLE_ID_1",
"dataType": 4,
"typeName": "INTEGER",
"columnSize": 32,
"decimalDigits": 0,
"numPrecRadix": 2,
"nullable": 0,
"charOctetLength": 32,
"ordinalPosition": 2,
"isNullable": "NO"
},
{
"isLast": true,
"tableCat": "TEST",
Expand All @@ -274,11 +318,21 @@
"numPrecRadix": 2,
"nullable": 0,
"charOctetLength": 32,
"ordinalPosition": 2,
"ordinalPosition": 3,
"isNullable": "NO"
}
],
"primaryKey": [],
"primaryKey": [
{
"isLast": true,
"tableCat": "TEST",
"tableSchem": "TEST_SCHEMA",
"tableName": "TEST_TABLE_3",
"columnName": "SIMPLE_ID_3",
"keySeq": "1",
"pkName": "CONSTRAINT_DCFE"
}
],
"foreignKeys": []
}
],
Expand Down
9 changes: 6 additions & 3 deletions core/src/test/resources/generic-case/sample.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ CREATE SCHEMA IF NOT EXISTS test_schema;
SET SCHEMA test_schema;

CREATE TABLE IF NOT EXISTS test_schema.test_table_1 (
simple_id_1 INT PRIMARY KEY,
simple_id_1 INT AUTO_INCREMENT PRIMARY KEY,
test_varchar VARCHAR(50) NOT NULL,
test_numeric NUMERIC(10,2) NOT NULL,
test_date DATE NOT NULL,
some_bool BOOLEAN,
test_datetime TIMESTAMP NOT NULL
);
COMMENT ON TABLE test_schema.test_table_1 IS 'test_table_1 description';

CREATE TABLE IF NOT EXISTS test_schema.test_table_2 (
simple_id_2 INT PRIMARY KEY,
simple_id_2 INT AUTO_INCREMENT PRIMARY KEY,
simple_id_1 INT NOT NULL,
test_varchar VARCHAR(50),
test_numeric NUMERIC(10,2),
test_date DATE,
test_datetime TIMESTAMP,
FOREIGN KEY (simple_id_2) REFERENCES test_schema.test_table_1(simple_id_1)
FOREIGN KEY (simple_id_1) REFERENCES test_schema.test_table_1(simple_id_1)
);
COMMENT ON COLUMN test_schema.test_table_2.simple_id_2 IS 'this is table2 id';

CREATE TABLE IF NOT EXISTS test_schema.test_table_3 (
simple_id_3 INT AUTO_INCREMENT PRIMARY KEY,
simple_id_1 INT NOT NULL,
simple_id_2 INT NOT NULL,
FOREIGN KEY (simple_id_1) REFERENCES test_schema.test_table_1(simple_id_1),
Expand Down
20 changes: 17 additions & 3 deletions core/src/test/resources/generic-case/table-filter.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@
"ordinalPosition": 4,
"isNullable": "NO"
},
{
"tableCat": "TEST",
"tableSchem": "TEST_SCHEMA",
"tableName": "TEST_TABLE_1",
"columnName": "SOME_BOOL",
"dataType": 16,
"typeName": "BOOLEAN",
"columnSize": 1,
"decimalDigits": 0,
"nullable": 1,
"charOctetLength": 1,
"ordinalPosition": 5,
"isNullable": "YES"
},
{
"isLast": true,
"tableCat": "TEST",
Expand All @@ -77,7 +91,7 @@
"decimalDigits": 6,
"nullable": 0,
"charOctetLength": 26,
"ordinalPosition": 5,
"ordinalPosition": 6,
"isNullable": "NO"
}
],
Expand All @@ -101,7 +115,7 @@
"fktableCat": "TEST",
"fktableSchem": "TEST_SCHEMA",
"fktableName": "TEST_TABLE_2",
"fkcolumnName": "SIMPLE_ID_2",
"fkcolumnName": "SIMPLE_ID_1",
"keySeq": 1,
"updateRule": 1,
"deleteRule": 1,
Expand All @@ -121,7 +135,7 @@
"keySeq": 1,
"updateRule": 1,
"deleteRule": 1,
"fkName": "CONSTRAINT_DCFE",
"fkName": "CONSTRAINT_DCFE4",
"pkName": "CONSTRAINT_D",
"deferrability": 7,
"isLast": true
Expand Down
50 changes: 50 additions & 0 deletions java-pojo-generator-mojo-example/hibernate.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package {{package}};

import jakarta.persistence.*;
import java.util.List;

/** {{rawTable.remarks}}
{{rawTable.tableCat}}.{{rawTable.tableSchem}}.{{rawTable.tableName}}{{#generationInfo}}

{{generationInfo}}{{/generationInfo}}
*/
@Entity
@Table(schema = "{{rawTable.tableSchem}}", name = "{{rawTable.tableName}}")
public class {{className}} {
{{#properties}}

{{#isRelational}}
{{#isManyToOne}}
@ManyToOne
@JoinColumn(name = "{{rawColumn.columnName}}") {{^isNullable}}@jakarta.validation.constraints.NotNull{{/isNullable}}
private {{propertyType}} {{propertyName}};
{{/isManyToOne}}
{{#isOneToMany}}
@OneToMany(mappedBy = "{{mappedBy}}", cascade = CascadeType.ALL, orphanRemoval = true)
private List<{{propertyType}}> {{propertyName}};
{{/isOneToMany}}
{{/isRelational}}
{{^isRelational}}
/** {{rawColumn.remarks}}
{{rawColumn.columnName}} {{rawColumn.typeName}}({{rawColumn.columnSize}}) Nullable={{rawColumn.isNullable}}
*/
@Column("{{rawColumn.columnName}}") {{#isId}}@Id @GeneratedValue(strategy = GenerationType.IDENTITY){{/isId}}{{^isNullable}}

@jakarta.validation.constraints.NotNull{{/isNullable}}{{#size}}

@jakarta.validation.constraints.Size(max = {{size}}){{/size}}
private {{propertyType}} {{propertyName}};
{{/isRelational}}
{{/properties}}
{{#properties}}

public {{propertyType}} get{{methodName}}() {
return {{propertyName}};
}

public void set{{methodName}}({{propertyType}} {{propertyName}}) {
this.{{propertyName}} = {{propertyName}};
}

{{/properties}}
}
37 changes: 18 additions & 19 deletions java-pojo-generator-mojo-example/init.sql
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
CREATE SCHEMA IF NOT EXISTS test_schema;
SET SCHEMA test_schema;

CREATE TABLE IF NOT EXISTS test_schema.test_table_1
(
simple_id_1 INT AUTO_INCREMENT PRIMARY KEY,
test_varchar VARCHAR(50) NOT NULL,
test_numeric NUMERIC(10, 2) NOT NULL,
test_date DATE NOT NULL,
some_bool BOOLEAN ,
test_datetime TIMESTAMP NOT NULL
CREATE TABLE IF NOT EXISTS test_schema.test_table_1 (
simple_id_1 INT AUTO_INCREMENT PRIMARY KEY,
test_varchar VARCHAR(50) NOT NULL,
test_numeric NUMERIC(10,2) NOT NULL,
test_date DATE NOT NULL,
some_bool BOOLEAN,
test_datetime TIMESTAMP NOT NULL
);
COMMENT ON TABLE test_schema.test_table_1 IS 'test_table_1 description';

CREATE TABLE IF NOT EXISTS test_schema.test_table_2
(
simple_id_2 INT AUTO_INCREMENT PRIMARY KEY,
test_varchar VARCHAR(50),
test_numeric NUMERIC(10, 2),
test_date DATE,
CREATE TABLE IF NOT EXISTS test_schema.test_table_2 (
simple_id_2 INT AUTO_INCREMENT PRIMARY KEY,
simple_id_1 INT NOT NULL,
test_varchar VARCHAR(50),
test_numeric NUMERIC(10,2),
test_date DATE,
test_datetime TIMESTAMP,
FOREIGN KEY (simple_id_2) REFERENCES test_schema.test_table_1 (simple_id_1)
FOREIGN KEY (simple_id_1) REFERENCES test_schema.test_table_1(simple_id_1)
);
COMMENT ON COLUMN test_schema.test_table_2.simple_id_2 IS 'this is table2 id';

CREATE TABLE IF NOT EXISTS test_schema.test_table_3
(
CREATE TABLE IF NOT EXISTS test_schema.test_table_3 (
simple_id_3 INT AUTO_INCREMENT PRIMARY KEY,
simple_id_1 INT NOT NULL,
simple_id_2 INT NOT NULL,
FOREIGN KEY (simple_id_1) REFERENCES test_schema.test_table_1 (simple_id_1),
FOREIGN KEY (simple_id_2) REFERENCES test_schema.test_table_2 (simple_id_2)
FOREIGN KEY (simple_id_1) REFERENCES test_schema.test_table_1(simple_id_1),
FOREIGN KEY (simple_id_2) REFERENCES test_schema.test_table_2(simple_id_2)
);

CREATE ALIAS IF NOT EXISTS NEXT_PRIME AS '
Expand Down
17 changes: 17 additions & 0 deletions java-pojo-generator-mojo-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@
<artifactId>spring-boot-starter-jdbc</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down Expand Up @@ -60,6 +65,18 @@
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.2.4.Final</version>
</dependency>

<!-- Jakarta Persistence API -->
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Loading
Loading