mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
refactor: refactor JdbcTypeMapper in "codegen" module
This commit is contained in:
parent
203f4d5236
commit
0ff7384581
@ -25,6 +25,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 默认方言抽象类。
|
||||
*
|
||||
* @author michael
|
||||
*/
|
||||
public abstract class AbstractJdbcDialect implements IDialect {
|
||||
@ -46,15 +47,15 @@ public abstract class AbstractJdbcDialect implements IDialect {
|
||||
column.setRawType(columnMetaData.getColumnTypeName(i));
|
||||
column.setRawLength(columnMetaData.getColumnDisplaySize(i));
|
||||
|
||||
String jdbcType = columnMetaData.getColumnClassName(i);
|
||||
column.setPropertyType(JdbcTypeMapping.getType(jdbcType, column.getRawLength()));
|
||||
|
||||
column.setAutoIncrement(columnMetaData.isAutoIncrement(i));
|
||||
|
||||
column.setNullable(columnMetaData.isNullable(i));
|
||||
//注释
|
||||
column.setComment(columnRemarks.get(column.getName()));
|
||||
|
||||
String jdbcType = columnMetaData.getColumnClassName(i);
|
||||
column.setPropertyType(JdbcTypeMapping.getType(jdbcType, table, column));
|
||||
|
||||
table.addColumn(column);
|
||||
}
|
||||
}
|
||||
@ -104,6 +105,4 @@ public abstract class AbstractJdbcDialect implements IDialect {
|
||||
protected abstract String forBuildColumnsSql(String schema, String tableName);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.mybatisflex.codegen.dialect;
|
||||
|
||||
import com.mybatisflex.codegen.entity.Column;
|
||||
import com.mybatisflex.codegen.entity.Table;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -22,6 +24,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 字段类型映射。
|
||||
*
|
||||
* @author michael
|
||||
*/
|
||||
public class JdbcTypeMapping {
|
||||
@ -67,17 +70,19 @@ public class JdbcTypeMapping {
|
||||
registerMapping("java.time.LocalDate", "java.util.Date");
|
||||
}
|
||||
|
||||
static String getType(String jdbcType, int length) {
|
||||
static String getType(String jdbcType, Table table, Column column) {
|
||||
if (mapper != null) {
|
||||
return mapper.getType(jdbcType, length);
|
||||
String type = mapper.getType(jdbcType, table, column);
|
||||
if (StringUtil.isNotBlank(type)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
String registered = mapping.get(jdbcType);
|
||||
return StringUtil.isNotBlank(registered) ? registered : jdbcType;
|
||||
}
|
||||
|
||||
public interface JdbcTypeMapper {
|
||||
String getType(String jdbcType, int length);
|
||||
String getType(String jdbcType, Table table, Column column);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user