-
Notifications
You must be signed in to change notification settings - Fork 356
Initial Data Model for Schema SQL Generation #1481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
a30d01a
9a7bb2b
38aeaaf
c59f8a7
e183e9e
5762a06
985b703
aed2adf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
kurtn718 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
private Class<?> type; | ||
private boolean nullable; | ||
|
||
public String getName() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Things like column and table names should be |
||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Class<?> getType() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see why we would need a |
||
return type; | ||
} | ||
|
||
public void setType(Class<?> type) { | ||
this.type = type; | ||
} | ||
|
||
public boolean isNullable() { | ||
return nullable; | ||
} | ||
|
||
public void setNullable(boolean nullable) { | ||
this.nullable = nullable; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<TableModel> tableData = new ArrayList<TableModel>(); | ||
|
||
public List<TableModel> getTableData() { | ||
return tableData; | ||
} | ||
|
||
public void setTableData(List<TableModel> tableData) { | ||
this.tableData = tableData; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<ColumnModel> columns = new ArrayList<ColumnModel>(); | ||
private List<ColumnModel> keyColumns = new ArrayList<ColumnModel>(); | ||
private List<ForeignKeyColumnModel> foreignKeyColumns = new ArrayList<ForeignKeyColumnModel>(); | ||
|
||
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<ColumnModel> getColumns() { | ||
return columns; | ||
} | ||
|
||
public void setColumns(List<ColumnModel> columns) { | ||
this.columns = columns; | ||
} | ||
|
||
public List<ColumnModel> getKeyColumns() { | ||
return keyColumns; | ||
} | ||
|
||
public void setKeyColumns(List<ColumnModel> keyColumns) { | ||
this.keyColumns = keyColumns; | ||
} | ||
|
||
public List<ForeignKeyColumnModel> getForeignKeyColumns() { | ||
return foreignKeyColumns; | ||
} | ||
|
||
public void setForeignKeyColumns(List<ForeignKeyColumnModel> foreignKeyColumns) { | ||
this.foreignKeyColumns = foreignKeyColumns; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the mapping context should create a
SchemaSqlGenerationDataModel
instead a mapping context should be used to create such a model. Either in the constructor of the class or in a factory.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About to push up a change for this. Code definitely looks cleaner with this!