Skip to content

Commit

Permalink
增加pgsql支持
Browse files Browse the repository at this point in the history
  • Loading branch information
zhou-hao committed Jan 22, 2019
1 parent 39c6e16 commit 3026eae
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ public Object getData(Object value) {
}
};
column.setValueConverter(dateConvert);
} else if (column.getJavaType() == boolean.class || column.getJavaType() == Boolean.class) {
column.setValueConverter(new NumberValueConverter(Boolean.class));
} else if (TypeUtils.isNumberType(column)) { //数字
//数字
column.setValueConverter(new NumberValueConverter(column.getJavaType()));
}
rdbTableMetaData.addColumn(column);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,26 +120,25 @@ public static RDBTableMetaData parseMetaDataFromEntity(Class entityClass) {
.getPropertyUtils()
.getPropertyDescriptors(entityClass);
for (PropertyDescriptor descriptor : descriptors) {
Column column = getAnnotation(entityClass, descriptor, Column.class);
if (column == null) {
Column columnAnn = getAnnotation(entityClass, descriptor, Column.class);
if (columnAnn == null) {
continue;
}
RDBColumnMetaData columnMetaData = new RDBColumnMetaData();
columnMetaData.setName(column.name());
columnMetaData.setAlias(descriptor.getName());
columnMetaData.setLength(column.length());
columnMetaData.setPrecision(column.precision());
columnMetaData.setJavaType(descriptor.getPropertyType());
if (!column.updatable()) {
columnMetaData.setProperty("read-only", true);
RDBColumnMetaData column = new RDBColumnMetaData();
column.setName(columnAnn.name());
column.setAlias(descriptor.getName());
column.setLength(columnAnn.length());
column.setPrecision(columnAnn.precision());
column.setJavaType(descriptor.getPropertyType());
if (!columnAnn.updatable()) {
column.setProperty("read-only", true);
}
if (!column.nullable()) {
columnMetaData.setNotNull(true);
if (!columnAnn.nullable()) {
column.setNotNull(true);
}
if (StringUtils.hasText(column.columnDefinition())) {
columnMetaData.setColumnDefinition(column.columnDefinition());
if (StringUtils.hasText(columnAnn.columnDefinition())) {
column.setColumnDefinition(columnAnn.columnDefinition());
}

Class propertyType = descriptor.getPropertyType();

JDBCType type = jdbcTypeMapping.get(propertyType);
Expand All @@ -150,8 +149,8 @@ public static RDBTableMetaData parseMetaDataFromEntity(Class entityClass) {
.findFirst()
.orElse(JDBCType.OTHER);
}
columnMetaData.setJdbcType(type);
ValueConverter dateConvert = new DateTimeConverter("yyyy-MM-dd HH:mm:ss", columnMetaData.getJavaType()) {
column.setJdbcType(type);
ValueConverter dateConvert = new DateTimeConverter("yyyy-MM-dd HH:mm:ss", column.getJavaType()) {
@Override
public Object getData(Object value) {
if (value instanceof Number) {
Expand All @@ -161,15 +160,15 @@ public Object getData(Object value) {
}
};

if (columnMetaData.getJdbcType() == JDBCType.DATE
|| columnMetaData.getJdbcType() == JDBCType.TIMESTAMP) {
columnMetaData.setValueConverter(dateConvert);
} else if (TypeUtils.isNumberType(columnMetaData)) {
columnMetaData.setValueConverter(new NumberValueConverter(columnMetaData.getJavaType()));
if (column.getJdbcType() == JDBCType.DATE
|| column.getJdbcType() == JDBCType.TIMESTAMP) {
column.setValueConverter(dateConvert);
} else if (column.getJavaType() == boolean.class || column.getJavaType() == Boolean.class) {
column.setValueConverter(new NumberValueConverter(Boolean.class));
} else if (TypeUtils.isNumberType(column)) {
column.setValueConverter(new NumberValueConverter(column.getJavaType()));
}


tableMetaData.addColumn(columnMetaData);
tableMetaData.addColumn(column);
}
return tableMetaData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.hswebframework.ezorm.rdb.executor.SqlExecutor;
import org.hswebframework.ezorm.rdb.meta.converter.ClobValueConverter;
import org.hswebframework.ezorm.rdb.meta.converter.JSONValueConverter;
import org.hswebframework.ezorm.rdb.meta.converter.NumberValueConverter;
import org.hswebframework.ezorm.rdb.simple.wrapper.BeanWrapper;
import org.hswebframework.expands.script.engine.DynamicScriptEngine;
import org.hswebframework.expands.script.engine.DynamicScriptEngineFactory;
Expand Down Expand Up @@ -169,7 +170,9 @@ protected void initInstallInfo() throws SQLException {
.addColumn().name("major_version").alias(majorVersion).number(32).javaType(Integer.class).comment("主版本号").commit()
.addColumn().name("minor_version").alias(minorVersion).number(32).javaType(Integer.class).comment("次版本号").commit()
.addColumn().name("revision_version").alias(revisionVersion).number(32).javaType(Integer.class).comment("修订版").commit()
.addColumn().name("snapshot").number(1).javaType(Boolean.class).comment("是否快照版").commit()
.addColumn().name("snapshot").number(1).javaType(Boolean.class)
.custom(column -> column.setValueConverter(new NumberValueConverter(Boolean.class)))
.comment("是否快照版").commit()
.addColumn().name("comment").varchar(2000).comment("系统说明").commit()
.addColumn().name("website").varchar(2000).comment("系统网址").commit()
.addColumn().name("framework_version").notNull().alias(frameworkVersion).clob()
Expand Down

0 comments on commit 3026eae

Please sign in to comment.