类 MysqlStrategy
java.lang.Object
org.dromara.autotable.core.strategy.mysql.MysqlStrategy
public class MysqlStrategy
extends Object
implements IStrategy<MysqlTableMetadata,MysqlCompareTableInfo,MysqlTablesMapper>
项目启动时自动扫描配置的目录中的model,根据配置的规则自动创建或更新表 该逻辑只适用于mysql,其他数据库尚且需要另外扩展,因为sql的语法不同
- 版本:
- 2019/07/06
- 作者:
- sunchenbin, Spet
-
字段概要
从接口继承的字段 org.dromara.autotable.core.strategy.IStrategy
log, TRANSACTION_COMMIT_MARK -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明@NonNull MysqlTableMetadataanalyseClass(Class<?> beanClass) 分析Bean,得到元数据信息private voidcompareColumns(MysqlTableMetadata mysqlTableMetadata, String tableName, MysqlCompareTableInfo mysqlCompareTableInfo) 对比列的不同private voidcompareIndexes(MysqlTableMetadata mysqlTableMetadata, MysqlCompareTableInfo mysqlCompareTableInfo, Map<String, List<InformationSchemaStatistics>> tableIndexes) private static voidcomparePrimary(MysqlTableMetadata mysqlTableMetadata, MysqlCompareTableInfo mysqlCompareTableInfo, List<InformationSchemaStatistics> tablePrimaries) @NonNull MysqlCompareTableInfocompareTable(MysqlTableMetadata tableMetadata) 对比表与bean的差异private static voidcompareTableProperties(MysqlTableMetadata mysqlTableMetadata, InformationSchemaTable tableInformation, MysqlCompareTableInfo mysqlCompareTableInfo) createTable(MysqlTableMetadata tableMetadata) 生成创建表SQL策略对应的数据库方言,与数据库驱动中的接口DatabaseMetaData.getDatabaseProductName()实现返回值一致根据表名删除表,生成删除表的SQLprivate static booleanisCharsetChanged(InformationSchemaColumn informationSchemaColumn, MysqlColumnMetadata mysqlColumnMetadata) private static booleanisCommentChanged(InformationSchemaColumn informationSchemaColumn, MysqlColumnMetadata mysqlColumnMetadata) private static booleanisDefaultValueChanged(InformationSchemaColumn informationSchemaColumn, MysqlColumnMetadata mysqlColumnMetadata) private static booleanisFieldTypeChanged(InformationSchemaColumn informationSchemaColumn, MysqlColumnMetadata mysqlColumnMetadata) 字段类型比对是否需要改变modifyTable(MysqlCompareTableInfo mysqlCompareTableInfo) 生成修改表SQLjava字段类型与数据库类型映射关系从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 org.dromara.autotable.core.strategy.IStrategy
checkTableNotExist, createMode, createTable, executeCreateTable, executeReturn, executeSql, getMapperClass, start, start, updateMode, validateMode
-
构造器详细资料
-
MysqlStrategy
public MysqlStrategy()
-
-
方法详细资料
-
databaseDialect
从接口复制的说明:IStrategy策略对应的数据库方言,与数据库驱动中的接口DatabaseMetaData.getDatabaseProductName()实现返回值一致- 指定者:
databaseDialect在接口中IStrategy<MysqlTableMetadata,MysqlCompareTableInfo, MysqlTablesMapper> - 返回:
- 方言
-
typeMapping
从接口复制的说明:IStrategyjava字段类型与数据库类型映射关系- 指定者:
typeMapping在接口中IStrategy<MysqlTableMetadata,MysqlCompareTableInfo, MysqlTablesMapper> - 返回:
- 映射
-
dropTable
从接口复制的说明:IStrategy根据表名删除表,生成删除表的SQL- 指定者:
dropTable在接口中IStrategy<MysqlTableMetadata,MysqlCompareTableInfo, MysqlTablesMapper> - 参数:
schema- schematableName- 表名- 返回:
- SQL
-
analyseClass
从接口复制的说明:IStrategy分析Bean,得到元数据信息- 指定者:
analyseClass在接口中IStrategy<MysqlTableMetadata,MysqlCompareTableInfo, MysqlTablesMapper> - 参数:
beanClass- 待分析的class- 返回:
- 表元信息
-
createTable
从接口复制的说明:IStrategy生成创建表SQL- 指定者:
createTable在接口中IStrategy<MysqlTableMetadata,MysqlCompareTableInfo, MysqlTablesMapper> - 参数:
tableMetadata- 表元数据- 返回:
- SQL
-
compareTable
从接口复制的说明:IStrategy对比表与bean的差异- 指定者:
compareTable在接口中IStrategy<MysqlTableMetadata,MysqlCompareTableInfo, MysqlTablesMapper> - 参数:
tableMetadata- 表元数据- 返回:
- 待修改的表信息描述
-
modifyTable
从接口复制的说明:IStrategy生成修改表SQL- 指定者:
modifyTable在接口中IStrategy<MysqlTableMetadata,MysqlCompareTableInfo, MysqlTablesMapper> - 参数:
mysqlCompareTableInfo- 修改表的描述信息- 返回:
- SQL
-
compareIndexes
private void compareIndexes(MysqlTableMetadata mysqlTableMetadata, MysqlCompareTableInfo mysqlCompareTableInfo, Map<String, List<InformationSchemaStatistics>> tableIndexes) -
comparePrimary
private static void comparePrimary(MysqlTableMetadata mysqlTableMetadata, MysqlCompareTableInfo mysqlCompareTableInfo, List<InformationSchemaStatistics> tablePrimaries) -
compareColumns
private void compareColumns(MysqlTableMetadata mysqlTableMetadata, String tableName, MysqlCompareTableInfo mysqlCompareTableInfo) 对比列的不同 -
isCharsetChanged
private static boolean isCharsetChanged(InformationSchemaColumn informationSchemaColumn, MysqlColumnMetadata mysqlColumnMetadata) -
isDefaultValueChanged
private static boolean isDefaultValueChanged(InformationSchemaColumn informationSchemaColumn, MysqlColumnMetadata mysqlColumnMetadata) -
isFieldTypeChanged
private static boolean isFieldTypeChanged(InformationSchemaColumn informationSchemaColumn, MysqlColumnMetadata mysqlColumnMetadata) 字段类型比对是否需要改变 -
isCommentChanged
private static boolean isCommentChanged(InformationSchemaColumn informationSchemaColumn, MysqlColumnMetadata mysqlColumnMetadata) -
compareTableProperties
private static void compareTableProperties(MysqlTableMetadata mysqlTableMetadata, InformationSchemaTable tableInformation, MysqlCompareTableInfo mysqlCompareTableInfo)
-