public abstract class SqlProcessorImpl extends Object implements TableSqlProcessor
COLUMN_DEF, COLUMN_NAME, COLUMN_SIZE, DATA_TYPE, DECIMAL_DIGITS, INDEX_NON_UNIQUE, NULLABLE, REMARKS, TYPE_NAME
Constructor and Description |
---|
SqlProcessorImpl() |
Modifier and Type | Method and Description |
---|---|
protected void |
appendBody(StringBuffer ddlBuffer,
Table table,
List<String> list) |
protected void |
appendColumnUpdate(List<String> existUpdateList,
TableField field,
StandardField standardField,
ColumnContext columnContext)
列字段是否发生改变
|
protected void |
appendComment(String comment,
StringBuffer ddlBuffer,
List<String> list) |
protected void |
appendDefaultValue(String defaultValue,
StringBuffer ddlBuffer) |
protected void |
appendField(StringBuffer ddlBuffer,
TableField field,
List<String> list,
Table table) |
protected void |
appendFooter(StringBuffer ddlBuffer,
Table table,
List<String> list) |
protected void |
appendFooterComment(Table table,
List<String> list)
在footer增加comment
|
protected String |
appendIncrease() |
protected void |
appendIndexReverse(StringBuffer ddlBuffer,
Index index) |
protected void |
appendPrimarySql(StringBuffer ddlBuffer,
Table table,
List<String> list) |
protected void |
appendTableSpace(StringBuffer ddlBuffer,
Table table)
表空间默认实现
|
protected void |
appendTypeAndDefault(StringBuffer ddlBuffer,
TableField field,
StandardField standardField) |
protected void |
char2DbLen(List<String> businessTypeList,
BusinessType businessType,
String databaseType) |
protected boolean |
checkCommentSame(String standardComment,
String remarks)
检查comment是否改变
|
protected boolean |
checkDefSame(String standardDefault,
String columnDef) |
protected boolean |
checkIndexBaseSame(Index tableIndex,
Map<String,String> dbIndexMap,
Connection con)
index基本信息是否一致
|
protected List<String> |
checkTableColumn(Map<String,Map<String,String>> columns,
Map<String,TableField> fieldDbNames,
Map<String,TableField> existInTable) |
boolean |
checkTableExist(Table table,
Connection connection) |
protected boolean |
checkTypeSame(String dbColumnType,
String tableDataType,
String dbDataType)
检查数据类型是否相同
|
protected boolean |
checkUniqueSame(Map<String,String> uniqueColumns,
String indexName,
boolean isFieldUnique) |
protected abstract String |
createAlterTypeSql(String tableName,
String fieldName,
String tableDataType) |
protected List<String> |
dealAddFields(Map<String,TableField> fieldDbNames,
String packageName,
Table table) |
protected void |
dealConstraintIndex(Table table,
List<String> preDropIndexes,
Map<String,Map<String,String>> dbIndexes)
删除有关联的索引
|
protected String |
dealDateType(String value)
处理日期类型
因为初始化数据是字符串类型,而实际是date类型,有些数据库需要进行转换。
|
protected void |
dealDefaultValueUpdate(StringBuffer alterTypeBuffer,
String fieldDefaultValue,
String columnDef) |
protected List<String> |
dealDropFields(List<String> dropFields,
Table table) |
protected List<String> |
dealExistFields(Map<String,TableField> existInTable,
Map<String,Map<String,String>> dbColumns,
Table table)
比较数据库metadata和配置中数据
|
protected void |
dealNotNullSql(StringBuffer alterTypeBuffer,
TableField field,
boolean dbNullAble) |
protected String |
dealTableName(String tableName) |
protected void |
defaultChangedFooterComment(Connection connection,
Table table,
List<String> list) |
protected String |
delimiter(String name) |
protected void |
getChangedFooterComment(Connection connection,
Table table,
List<String> list) |
List<String> |
getClearTableSql(Table table,
Connection connection) |
protected Map<String,Map<String,String>> |
getColumns(DatabaseMetaData metadata,
String catalog,
Table table) |
protected String |
getComment(StandardField standardField) |
List<String> |
getCreateSql(Table table,
String packageName)
获得创建表格的语句(包含index)
|
protected abstract String |
getDatabaseType() |
protected String |
getDbColumnColumnDef(Map<String,String> attributes)
获取默认值
|
protected String |
getDbColumnRemarks(Map<String,String> attributes)
获取注释
|
protected String |
getDbColumnType(Map<String,String> attributes) |
protected List<Map<String,String>> |
getDbForeignList(Connection connection,
Table table) |
protected Map<String,Map<String,String>> |
getDbIndexColumns(DatabaseMetaData metadata,
String schema,
Table table)
获取表的所有索引
|
protected String |
getDefaultValue(TableField field,
StandardField standardField) |
protected String |
getDropForeignSql(String dropConstraint,
Table table) |
protected String |
getDropIndexBaseSql(String dropIndexName,
String nameWithOutSchema) |
String |
getDropSql(Table table,
String packageName) |
protected String |
getFieldStdFieldName(String fieldId,
Table table) |
List<String> |
getForeignKeySqls(Table table,
String packageName)
获取外键,直接使用table的外键作为需要创建的外键(适用于全量sql)
|
List<String> |
getForeignKeySqls(Table table,
String packageName,
List<ForeignReference> foreignReferences)
获取外键
|
protected void |
getForeignUpdate(Table table,
String packageName,
Connection connection,
List<String> list)
更新外键
|
List<String> |
getIndexCreateSql(Table table,
String packageName)
获得创建索引的语句
|
protected String |
getIndexName(Index index,
Table table) |
protected void |
getIndexUpdate(Connection connection,
Table table,
List<String> list) |
protected StringBuffer |
getKeysBuffer(Table table) |
protected String |
getOneFkSql(Table table,
Table foreignTable,
ForeignReference foreignReference) |
protected void |
getOtherUpdate(Table table,
String packageName,
Connection connection,
List<String> list) |
protected String |
getQueryForeignSql(Table table,
String schema) |
protected String |
getQuerySchemaName(String schema,
String catalog)
获取查询语句的schema
|
protected String |
getSchema(String schema,
Connection connection) |
protected String |
getSchema(Table table,
DatabaseMetaData metadata) |
protected List<String> |
getSeqTriggerSql(Table table,
String packageName)
创建seq和trigger语句
|
protected void |
getSeqTriggerUpdate(Connection connection,
Table table,
List<String> list) |
protected void |
getTableColumnUpdate(Table table,
String packageName,
DatabaseMetaData metadata,
String catalog,
List<String> list)
获取列变化增量语句
|
List<String> |
getTableCreateSql(Table table,
String packageName)
获得创建表格的语句(不包含index)
|
protected String |
getTableName(Table table) |
TableProcessor |
getTableProcessor() |
List<String> |
getUpdateSql(Table table,
String packageName,
Connection connection)
获得(正向)Update表格的语句
|
void |
initChar2Byte(String language) |
protected boolean |
notNeedDropIndex(List<Index> preAddIndexes,
Table table,
String dbIndexName,
Map<String,Map<String,String>> dbIndexMaps,
Connection connection) |
void |
setTableProcessor(TableProcessor tableProcessor) |
public TableProcessor getTableProcessor()
getTableProcessor
in interface TableSqlProcessor
public void setTableProcessor(TableProcessor tableProcessor)
setTableProcessor
in interface TableSqlProcessor
protected abstract String getDatabaseType()
public List<String> getCreateSql(Table table, String packageName)
TableSqlProcessor
getCreateSql
in interface TableSqlProcessor
protected List<String> getSeqTriggerSql(Table table, String packageName)
table
- packageName
- protected void appendPrimarySql(StringBuffer ddlBuffer, Table table, List<String> list)
protected StringBuffer getKeysBuffer(Table table)
public List<String> getForeignKeySqls(Table table, String packageName)
getForeignKeySqls
in interface TableSqlProcessor
table
- packageName
- public List<String> getForeignKeySqls(Table table, String packageName, List<ForeignReference> foreignReferences)
table
- packageName
- foreignReferences
- 需要更新的外键对象protected String getOneFkSql(Table table, Table foreignTable, ForeignReference foreignReference)
public List<String> getTableCreateSql(Table table, String packageName)
TableSqlProcessor
getTableCreateSql
in interface TableSqlProcessor
public List<String> getIndexCreateSql(Table table, String packageName)
TableSqlProcessor
getIndexCreateSql
in interface TableSqlProcessor
public List<String> getUpdateSql(Table table, String packageName, Connection connection) throws SQLException
TableSqlProcessor
getUpdateSql
in interface TableSqlProcessor
SQLException
protected void getOtherUpdate(Table table, String packageName, Connection connection, List<String> list) throws SQLException
SQLException
protected void getSeqTriggerUpdate(Connection connection, Table table, List<String> list) throws SQLException
SQLException
protected void getIndexUpdate(Connection connection, Table table, List<String> list) throws SQLException
SQLException
protected String getDropIndexBaseSql(String dropIndexName, String nameWithOutSchema)
protected String getSchema(String schema, Connection connection) throws SQLException
SQLException
protected boolean notNeedDropIndex(List<Index> preAddIndexes, Table table, String dbIndexName, Map<String,Map<String,String>> dbIndexMaps, Connection connection)
protected boolean checkIndexBaseSame(Index tableIndex, Map<String,String> dbIndexMap, Connection con)
tableIndex
- dbIndexMap
- con
- protected void dealConstraintIndex(Table table, List<String> preDropIndexes, Map<String,Map<String,String>> dbIndexes)
table
- preDropIndexes
- protected void getChangedFooterComment(Connection connection, Table table, List<String> list) throws SQLException
SQLException
protected void defaultChangedFooterComment(Connection connection, Table table, List<String> list) throws SQLException
SQLException
protected List<Map<String,String>> getDbForeignList(Connection connection, Table table) throws SQLException
SQLException
protected void getForeignUpdate(Table table, String packageName, Connection connection, List<String> list) throws SQLException
table
- packageName
- connection
- list
- SQLException
protected String getQuerySchemaName(String schema, String catalog)
schema
- catalog
- protected void getTableColumnUpdate(Table table, String packageName, DatabaseMetaData metadata, String catalog, List<String> list) throws SQLException
table
- packageName
- metadata
- catalog
- list
- SQLException
protected List<String> checkTableColumn(Map<String,Map<String,String>> columns, Map<String,TableField> fieldDbNames, Map<String,TableField> existInTable)
protected List<String> dealAddFields(Map<String,TableField> fieldDbNames, String packageName, Table table)
protected List<String> dealExistFields(Map<String,TableField> existInTable, Map<String,Map<String,String>> dbColumns, Table table)
existInTable
- 配置文件中对应tablefield k-vdbColumns
- 数据库中的metadata k-vtable
- 表信息protected void appendColumnUpdate(List<String> existUpdateList, TableField field, StandardField standardField, ColumnContext columnContext)
existUpdateList
- field
- standardField
- columnContext
- protected void dealNotNullSql(StringBuffer alterTypeBuffer, TableField field, boolean dbNullAble)
protected void dealDefaultValueUpdate(StringBuffer alterTypeBuffer, String fieldDefaultValue, String columnDef)
protected boolean checkUniqueSame(Map<String,String> uniqueColumns, String indexName, boolean isFieldUnique)
protected Map<String,Map<String,String>> getDbIndexColumns(DatabaseMetaData metadata, String schema, Table table) throws SQLException
metadata
- schema
- table
- SQLException
protected boolean checkCommentSame(String standardComment, String remarks)
standardComment
- remarks
- protected boolean checkTypeSame(String dbColumnType, String tableDataType, String dbDataType)
dbColumnType
- tableDataType
- protected abstract String createAlterTypeSql(String tableName, String fieldName, String tableDataType)
protected void appendBody(StringBuffer ddlBuffer, Table table, List<String> list)
protected void appendField(StringBuffer ddlBuffer, TableField field, List<String> list, Table table)
protected void char2DbLen(List<String> businessTypeList, BusinessType businessType, String databaseType)
protected void appendTypeAndDefault(StringBuffer ddlBuffer, TableField field, StandardField standardField)
protected String getComment(StandardField standardField)
protected void appendComment(String comment, StringBuffer ddlBuffer, List<String> list)
protected void appendFooterComment(Table table, List<String> list)
table
- list
- protected void appendDefaultValue(String defaultValue, StringBuffer ddlBuffer)
protected String appendIncrease()
protected void appendIndexReverse(StringBuffer ddlBuffer, Index index)
protected void appendFooter(StringBuffer ddlBuffer, Table table, List<String> list)
protected void appendTableSpace(StringBuffer ddlBuffer, Table table)
ddlBuffer
- table
- public String getDropSql(Table table, String packageName)
getDropSql
in interface TableSqlProcessor
protected Map<String,Map<String,String>> getColumns(DatabaseMetaData metadata, String catalog, Table table) throws SQLException
SQLException
protected String getSchema(Table table, DatabaseMetaData metadata) throws SQLException
SQLException
public boolean checkTableExist(Table table, Connection connection) throws SQLException
checkTableExist
in interface TableSqlProcessor
SQLException
protected String getDbColumnRemarks(Map<String,String> attributes)
attributes
- protected String getDbColumnColumnDef(Map<String,String> attributes)
attributes
- protected String getDefaultValue(TableField field, StandardField standardField)
field
- standardField
- protected String dealDateType(String value)
value
- public List<String> getClearTableSql(Table table, Connection connection) throws SQLException
getClearTableSql
in interface TableSqlProcessor
SQLException
public void initChar2Byte(String language)
initChar2Byte
in interface TableSqlProcessor
Copyright © 2006–2018 TinyGroup. All rights reserved.