From a30d01a263145d2b97004351da442d503733af3c Mon Sep 17 00:00:00 2001 From: Kurt Niemi Date: Wed, 5 Apr 2023 09:02:19 -0400 Subject: [PATCH 1/7] 1478 - Prepare branch --- pom.xml | 2 +- spring-data-jdbc-distribution/pom.xml | 2 +- spring-data-jdbc/pom.xml | 4 ++-- spring-data-r2dbc/pom.xml | 4 ++-- spring-data-relational/pom.xml | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index ec73fb59c9..2c77685644 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.springframework.data spring-data-relational-parent - 3.1.0-SNAPSHOT + 3.1.0-1478-SNAPSHOT pom Spring Data Relational Parent diff --git a/spring-data-jdbc-distribution/pom.xml b/spring-data-jdbc-distribution/pom.xml index 6e018ca17d..34e8036549 100644 --- a/spring-data-jdbc-distribution/pom.xml +++ b/spring-data-jdbc-distribution/pom.xml @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 3.1.0-SNAPSHOT + 3.1.0-1478-SNAPSHOT ../pom.xml diff --git a/spring-data-jdbc/pom.xml b/spring-data-jdbc/pom.xml index 573b188bcc..77b5e9a2d2 100644 --- a/spring-data-jdbc/pom.xml +++ b/spring-data-jdbc/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-jdbc - 3.1.0-SNAPSHOT + 3.1.0-1478-SNAPSHOT Spring Data JDBC Spring Data module for JDBC repositories. @@ -15,7 +15,7 @@ org.springframework.data spring-data-relational-parent - 3.1.0-SNAPSHOT + 3.1.0-1478-SNAPSHOT diff --git a/spring-data-r2dbc/pom.xml b/spring-data-r2dbc/pom.xml index 4637d73956..5ccd191bb5 100644 --- a/spring-data-r2dbc/pom.xml +++ b/spring-data-r2dbc/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-r2dbc - 3.1.0-SNAPSHOT + 3.1.0-1478-SNAPSHOT Spring Data R2DBC Spring Data module for R2DBC @@ -15,7 +15,7 @@ org.springframework.data spring-data-relational-parent - 3.1.0-SNAPSHOT + 3.1.0-1478-SNAPSHOT diff --git a/spring-data-relational/pom.xml b/spring-data-relational/pom.xml index 043fbccb68..de109b3532 100644 --- a/spring-data-relational/pom.xml +++ b/spring-data-relational/pom.xml @@ -6,7 +6,7 @@ 4.0.0 spring-data-relational - 3.1.0-SNAPSHOT + 3.1.0-1478-SNAPSHOT Spring Data Relational Spring Data Relational support @@ -14,7 +14,7 @@ org.springframework.data spring-data-relational-parent - 3.1.0-SNAPSHOT + 3.1.0-1478-SNAPSHOT From 9a7bb2bed981097270b1e5f24ddfb0a612b48ce9 Mon Sep 17 00:00:00 2001 From: Kurt Niemi Date: Wed, 5 Apr 2023 09:11:29 -0400 Subject: [PATCH 2/7] Model fot Generating Schema SQL Initial model for generating schema SQL. Closes #1478 --- .../mapping/RelationalMappingContext.java | 32 ++++++++ .../schemasqlgeneration/ColumnModel.java | 51 ++++++++++++ .../ForeignKeyColumnModel.java | 45 +++++++++++ .../SchemaSQLGenerationDataModel.java | 37 +++++++++ .../schemasqlgeneration/TableModel.java | 72 +++++++++++++++++ .../SchemaSQLGenerationDataModelTests.java | 78 +++++++++++++++++++ 6 files changed, 315 insertions(+) create mode 100644 spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java create mode 100644 spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ForeignKeyColumnModel.java create mode 100644 spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java create mode 100644 spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java create mode 100644 spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java index c6712a4c9a..13ee6fb6ba 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java @@ -19,9 +19,14 @@ import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.model.Property; import org.springframework.data.mapping.model.SimpleTypeHolder; +import org.springframework.data.relational.core.mapping.schemasqlgeneration.ColumnModel; +import org.springframework.data.relational.core.mapping.schemasqlgeneration.SchemaSQLGenerationDataModel; +import org.springframework.data.relational.core.mapping.schemasqlgeneration.TableModel; import org.springframework.data.util.TypeInformation; import org.springframework.util.Assert; +import java.util.Iterator; + /** * {@link MappingContext} implementation. * @@ -102,4 +107,31 @@ public NamingStrategy getNamingStrategy() { return this.namingStrategy; } + /** + * Method to build a data model of Tables/Columns and their relationships + * that will be used in SQL Generation. + */ + public SchemaSQLGenerationDataModel generateSchemaSQL() { + + SchemaSQLGenerationDataModel model = new SchemaSQLGenerationDataModel(); + + for (RelationalPersistentEntity entity : getPersistentEntities()) { + TableModel tableModel = new TableModel(); + tableModel.setName(entity.getTableName().getReference()); + + Iterator iter = + entity.getPersistentProperties(Column.class).iterator(); + + while (iter.hasNext()) { + BasicRelationalPersistentProperty p = iter.next(); + ColumnModel columnModel = new ColumnModel(); + columnModel.setName(p.getColumnName().getReference()); + columnModel.setType(p.getActualType()); + tableModel.getColumns().add(columnModel); + } + model.getTableData().add(tableModel); + } + + return model; + } } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java new file mode 100644 index 0000000000..7178731586 --- /dev/null +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java @@ -0,0 +1,51 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.relational.core.mapping.schemasqlgeneration; + +/** + * Class that models a Column for generating SQL for Schema generation. + * + * @author Kurt Niemi + */ +public class ColumnModel { + private String name; + private Class type; + private boolean nullable; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Class getType() { + return type; + } + + public void setType(Class type) { + this.type = type; + } + + public boolean isNullable() { + return nullable; + } + + public void setNullable(boolean nullable) { + this.nullable = nullable; + } +} diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ForeignKeyColumnModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ForeignKeyColumnModel.java new file mode 100644 index 0000000000..0bf3ac091c --- /dev/null +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ForeignKeyColumnModel.java @@ -0,0 +1,45 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.relational.core.mapping.schemasqlgeneration; + +/** + * Class that models a Foreign Key relationship for generating SQL for Schema generation. + * + * @author Kurt Niemi + */ +public class ForeignKeyColumnModel { + private TableModel foreignTable; + private ColumnModel foreignColumn; + private ColumnModel column; + + public ForeignKeyColumnModel(TableModel foreignTable, ColumnModel foreignColumn, ColumnModel column) { + this.foreignTable = foreignTable; + this.foreignColumn = foreignColumn; + this.column = column; + } + + public TableModel getForeignTable() { + return foreignTable; + } + + public ColumnModel getForeignColumn() { + return foreignColumn; + } + + public ColumnModel getColumn() { + return column; + } +} diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java new file mode 100644 index 0000000000..d024c5ac1d --- /dev/null +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java @@ -0,0 +1,37 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.relational.core.mapping.schemasqlgeneration; + +import java.util.ArrayList; +import java.util.List; + +/** + * Model class that contains Table/Column information that can be used + * to generate SQL for Schema generation. + * + * @author Kurt Niemi + */ +public class SchemaSQLGenerationDataModel { + private List tableData = new ArrayList(); + + public List getTableData() { + return tableData; + } + + public void setTableData(List tableData) { + this.tableData = tableData; + } +} diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java new file mode 100644 index 0000000000..a1427a129f --- /dev/null +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java @@ -0,0 +1,72 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.relational.core.mapping.schemasqlgeneration; + +import java.util.ArrayList; +import java.util.List; + +/** + * Class that models a Table for generating SQL for Schema generation. + * + * @author Kurt Niemi + */ +public class TableModel { + private String schema; + private String name; + private List columns = new ArrayList(); + private List keyColumns = new ArrayList(); + private List foreignKeyColumns = new ArrayList(); + + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getColumns() { + return columns; + } + + public void setColumns(List columns) { + this.columns = columns; + } + + public List getKeyColumns() { + return keyColumns; + } + + public void setKeyColumns(List keyColumns) { + this.keyColumns = keyColumns; + } + + public List getForeignKeyColumns() { + return foreignKeyColumns; + } + + public void setForeignKeyColumns(List foreignKeyColumns) { + this.foreignKeyColumns = foreignKeyColumns; + } +} diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java new file mode 100644 index 0000000000..39dad8522a --- /dev/null +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java @@ -0,0 +1,78 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.relational.schemasqlgeneration; + +import org.junit.jupiter.api.Test; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.RelationalMappingContext; +import org.springframework.data.relational.core.mapping.Table; +import org.springframework.data.relational.core.mapping.schemasqlgeneration.SchemaSQLGenerationDataModel; +import org.springframework.data.relational.core.mapping.schemasqlgeneration.TableModel; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Unit tests for the {@link SchemaSQLGenerationDataModel}. + * + * @author Kurt Niemi + */ +public class SchemaSQLGenerationDataModelTests { + + @Test + void testBasicModelGeneration() { + RelationalMappingContext context = new RelationalMappingContext(); + context.getRequiredPersistentEntity(SchemaSQLGenerationDataModelTests.Luke.class); + context.getRequiredPersistentEntity(SchemaSQLGenerationDataModelTests.Vader.class); + + SchemaSQLGenerationDataModel model = context.generateSchemaSQL(); + + assertThat(model.getTableData().size()).isEqualTo(2); + + TableModel t1 = model.getTableData().get(0); + assertThat(t1.getName()).isEqualTo("luke"); + assertThat(t1.getColumns().get(0).getName()).isEqualTo("force"); + assertThat(t1.getColumns().get(1).getName()).isEqualTo("be"); + assertThat(t1.getColumns().get(2).getName()).isEqualTo("with"); + assertThat(t1.getColumns().get(3).getName()).isEqualTo("you"); + + TableModel t2 = model.getTableData().get(1); + assertThat(t2.getName()).isEqualTo("vader"); + assertThat(t2.getColumns().get(0).getName()).isEqualTo("luke_i_am_your_father"); + assertThat(t2.getColumns().get(1).getName()).isEqualTo("dark_side"); + } + + @Table + static class Luke { + @Column + public String force; + @Column + public String be; + @Column + public String with; + @Column + public String you; + } + + @Table + static class Vader { + @Column + public String lukeIAmYourFather; + @Column + public Boolean darkSide; + } + + +} From 38aeaafaf8c9f262331094a3653aa5aa8564b910 Mon Sep 17 00:00:00 2001 From: Kurt Niemi Date: Mon, 10 Apr 2023 19:29:51 -0400 Subject: [PATCH 3/7] Changes to make model attributes final and declare model classes as Serializable --- .../mapping/RelationalMappingContext.java | 7 +-- .../schemasqlgeneration/ColumnModel.java | 35 ++++++++------- .../ForeignKeyColumnModel.java | 13 ++++-- .../SchemaSQLGenerationDataModel.java | 12 ++--- .../schemasqlgeneration/TableModel.java | 44 ++++++++----------- 5 files changed, 55 insertions(+), 56 deletions(-) diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java index 13ee6fb6ba..4da7000577 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java @@ -116,17 +116,14 @@ public SchemaSQLGenerationDataModel generateSchemaSQL() { SchemaSQLGenerationDataModel model = new SchemaSQLGenerationDataModel(); for (RelationalPersistentEntity entity : getPersistentEntities()) { - TableModel tableModel = new TableModel(); - tableModel.setName(entity.getTableName().getReference()); + TableModel tableModel = new TableModel(entity.getTableName().getReference()); Iterator iter = entity.getPersistentProperties(Column.class).iterator(); while (iter.hasNext()) { BasicRelationalPersistentProperty p = iter.next(); - ColumnModel columnModel = new ColumnModel(); - columnModel.setName(p.getColumnName().getReference()); - columnModel.setType(p.getActualType()); + ColumnModel columnModel = new ColumnModel(p.getColumnName().getReference(), p.getActualType()); tableModel.getColumns().add(columnModel); } model.getTableData().add(tableModel); diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java index 7178731586..3b0b5bd014 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java @@ -15,37 +15,42 @@ */ package org.springframework.data.relational.core.mapping.schemasqlgeneration; +import java.io.Serial; +import java.io.Serializable; + /** * Class that models a Column for generating SQL for Schema generation. * * @author Kurt Niemi */ -public class ColumnModel { - private String name; - private Class type; - private boolean nullable; +public class ColumnModel implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + private final String name; + private final Class type; + private final boolean nullable; - public String getName() { - return name; + public ColumnModel(String name, Class type, boolean nullable) { + this.name = name; + this.type = type; + this.nullable = nullable; } - public void setName(String name) { + public ColumnModel(String name, Class type) { this.name = name; + this.type = type; + this.nullable = false; } - public Class getType() { - return type; + public String getName() { + return name; } - public void setType(Class type) { - this.type = type; + public Class getType() { + return type; } public boolean isNullable() { return nullable; } - - public void setNullable(boolean nullable) { - this.nullable = nullable; - } } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ForeignKeyColumnModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ForeignKeyColumnModel.java index 0bf3ac091c..04bc3d46f0 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ForeignKeyColumnModel.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ForeignKeyColumnModel.java @@ -15,15 +15,20 @@ */ package org.springframework.data.relational.core.mapping.schemasqlgeneration; +import java.io.Serial; +import java.io.Serializable; + /** * Class that models a Foreign Key relationship for generating SQL for Schema generation. * * @author Kurt Niemi */ -public class ForeignKeyColumnModel { - private TableModel foreignTable; - private ColumnModel foreignColumn; - private ColumnModel column; +public class ForeignKeyColumnModel implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + private final TableModel foreignTable; + private final ColumnModel foreignColumn; + private final ColumnModel column; public ForeignKeyColumnModel(TableModel foreignTable, ColumnModel foreignColumn, ColumnModel column) { this.foreignTable = foreignTable; diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java index d024c5ac1d..b7c4eee878 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java @@ -15,6 +15,8 @@ */ package org.springframework.data.relational.core.mapping.schemasqlgeneration; +import java.io.Serial; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -24,14 +26,12 @@ * * @author Kurt Niemi */ -public class SchemaSQLGenerationDataModel { - private List tableData = new ArrayList(); +public class SchemaSQLGenerationDataModel implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + private final List tableData = new ArrayList(); public List getTableData() { return tableData; } - - public void setTableData(List tableData) { - this.tableData = tableData; - } } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java index a1427a129f..cce108eda8 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java @@ -15,6 +15,8 @@ */ package org.springframework.data.relational.core.mapping.schemasqlgeneration; +import java.io.Serial; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; @@ -23,50 +25,40 @@ * * @author Kurt Niemi */ -public class TableModel { - private String schema; - private String name; - private List columns = new ArrayList(); - private List keyColumns = new ArrayList(); - private List foreignKeyColumns = new ArrayList(); +public class TableModel implements Serializable { + @Serial + private static final long serialVersionUID = 1L; + private final String schema; + private final String name; + private final List columns = new ArrayList(); + private final List keyColumns = new ArrayList(); + private final List foreignKeyColumns = new ArrayList(); - public String getSchema() { - return schema; + public TableModel(String schema, String name) { + this.schema = schema; + this.name = name; + } + public TableModel(String name) { + this(name, null); } - public void setSchema(String schema) { - this.schema = schema; + public String getSchema() { + return schema; } public String getName() { return name; } - public void setName(String name) { - this.name = name; - } - public List getColumns() { return columns; } - public void setColumns(List columns) { - this.columns = columns; - } - public List getKeyColumns() { return keyColumns; } - public void setKeyColumns(List keyColumns) { - this.keyColumns = keyColumns; - } - public List getForeignKeyColumns() { return foreignKeyColumns; } - - public void setForeignKeyColumns(List foreignKeyColumns) { - this.foreignKeyColumns = foreignKeyColumns; - } } From c59f8a7165781f5245faef8ba3d0cf400df1848d Mon Sep 17 00:00:00 2001 From: Kurt Niemi Date: Mon, 10 Apr 2023 19:40:47 -0400 Subject: [PATCH 4/7] Use SQLIdentifiers for Table and Column names --- .../core/mapping/RelationalMappingContext.java | 4 ++-- .../mapping/schemasqlgeneration/ColumnModel.java | 10 ++++++---- .../core/mapping/schemasqlgeneration/TableModel.java | 12 +++++++----- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java index 4da7000577..588de044d8 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java @@ -116,14 +116,14 @@ public SchemaSQLGenerationDataModel generateSchemaSQL() { SchemaSQLGenerationDataModel model = new SchemaSQLGenerationDataModel(); for (RelationalPersistentEntity entity : getPersistentEntities()) { - TableModel tableModel = new TableModel(entity.getTableName().getReference()); + TableModel tableModel = new TableModel(entity.getTableName()); Iterator iter = entity.getPersistentProperties(Column.class).iterator(); while (iter.hasNext()) { BasicRelationalPersistentProperty p = iter.next(); - ColumnModel columnModel = new ColumnModel(p.getColumnName().getReference(), p.getActualType()); + ColumnModel columnModel = new ColumnModel(p.getColumnName(), p.getActualType()); tableModel.getColumns().add(columnModel); } model.getTableData().add(tableModel); diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java index 3b0b5bd014..a71997cf5a 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java @@ -15,6 +15,8 @@ */ package org.springframework.data.relational.core.mapping.schemasqlgeneration; +import org.springframework.data.relational.core.sql.SqlIdentifier; + import java.io.Serial; import java.io.Serializable; @@ -26,23 +28,23 @@ public class ColumnModel implements Serializable { @Serial private static final long serialVersionUID = 1L; - private final String name; + private final SqlIdentifier name; private final Class type; private final boolean nullable; - public ColumnModel(String name, Class type, boolean nullable) { + public ColumnModel(SqlIdentifier name, Class type, boolean nullable) { this.name = name; this.type = type; this.nullable = nullable; } - public ColumnModel(String name, Class type) { + public ColumnModel(SqlIdentifier name, Class type) { this.name = name; this.type = type; this.nullable = false; } - public String getName() { + public SqlIdentifier getName() { return name; } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java index cce108eda8..fb59264ffe 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/TableModel.java @@ -15,6 +15,8 @@ */ package org.springframework.data.relational.core.mapping.schemasqlgeneration; +import org.springframework.data.relational.core.sql.SqlIdentifier; + import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; @@ -29,24 +31,24 @@ public class TableModel implements Serializable { @Serial private static final long serialVersionUID = 1L; private final String schema; - private final String name; + private final SqlIdentifier name; private final List columns = new ArrayList(); private final List keyColumns = new ArrayList(); private final List foreignKeyColumns = new ArrayList(); - public TableModel(String schema, String name) { + public TableModel(String schema, SqlIdentifier name) { this.schema = schema; this.name = name; } - public TableModel(String name) { - this(name, null); + public TableModel(SqlIdentifier name) { + this(null, name); } public String getSchema() { return schema; } - public String getName() { + public SqlIdentifier getName() { return name; } From e183e9ea2a65b9016a1a68a183913ecf43a05760 Mon Sep 17 00:00:00 2001 From: Kurt Niemi Date: Tue, 11 Apr 2023 14:14:15 -0400 Subject: [PATCH 5/7] Move logic for generating Schema Generation model outside of RelationalMappingContext --- .../mapping/RelationalMappingContext.java | 28 ---------------- .../SchemaSQLGenerationDataModel.java | 32 +++++++++++++++++++ .../SchemaSQLGenerationDataModelTests.java | 7 ++-- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java index 588de044d8..4a20ba7080 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/RelationalMappingContext.java @@ -19,9 +19,6 @@ import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mapping.model.Property; import org.springframework.data.mapping.model.SimpleTypeHolder; -import org.springframework.data.relational.core.mapping.schemasqlgeneration.ColumnModel; -import org.springframework.data.relational.core.mapping.schemasqlgeneration.SchemaSQLGenerationDataModel; -import org.springframework.data.relational.core.mapping.schemasqlgeneration.TableModel; import org.springframework.data.util.TypeInformation; import org.springframework.util.Assert; @@ -106,29 +103,4 @@ protected RelationalPersistentProperty createPersistentProperty(Property propert public NamingStrategy getNamingStrategy() { return this.namingStrategy; } - - /** - * Method to build a data model of Tables/Columns and their relationships - * that will be used in SQL Generation. - */ - public SchemaSQLGenerationDataModel generateSchemaSQL() { - - SchemaSQLGenerationDataModel model = new SchemaSQLGenerationDataModel(); - - for (RelationalPersistentEntity entity : getPersistentEntities()) { - TableModel tableModel = new TableModel(entity.getTableName()); - - Iterator iter = - entity.getPersistentProperties(Column.class).iterator(); - - while (iter.hasNext()) { - BasicRelationalPersistentProperty p = iter.next(); - ColumnModel columnModel = new ColumnModel(p.getColumnName(), p.getActualType()); - tableModel.getColumns().add(columnModel); - } - model.getTableData().add(tableModel); - } - - return model; - } } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java index b7c4eee878..190a5dbaf1 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java @@ -15,9 +15,15 @@ */ package org.springframework.data.relational.core.mapping.schemasqlgeneration; +import org.springframework.data.relational.core.mapping.BasicRelationalPersistentProperty; +import org.springframework.data.relational.core.mapping.Column; +import org.springframework.data.relational.core.mapping.RelationalMappingContext; +import org.springframework.data.relational.core.mapping.RelationalPersistentEntity; + import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; /** @@ -31,6 +37,32 @@ public class SchemaSQLGenerationDataModel implements Serializable { private static final long serialVersionUID = 1L; private final List tableData = new ArrayList(); + /** + * Default constructor so that we can deserialize a model + */ + public SchemaSQLGenerationDataModel() { + } + + /** + * Create model from a RelationalMappingContext + */ + public SchemaSQLGenerationDataModel(RelationalMappingContext context) { + + for (RelationalPersistentEntity entity : context.getPersistentEntities()) { + TableModel tableModel = new TableModel(entity.getTableName()); + + Iterator iter = + entity.getPersistentProperties(Column.class).iterator(); + + while (iter.hasNext()) { + BasicRelationalPersistentProperty p = iter.next(); + ColumnModel columnModel = new ColumnModel(p.getColumnName(), p.getActualType()); + tableModel.getColumns().add(columnModel); + } + tableData.add(tableModel); + } + } + public List getTableData() { return tableData; } diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java index 39dad8522a..9a6e847c13 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java @@ -20,6 +20,7 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext; import org.springframework.data.relational.core.mapping.Table; import org.springframework.data.relational.core.mapping.schemasqlgeneration.SchemaSQLGenerationDataModel; +import org.springframework.data.relational.core.mapping.schemasqlgeneration.SchemaSQLGenerator; import org.springframework.data.relational.core.mapping.schemasqlgeneration.TableModel; import static org.assertj.core.api.Assertions.assertThat; @@ -37,12 +38,12 @@ void testBasicModelGeneration() { context.getRequiredPersistentEntity(SchemaSQLGenerationDataModelTests.Luke.class); context.getRequiredPersistentEntity(SchemaSQLGenerationDataModelTests.Vader.class); - SchemaSQLGenerationDataModel model = context.generateSchemaSQL(); + SchemaSQLGenerationDataModel model = new SchemaSQLGenerationDataModel(context); assertThat(model.getTableData().size()).isEqualTo(2); - TableModel t1 = model.getTableData().get(0); - assertThat(t1.getName()).isEqualTo("luke"); + TableModel t1 = model.getTableData().get(1); + assertThat(t1.getName().getReference()).isEqualTo("luke"); assertThat(t1.getColumns().get(0).getName()).isEqualTo("force"); assertThat(t1.getColumns().get(1).getName()).isEqualTo("be"); assertThat(t1.getColumns().get(2).getName()).isEqualTo("with"); From 5762a06feee1cd7c40585e2b653a442953dec0c8 Mon Sep 17 00:00:00 2001 From: Kurt Niemi Date: Tue, 11 Apr 2023 19:18:56 -0400 Subject: [PATCH 6/7] Changes to generate/populate type on Column model --- .../schemasqlgeneration/BaseTypeMapper.java | 34 +++++++++++++++++++ .../schemasqlgeneration/ColumnModel.java | 8 ++--- .../SchemaSQLGenerationDataModel.java | 10 +++++- 3 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/BaseTypeMapper.java diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/BaseTypeMapper.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/BaseTypeMapper.java new file mode 100644 index 0000000000..9e8f5335e0 --- /dev/null +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/BaseTypeMapper.java @@ -0,0 +1,34 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.relational.core.mapping.schemasqlgeneration; + +import java.util.HashMap; + +public class BaseTypeMapper { + + final HashMap,String> mapClassToDatabaseType = new HashMap,String>(); + + public BaseTypeMapper() { + mapClassToDatabaseType.put(String.class, "VARCHAR(255)"); + mapClassToDatabaseType.put(Boolean.class, "TINYINT"); + mapClassToDatabaseType.put(Double.class, "DOUBLE"); + mapClassToDatabaseType.put(Float.class, "FLOAT"); + mapClassToDatabaseType.put(Integer.class, "INT"); + } + public String databaseTypeFromClass(Class type) { + return mapClassToDatabaseType.get(type); + } +} diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java index a71997cf5a..18cd0d12c1 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/ColumnModel.java @@ -29,16 +29,16 @@ public class ColumnModel implements Serializable { @Serial private static final long serialVersionUID = 1L; private final SqlIdentifier name; - private final Class type; + private final String type; private final boolean nullable; - public ColumnModel(SqlIdentifier name, Class type, boolean nullable) { + public ColumnModel(SqlIdentifier name, String type, boolean nullable) { this.name = name; this.type = type; this.nullable = nullable; } - public ColumnModel(SqlIdentifier name, Class type) { + public ColumnModel(SqlIdentifier name, String type) { this.name = name; this.type = type; this.nullable = false; @@ -48,7 +48,7 @@ public SqlIdentifier getName() { return name; } - public Class getType() { + public String getType() { return type; } diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java index 190a5dbaf1..aa31a656f5 100644 --- a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerationDataModel.java @@ -23,6 +23,7 @@ import java.io.Serial; import java.io.Serializable; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -36,6 +37,7 @@ public class SchemaSQLGenerationDataModel implements Serializable { @Serial private static final long serialVersionUID = 1L; private final List tableData = new ArrayList(); + BaseTypeMapper typeMapper; /** * Default constructor so that we can deserialize a model @@ -48,6 +50,10 @@ public SchemaSQLGenerationDataModel() { */ public SchemaSQLGenerationDataModel(RelationalMappingContext context) { + if (typeMapper == null) { + typeMapper = new BaseTypeMapper(); + } + for (RelationalPersistentEntity entity : context.getPersistentEntities()) { TableModel tableModel = new TableModel(entity.getTableName()); @@ -56,7 +62,9 @@ public SchemaSQLGenerationDataModel(RelationalMappingContext context) { while (iter.hasNext()) { BasicRelationalPersistentProperty p = iter.next(); - ColumnModel columnModel = new ColumnModel(p.getColumnName(), p.getActualType()); + ColumnModel columnModel = new ColumnModel(p.getColumnName(), + typeMapper.databaseTypeFromClass(p.getActualType()), + true); tableModel.getColumns().add(columnModel); } tableData.add(tableModel); From 985b703464cf78a6819b2385972809dba686f8b8 Mon Sep 17 00:00:00 2001 From: Kurt Niemi Date: Tue, 11 Apr 2023 19:19:52 -0400 Subject: [PATCH 7/7] Initial SQL generation (no aggregates / default types) --- .../SchemaSQLGenerator.java | 113 ++++++++++++++++++ .../SchemaSQLGenerationDataModelTests.java | 36 +++--- 2 files changed, 135 insertions(+), 14 deletions(-) create mode 100644 spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerator.java diff --git a/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerator.java b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerator.java new file mode 100644 index 0000000000..8b9c8a77a0 --- /dev/null +++ b/spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/schemasqlgeneration/SchemaSQLGenerator.java @@ -0,0 +1,113 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.data.relational.core.mapping.schemasqlgeneration; + +import org.springframework.data.relational.core.sql.IdentifierProcessing; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +public class SchemaSQLGenerator { + + private final IdentifierProcessing identifierProcssing; + public SchemaSQLGenerator(IdentifierProcessing identifierProcessing) { + this.identifierProcssing = identifierProcessing; + } + + List> reorderTablesInHierarchy(SchemaSQLGenerationDataModel dataModel) { + + // ::TODO:: Take Parent/Child relationships into account (i.e if a child table has + // a Foreign Key to a table, that parent table needs to be created first. + + // For now this method will simple put the tables in the same level + List> orderedTables = new ArrayList>(); + List tables = new ArrayList(); + + for (TableModel table : dataModel.getTableData()) { + tables.add(table); + } + orderedTables.add(tables); + + return orderedTables; + } + + HashMap,String> mapClassToSQLType = null; + + public String generateSQL(ColumnModel column) { + + StringBuilder sql = new StringBuilder(); + sql.append(column.getName().toSql(identifierProcssing)); + sql.append(" "); + + sql.append(column.getType()); + + if (!column.isNullable()) { + sql.append(" NOT NULL"); + } + + return sql.toString(); + } + + public String generatePrimaryKeySQL(TableModel table) { + // ::TODO:: Implement + return ""; + } + + public String generateForeignKeySQL(TableModel table) { + // ::TODO:: Implement + return ""; + } + + public String generateSQL(TableModel table) { + + StringBuilder sql = new StringBuilder(); + + sql.append("CREATE TABLE "); + sql.append(table.getName().toSql(identifierProcssing)); + sql.append(" ("); + + int numColumns = table.getColumns().size(); + for (int i=0; i < numColumns; i++) { + sql.append(generateSQL(table.getColumns().get(i))); + if (i != numColumns-1) { + sql.append(","); + } + } + + sql.append(generatePrimaryKeySQL(table)); + sql.append(generateForeignKeySQL(table)); + + sql.append(" );"); + + return sql.toString(); + } + + public String generateSQL(SchemaSQLGenerationDataModel dataModel) { + + StringBuilder sql = new StringBuilder(); + List> orderedTables = reorderTablesInHierarchy(dataModel); + + for (List tables : orderedTables) { + for (TableModel table : tables) { + String tableSQL = generateSQL(table); + sql.append(tableSQL + "\n"); + } + } + + return sql.toString(); + } +} diff --git a/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java b/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java index 9a6e847c13..517c369d63 100644 --- a/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java +++ b/spring-data-relational/src/test/java/org/springframework/data/relational/schemasqlgeneration/SchemaSQLGenerationDataModelTests.java @@ -22,6 +22,8 @@ import org.springframework.data.relational.core.mapping.schemasqlgeneration.SchemaSQLGenerationDataModel; import org.springframework.data.relational.core.mapping.schemasqlgeneration.SchemaSQLGenerator; import org.springframework.data.relational.core.mapping.schemasqlgeneration.TableModel; +import org.springframework.data.relational.core.sql.IdentifierProcessing; +import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -33,28 +35,28 @@ public class SchemaSQLGenerationDataModelTests { @Test - void testBasicModelGeneration() { + void testBasicSchemaSQLGeneration() { + + IdentifierProcessing.Quoting quoting = new IdentifierProcessing.Quoting("`"); + IdentifierProcessing identifierProcessing = IdentifierProcessing.create(quoting, IdentifierProcessing.LetterCasing.LOWER_CASE); + SchemaSQLGenerator generator = new SchemaSQLGenerator(identifierProcessing); + RelationalMappingContext context = new RelationalMappingContext(); context.getRequiredPersistentEntity(SchemaSQLGenerationDataModelTests.Luke.class); - context.getRequiredPersistentEntity(SchemaSQLGenerationDataModelTests.Vader.class); SchemaSQLGenerationDataModel model = new SchemaSQLGenerationDataModel(context); + String sql = generator.generateSQL(model); + assertThat(sql).isEqualTo("CREATE TABLE `luke` (`force` VARCHAR(255),`be` VARCHAR(255),`with` VARCHAR(255),`you` VARCHAR(255) );\n"); - assertThat(model.getTableData().size()).isEqualTo(2); - - TableModel t1 = model.getTableData().get(1); - assertThat(t1.getName().getReference()).isEqualTo("luke"); - assertThat(t1.getColumns().get(0).getName()).isEqualTo("force"); - assertThat(t1.getColumns().get(1).getName()).isEqualTo("be"); - assertThat(t1.getColumns().get(2).getName()).isEqualTo("with"); - assertThat(t1.getColumns().get(3).getName()).isEqualTo("you"); + context = new RelationalMappingContext(); + context.getRequiredPersistentEntity(SchemaSQLGenerationDataModelTests.Vader.class); - TableModel t2 = model.getTableData().get(1); - assertThat(t2.getName()).isEqualTo("vader"); - assertThat(t2.getColumns().get(0).getName()).isEqualTo("luke_i_am_your_father"); - assertThat(t2.getColumns().get(1).getName()).isEqualTo("dark_side"); + model = new SchemaSQLGenerationDataModel(context); + sql = generator.generateSQL(model); + assertThat(sql).isEqualTo("CREATE TABLE `vader` (`luke_i_am_your_father` VARCHAR(255),`dark_side` TINYINT,`floater` FLOAT,`double_class` DOUBLE,`integer_class` INT );\n"); } + @Table static class Luke { @Column @@ -73,6 +75,12 @@ static class Vader { public String lukeIAmYourFather; @Column public Boolean darkSide; + @Column + public Float floater; + @Column + public Double doubleClass; + @Column + public Integer integerClass; }