diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/jpa/JpaEntityTableMetadataParserProcessor.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/jpa/JpaEntityTableMetadataParserProcessor.java index 18a965c2..8576a3c7 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/jpa/JpaEntityTableMetadataParserProcessor.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/mapping/jpa/JpaEntityTableMetadataParserProcessor.java @@ -357,7 +357,7 @@ private void handleColumnAnnotation(PropertyDescriptor descriptor, Set javaType) { return CustomDataType.of(id, name, sqlType, javaType); } diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/RDBColumnMetadata.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/RDBColumnMetadata.java index 272e0829..e39fc2b8 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/RDBColumnMetadata.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/RDBColumnMetadata.java @@ -128,12 +128,19 @@ public void setJdbcType(SQLType jdbcType, Class javaType) { setType(JdbcDataType.of(jdbcType, javaType)); } + public int getLength(int length) { + if (this.length <= 0) { + return length; + } + return this.length; + } + public int getPrecision(int defaultPrecision) { if (precision <= 0) { if (length <= 0) { return defaultPrecision; } else { - return length; + return Math.min(length, defaultPrecision); } } return precision; diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/dialect/DefaultDialect.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/dialect/DefaultDialect.java index 04ff8a57..25fbbccf 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/dialect/DefaultDialect.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/metadata/dialect/DefaultDialect.java @@ -34,10 +34,10 @@ public DefaultDialect() { defaultDataTypeBuilder = (meta) -> meta.getType().getName().toLowerCase(); registerDataType("varchar", DataType.builder(DataType.jdbc(JDBCType.VARCHAR, String.class), - column -> "varchar(" + column.getLength() + ")")); + column -> "varchar(" + column.getLength(255) + ")")); registerDataType("nvarchar", DataType.builder(DataType.jdbc(JDBCType.NVARCHAR, String.class), - column -> "nvarchar(" + column.getLength() + ")")); + column -> "nvarchar(" + column.getLength(255) + ")")); registerDataType("decimal", DataType.builder(DataType.jdbc(JDBCType.DECIMAL, BigDecimal.class), column -> "decimal(" + column.getPrecision(32) + "," + column.getScale() + ")")); diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/mssql/SqlServer2012TableMetadataParser.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/mssql/SqlServer2012TableMetadataParser.java index b417158a..6baf59c7 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/mssql/SqlServer2012TableMetadataParser.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/mssql/SqlServer2012TableMetadataParser.java @@ -54,9 +54,11 @@ protected String getTableMetaSql(String tname) { @Override protected String getTableCommentSql(String tname) { - return "select cast(p.value as varchar(500)) as comment " + - "from sys.extended_properties p " + - " where p.major_id=object_id(#{table}) and p.minor_id=0"; + return "select cast(ep.value as nvarchar(500)) as [comment],t.name as [table_name]" + + " from sys.tables t" + + " LEFT JOIN"+ + " sys.extended_properties ep ON t.object_id = ep.major_id AND ep.name = 'MS_Description'"+ + " where ep.minor_id=0 and t.schema_id = SCHEMA_ID(#{schema}) and t.name like #{table}"; } @Override diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/postgres/PostgresqlDialect.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/postgres/PostgresqlDialect.java index 0b16a414..5d25c47b 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/postgres/PostgresqlDialect.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/postgres/PostgresqlDialect.java @@ -17,8 +17,8 @@ public class PostgresqlDialect extends DefaultDialect { public PostgresqlDialect() { - addDataTypeBuilder(JDBCType.CHAR, (meta) -> StringUtils.concat("char(", meta.getLength(), ")")); - addDataTypeBuilder(JDBCType.VARCHAR, (meta) -> StringUtils.concat("varchar(", meta.getLength(), ")")); + addDataTypeBuilder(JDBCType.CHAR, (meta) -> StringUtils.concat("char(", meta.getLength(255), ")")); + addDataTypeBuilder(JDBCType.VARCHAR, (meta) -> StringUtils.concat("varchar(", meta.getLength(255), ")")); addDataTypeBuilder(JDBCType.TIMESTAMP, (meta) -> "timestamp"); addDataTypeBuilder(JDBCType.TIME, (meta) -> "time"); addDataTypeBuilder(JDBCType.DATE, (meta) -> "date"); diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/postgres/PostgresqlTableMetadataParser.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/postgres/PostgresqlTableMetadataParser.java index a8d1647e..54079c53 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/postgres/PostgresqlTableMetadataParser.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/supports/postgres/PostgresqlTableMetadataParser.java @@ -58,13 +58,14 @@ public class PostgresqlTableMetadataParser extends RDBTableMetadataParser { " and table_name like #{table}" ); - private static final String TABLE_COMMENT_SQL = String.join(" ", - "select" - , "relname::varchar as \"table_name\"," - , "cast(obj_description(relfilenode,'pg_class') as varchar) as \"comment\" " - , "from pg_class c", - "where relname like #{table} and relkind = 'r' and relname not like 'pg_%'", - "and relname not like 'sql_%'" + private static final String TABLE_COMMENT_SQL = String.join(" " + , "SELECT DISTINCT \"table_name\", cast(obj_description(c.oid,'pg_class') as varchar) AS \"comment\"" + , "FROM information_schema.tables t" + , "JOIN pg_class c ON t.table_name = c.relname" + , "JOIN pg_description d ON c.oid = d.objoid" + , "WHERE t.table_schema = #{schema}" + , "AND d.objsubid = 0" + , "AND t.table_name LIKE #{table}" ); private static final String ALL_TABLE_SQL = "select table_name::varchar as \"name\" from information_schema.TABLES where table_schema=#{schema}"; diff --git a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/utils/DataTypeUtils.java b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/utils/DataTypeUtils.java index 0ff71194..4370e34e 100644 --- a/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/utils/DataTypeUtils.java +++ b/hsweb-easy-orm-rdb/src/main/java/org/hswebframework/ezorm/rdb/utils/DataTypeUtils.java @@ -51,12 +51,7 @@ public static boolean typeIsDate(DataType type) { } - public static boolean typeIsNumber(DataType type) { - if (type == null) { - return false; - } - - SQLType sqlType = type.getSqlType(); + public static boolean sqlTypeIsNumber(SQLType sqlType) { if (sqlType != null) { if (sqlType instanceof JDBCType) switch (((JDBCType) sqlType)) { @@ -71,6 +66,17 @@ public static boolean typeIsNumber(DataType type) { return true; } } + return false; + } + + public static boolean typeIsNumber(DataType type) { + if (type == null) { + return false; + } + + if (sqlTypeIsNumber(type.getSqlType())) { + return true; + } if (type.getJavaType() != null) { Class clazz = type.getJavaType();