From 8a12964d01b50b6901316c5ce0d32ccd83f5d064 Mon Sep 17 00:00:00 2001 From: "j.x" Date: Fri, 2 Aug 2024 10:57:24 +0800 Subject: [PATCH] fix: downgrade jdk version to 21 and fix postgresql ddl comment problem --- pom.xml | 4 +- .../uno/data/orm/dsl/dml/QueryOperator.java | 10 +++++ .../uno/data/orm/dsl/helper/PojoWrapper.java | 8 ++-- .../MetaAcceptorQueryOperator.java | 6 +++ .../allio/uno/data/orm/dsl/type/DSLType.java | 2 +- .../executor/CommandExecutorRegistryImpl.java | 10 ++--- .../allio/uno/data/query/BaseQueryFilter.java | 5 +++ .../db/DbCommandExecutorProcessor.java | 2 +- .../elasticsearch/dml/EsQueryOperator.java | 7 +++- .../influxdb/dml/InfluxdbQueryOperator.java | 5 +++ .../dsl/mongodb/dml/MongodbQueryOperator.java | 7 +++- .../data/orm/dsl/sql/ddl/DDLSQLSupport.java | 26 ++++++++++-- .../dsl/sql/ddl/SQLAlterTableOperator.java | 2 +- .../dsl/sql/ddl/SQLCreateTableOperator.java | 40 +++++++++---------- .../dsl/sql/dialect/type/DSLTypeDelegate.java | 5 +-- .../orm/dsl/sql/dml/SQLQueryOperator.java | 16 ++++++++ .../orm/dsl/type/DruidDataTypeAdapter.java | 8 ++-- .../orm/dsl/ddl/sql/DDLSQLSupportTest.java | 16 +++++++- 18 files changed, 132 insertions(+), 47 deletions(-) diff --git a/pom.xml b/pom.xml index b92c3b6..09ac983 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ - 22 + 21 9.44.0.Final 2023.0.6 3.3.0 @@ -204,4 +204,4 @@ https://packages.aliyun.com/maven/repository/2300285-snapshot-JAW5GT/ - \ No newline at end of file + diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/QueryOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/QueryOperator.java index c98e3bf..9457271 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/QueryOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/dml/QueryOperator.java @@ -739,6 +739,16 @@ default T groupByOne(Collection fieldNames) { // ====================== advanced method ====================== /** + * build tree query operator + * + * @param query the build tree query base query operator + * @return self + */ + T tree(QueryOperator query); + + /** + * recursive tree select + * * build tree query operator *

the entity field muse contains id and parent_id

* diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/helper/PojoWrapper.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/helper/PojoWrapper.java index 65e7609..5cb94a2 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/helper/PojoWrapper.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/helper/PojoWrapper.java @@ -181,7 +181,7 @@ private Table obtainTable() { TableResolver tableResolver = TABLE_RESOLVES.computeIfAbsent( pojoClass, - _ -> { + p -> { Class tableResolverClass = tableResolve.value(); return Optional.ofNullable(tableResolverClass) .map(ClassUtils::newInstance) @@ -244,7 +244,7 @@ private List obtainColumnDefs() { ColumnDefListResolver columnDefListResolver = CLASS_COLUMN_LIST_RESOLVERS.computeIfAbsent( pojoClass, - _ -> { + f -> { Class columnDefResolverClass = columnDefListResolve.value(); return Optional.ofNullable(columnDefResolverClass) .map(ClassUtils::newInstance) @@ -302,7 +302,7 @@ private ColumnDef createColumnDef(Field field) { .flatMap(c -> { ColumnDefResolver columnDefResolver = COLUMN_RESOLVES.computeIfAbsent( field, - _ -> { + k -> { Class columnResolverClass = columnDefResolve.value(); return Optional.ofNullable(columnResolverClass) .map(ClassUtils::newInstance) @@ -500,7 +500,7 @@ private static PojoInspect getPojoInspection(Class pojoClass) { return Optional.ofNullable(pojoInspection) .map(p -> { Class pojoInspectClass = p.value(); - return POJO_INSPECTS.computeIfAbsent(pojoClass, _ -> Optional.ofNullable(pojoInspectClass).map(ClassUtils::newInstance).orElse(null)); + return POJO_INSPECTS.computeIfAbsent(pojoClass, f -> Optional.ofNullable(pojoInspectClass).map(ClassUtils::newInstance).orElse(null)); }) .orElse(DEFAULT_POJO_INSPECT); } diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorQueryOperator.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorQueryOperator.java index 9a82010..639a44b 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorQueryOperator.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/opeartorgroup/MetaAcceptorQueryOperator.java @@ -105,6 +105,12 @@ public MetaAcceptorQueryOperator groupByOnes(Collection fieldNames) { return self(); } + @Override + public MetaAcceptorQueryOperator tree(QueryOperator query) { + actual.tree(query); + return self(); + } + @Override public MetaAcceptorQueryOperator tree(QueryOperator baseQuery, QueryOperator subQuery) { actual.tree(baseQuery, subQuery); diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/type/DSLType.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/type/DSLType.java index 4c2bdaf..aaf3155 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/type/DSLType.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/dsl/type/DSLType.java @@ -196,7 +196,7 @@ enum DefaultDSLType implements DSLType { LONGVARBINARY("longvarchar", Types.LONGVARBINARY, 2048, null), // ====================== 其他类型 ====================== - BOOLEAN("char", Types.BOOLEAN, 0, null), + BOOLEAN("boolean", Types.BOOLEAN, 0, null), // ====================== 高级类型 ====================== OBJECT("object", Types.JAVA_OBJECT, null, null), diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandExecutorRegistryImpl.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandExecutorRegistryImpl.java index 3bb96ea..417cefb 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandExecutorRegistryImpl.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/orm/executor/CommandExecutorRegistryImpl.java @@ -86,16 +86,16 @@ public T register(ExecutorOptions executorO } T commandExecutor; if (ifPresent) { - commandExecutor = (T) commandExecutorMap.compute(key, (_, _) -> commandExecutorSupplier.get()); - optionsKeyMap.compute(executorOptions, (_, _) -> key); + commandExecutor = (T) commandExecutorMap.compute(key, (k, v) -> commandExecutorSupplier.get()); + optionsKeyMap.compute(executorOptions, (k, v) -> key); } else { - commandExecutor = (T) commandExecutorMap.computeIfAbsent(key, _ -> commandExecutorSupplier.get()); - optionsKeyMap.computeIfAbsent(executorOptions, _ -> key); + commandExecutor = (T) commandExecutorMap.computeIfAbsent(key, v -> commandExecutorSupplier.get()); + optionsKeyMap.computeIfAbsent(executorOptions, k -> key); } boolean systemDefault = executorOptions.isSystemDefault(); if (systemDefault) { Envs.setProperty(ExecutorKey.DSL_EXECUTOR_TYPE_KEY, executorOptions.getExecutorKey().key()); - Envs.setProperty(AggregateCommandExecutor.DEFAULT_KEY, key); + Envs.setProperty(CommandExecutor.DEFAULT_KEY, key); } return commandExecutor; } finally { diff --git a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/query/BaseQueryFilter.java b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/query/BaseQueryFilter.java index 113e7e7..146911d 100644 --- a/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/query/BaseQueryFilter.java +++ b/uno-data/uno-data-api/src/main/java/cc/allio/uno/data/query/BaseQueryFilter.java @@ -303,6 +303,11 @@ public BaseQueryFilter groupByOnes(Collection fieldNames) { return self(); } + @Override + public BaseQueryFilter tree(QueryOperator query) { + return null; + } + @Override public BaseQueryFilter tree(QueryOperator baseQuery, QueryOperator subQuery) { queryOperator.tree(baseQuery, subQuery); diff --git a/uno-data/uno-data-db/src/main/java/cc/allio/uno/data/orm/executor/db/DbCommandExecutorProcessor.java b/uno-data/uno-data-db/src/main/java/cc/allio/uno/data/orm/executor/db/DbCommandExecutorProcessor.java index 2d7681d..f77b1ae 100644 --- a/uno-data/uno-data-db/src/main/java/cc/allio/uno/data/orm/executor/db/DbCommandExecutorProcessor.java +++ b/uno-data/uno-data-db/src/main/java/cc/allio/uno/data/orm/executor/db/DbCommandExecutorProcessor.java @@ -30,7 +30,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw proxyFactory.addAspect(DbCommandExecutorAspect.class); NameMatchMethodPointcut pointcut = new NameMatchMethodPointcut(); pointcut.setMappedName("getExecutor"); - MethodInterceptor methodInterceptor = _ -> CommandExecutorFactory.getDSLExecutor(ExecutorKey.DB); + MethodInterceptor methodInterceptor = e -> CommandExecutorFactory.getDSLExecutor(ExecutorKey.DB); proxyFactory.addAdvisor(new DefaultPointcutAdvisor(pointcut, methodInterceptor)); return proxyFactory.getProxy(); } diff --git a/uno-data/uno-data-elasticsearch/src/main/java/cc/allio/uno/data/orm/dsl/elasticsearch/dml/EsQueryOperator.java b/uno-data/uno-data-elasticsearch/src/main/java/cc/allio/uno/data/orm/dsl/elasticsearch/dml/EsQueryOperator.java index 8a1d06e..bc19a2a 100644 --- a/uno-data/uno-data-elasticsearch/src/main/java/cc/allio/uno/data/orm/dsl/elasticsearch/dml/EsQueryOperator.java +++ b/uno-data/uno-data-elasticsearch/src/main/java/cc/allio/uno/data/orm/dsl/elasticsearch/dml/EsQueryOperator.java @@ -213,6 +213,11 @@ public EsQueryOperator groupByOnes(Collection fieldNames) { throw new DSLException(ERROR_MSG); } + @Override + public EsQueryOperator tree(QueryOperator query) { + return self(); + } + @Override public EsQueryOperator tree(QueryOperator baseQuery, QueryOperator subQuery) { // nothing to do @@ -246,4 +251,4 @@ private void addDefaultQuery() { matchAll(); } } -} \ No newline at end of file +} diff --git a/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/dsl/influxdb/dml/InfluxdbQueryOperator.java b/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/dsl/influxdb/dml/InfluxdbQueryOperator.java index 3b4426a..ec07005 100644 --- a/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/dsl/influxdb/dml/InfluxdbQueryOperator.java +++ b/uno-data/uno-data-influxdb/src/main/java/cc/allio/uno/data/orm/dsl/influxdb/dml/InfluxdbQueryOperator.java @@ -121,6 +121,11 @@ public InfluxdbQueryOperator groupByOnes(Collection fieldNames) { return self(); } + @Override + public InfluxdbQueryOperator tree(QueryOperator query) { + return self(); + } + @Override public InfluxdbQueryOperator tree(QueryOperator baseQuery, QueryOperator subQuery) { throw Exceptions.unOperate("tree(QueryOperator baseQuery, QueryOperator subQuery)"); diff --git a/uno-data/uno-data-mongodb/src/main/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbQueryOperator.java b/uno-data/uno-data-mongodb/src/main/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbQueryOperator.java index efc3849..07ef13f 100644 --- a/uno-data/uno-data-mongodb/src/main/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbQueryOperator.java +++ b/uno-data/uno-data-mongodb/src/main/java/cc/allio/uno/data/orm/dsl/mongodb/dml/MongodbQueryOperator.java @@ -192,8 +192,13 @@ public MongodbQueryOperator groupByOnes(Collection fieldNames) { return self(); } + @Override + public MongodbQueryOperator tree(QueryOperator query) { + return self(); + } + @Override public MongodbQueryOperator tree(QueryOperator baseQuery, QueryOperator subQuery) { - throw Exceptions.unOperate("tree"); + return self(); } } diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/DDLSQLSupport.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/DDLSQLSupport.java index f6778e8..8cdb7a4 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/DDLSQLSupport.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/DDLSQLSupport.java @@ -92,15 +92,35 @@ public static SQLColumnDefinition createColumnDefinition(ColumnDef columnDef, DB return sqlColumnDefinition; } + /** + * create druid {@link SQLCommentStatement} instance + * + * @param comment the table comment + * @param table the {@link Table} instance + * @param dbType the {@link DBType} + * @return the table {@link SQLCommentStatement} instance + */ + public static SQLCommentStatement createTableCommentStatement(String comment, Table table, DBType dbType) { + var druidType = DruidDbTypeAdapter.getInstance().adapt(dbType); + SQLCommentStatement tableComment = new SQLCommentStatement(); + SQLExprTableSource tableSource = DDLSQLSupport.createTableSource(table, dbType); + tableComment.setComment(new SQLCharExpr(comment)); + tableComment.setType(SQLCommentStatement.Type.TABLE); + tableComment.setOn(tableSource); + tableComment.setDbType(druidType); + return tableComment; + } + /** * create druid {@link SQLCommentStatement} instance * * @param columnDef the {@link ColumnDef} instance * @param table the {@link Table} instance * @param dbType the {@link DbType} - * @return the {@link SQLCommentStatement} instance + * @return the column {@link SQLCommentStatement} instance */ - public static SQLCommentStatement createCommentStatement(ColumnDef columnDef, Table table, DbType dbType) { + public static SQLCommentStatement createCommentStatement(ColumnDef columnDef, Table table, DBType dbType) { + var druidType = DruidDbTypeAdapter.getInstance().adapt(dbType); String columnCommentInfo = columnDef.getComment(); SQLCommentStatement columnComment = new SQLCommentStatement(); SQLExprTableSource tableSource = new SQLExprTableSource(); @@ -121,7 +141,7 @@ public static SQLCommentStatement createCommentStatement(ColumnDef columnDef, Ta columnComment.setComment(new SQLCharExpr(columnCommentInfo)); columnComment.setOn(tableSource); columnComment.setType(SQLCommentStatement.Type.COLUMN); - columnComment.setDbType(dbType); + columnComment.setDbType(druidType); return columnComment; } diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLAlterTableOperator.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLAlterTableOperator.java index 1d383a0..7ea5d57 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLAlterTableOperator.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLAlterTableOperator.java @@ -180,7 +180,7 @@ public List> getPostOperatorList() { for (ColumnDef columnDef : commentColumnDefList) { String columnCommentInfo = columnDef.getComment(); if (StringUtils.isNotBlank(columnCommentInfo)) { - SQLCommentStatement commentStatement = DDLSQLSupport.createCommentStatement(columnDef, from, druidDbType); + SQLCommentStatement commentStatement = DDLSQLSupport.createCommentStatement(columnDef, from, dbType); String columnCommentSQL = SQLUtils.toSQLString(commentStatement, druidDbType); commentOperatorList.add(Operator.from(columnCommentSQL)); } diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLCreateTableOperator.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLCreateTableOperator.java index d12ee14..ae6bbcb 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLCreateTableOperator.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/ddl/SQLCreateTableOperator.java @@ -34,7 +34,7 @@ public class SQLCreateTableOperator implements CreateTableOperator columnDefs = Lists.newArrayList(); + private final List commentColumnDefList = Lists.newArrayList(); public SQLCreateTableOperator() { this(DBType.getSystemDbType()); @@ -93,6 +93,7 @@ public SQLCreateTableOperator from(String table) { @Override public SQLCreateTableOperator from(Table table) { this.table = table; + comment(table.getComment()); SQLExprTableSource tableSource = DDLSQLSupport.createTableSource(table, dbType); createTableStatement.setTableSource(tableSource); return self(); @@ -105,7 +106,9 @@ public Table getTable() { @Override public SQLCreateTableOperator column(ColumnDef columnDef) { - columnDefs.add(columnDef); + if (DBType.POSTGRESQL == dbType) { + commentColumnDefList.add(columnDef); + } SQLColumnDefinition columnDefinition = DDLSQLSupport.createColumnDefinition(columnDef, dbType); createTableStatement.addColumn(columnDefinition); return self(); @@ -113,7 +116,10 @@ public SQLCreateTableOperator column(ColumnDef columnDef) { @Override public SQLCreateTableOperator comment(String comment) { - this.comment = comment; + if (DBType.POSTGRESQL == dbType) { + this.comment = comment; + } + createTableStatement.setComment(new SQLIdentifierExpr(comment)); return self(); } @@ -121,24 +127,18 @@ public SQLCreateTableOperator comment(String comment) { @Override public List> getPostOperatorList() { List> commentOperatorList = Lists.newArrayList(); - if (DBType.POSTGRESQL == dbType) { - if (StringUtils.isNotBlank(comment)) { - SQLCommentStatement tableComment = new SQLCommentStatement(); - tableComment.setComment(new SQLIdentifierExpr(comment)); - tableComment.setType(SQLCommentStatement.Type.TABLE); - SQLExprTableSource tableSource = DDLSQLSupport.createTableSource(table, dbType); - tableComment.setOn(tableSource); - String tableCommentSQL = SQLUtils.toSQLString(tableSource, druidType); - commentOperatorList.add(Operator.from(tableCommentSQL)); - } + if (StringUtils.isNotBlank(comment)) { + SQLCommentStatement tableComment = DDLSQLSupport.createTableCommentStatement(comment, table, dbType); + String tableCommentSQL = SQLUtils.toSQLString(tableComment, druidType); + commentOperatorList.add(Operator.from(tableCommentSQL)); + } - for (ColumnDef columnDef : columnDefs) { - String columnCommentInfo = columnDef.getComment(); - if (StringUtils.isNotBlank(columnCommentInfo)) { - SQLCommentStatement commentStatement = DDLSQLSupport.createCommentStatement(columnDef, table, druidType); - String columnCommentSQL = SQLUtils.toSQLString(commentStatement, druidType); - commentOperatorList.add(Operator.from(columnCommentSQL)); - } + for (ColumnDef columnDef : commentColumnDefList) { + String columnCommentInfo = columnDef.getComment(); + if (StringUtils.isNotBlank(columnCommentInfo)) { + SQLCommentStatement commentStatement = DDLSQLSupport.createCommentStatement(columnDef, table, dbType); + String columnCommentSQL = SQLUtils.toSQLString(commentStatement, druidType); + commentOperatorList.add(Operator.from(columnCommentSQL)); } } return commentOperatorList; diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/dialect/type/DSLTypeDelegate.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/dialect/type/DSLTypeDelegate.java index 2ca8920..1b3d5d7 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/dialect/type/DSLTypeDelegate.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/dialect/type/DSLTypeDelegate.java @@ -25,9 +25,8 @@ protected DSLTypeDelegate(DSLType sqlType, Integer precision, Integer scale) { List parent = linkType.getParent(); if (parent.stream().anyMatch(p -> p.getName().equals(sqlType.getName()))) { dslType = linkType; - // 优先取link的定义 - precision = dslType.getPrecision(); - scale = dslType.getScale(); + precision = linkType.getPrecision(); + scale = linkType.getScale(); break; } } diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/dml/SQLQueryOperator.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/dml/SQLQueryOperator.java index 72f5eec..b8ba39d 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/dml/SQLQueryOperator.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/sql/dml/SQLQueryOperator.java @@ -62,6 +62,11 @@ public class SQLQueryOperator extends SQLWhereOperatorImpl imp // select columns缓存 private final List columns = Lists.newArrayList(); + /** + * 非递归的 + */ + static final String NON_RECURSIVE_QUERY_TEMPLATE = "WITH RECURSIVE biz_tree AS (#{query}) SELECT #{columns} FROM biz_tree"; + /** * tree query template, like as *

@@ -306,6 +311,17 @@ public SQLQueryOperator groupByOnes(Collection fieldNames) { return self(); } + @Override + public SQLQueryOperator tree(QueryOperator query) { + String baseQueryDsl = query.getDSL(); + String treeQuery = + ExpressionTemplate.parse( + NON_RECURSIVE_QUERY_TEMPLATE, + "query", baseQueryDsl, + "columns", String.join(StringPool.COMMA, query.obtainSelectColumns())); + return customize(treeQuery); + } + @Override public SQLQueryOperator tree(QueryOperator baseQuery, QueryOperator subQuery) { String baseQueryDsl = baseQuery.getDSL(); diff --git a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/type/DruidDataTypeAdapter.java b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/type/DruidDataTypeAdapter.java index 72a8e03..1ec896a 100644 --- a/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/type/DruidDataTypeAdapter.java +++ b/uno-data/uno-data-sql/src/main/java/cc/allio/uno/data/orm/dsl/type/DruidDataTypeAdapter.java @@ -65,10 +65,10 @@ public SQLDataType adapt(DataType o) { case DefaultDSLType.DECIMAL: SQLDataTypeImpl decimalDataType = new SQLDataTypeImpl(dbSQLType.getName()); if (precision != null) { - decimalDataType.addArgument(new SQLIntegerExpr(dataType.getPrecision())); + decimalDataType.addArgument(new SQLIntegerExpr(precision)); } if (scale != null) { - decimalDataType.addArgument(new SQLIntegerExpr(dataType.getPrecision())); + decimalDataType.addArgument(new SQLIntegerExpr(precision)); } return decimalDataType; case DefaultDSLType.DATE, @@ -81,7 +81,9 @@ public SQLDataType adapt(DataType o) { return dateDataType; default: SQLDataTypeImpl charDataType = new SQLDataTypeImpl(dbSQLType.getName()); - charDataType.addArgument(new SQLIntegerExpr(dataType.getPrecision())); + if (precision != null) { + charDataType.addArgument(new SQLIntegerExpr(precision)); + } return charDataType; } } diff --git a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/DDLSQLSupportTest.java b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/DDLSQLSupportTest.java index 9a71e1e..a5ba0bb 100644 --- a/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/DDLSQLSupportTest.java +++ b/uno-data/uno-data-sql/src/test/java/cc/allio/uno/data/orm/dsl/ddl/sql/DDLSQLSupportTest.java @@ -4,14 +4,26 @@ import cc.allio.uno.data.orm.dsl.DSLName; import cc.allio.uno.data.orm.dsl.Table; import cc.allio.uno.data.orm.dsl.sql.ddl.DDLSQLSupport; +import cc.allio.uno.data.orm.dsl.type.DBType; import cc.allio.uno.test.BaseTestCase; -import com.alibaba.druid.DbType; import com.alibaba.druid.sql.SQLUtils; import com.alibaba.druid.sql.ast.statement.SQLCommentStatement; import org.junit.jupiter.api.Test; public class DDLSQLSupportTest extends BaseTestCase { + @Test + void testCreateTableCommentStatement() { + Table table = new Table(); + table.setName(DSLName.of("dual")); + SQLCommentStatement tableCommentStatement = DDLSQLSupport.createTableCommentStatement("test", table, DBType.POSTGRESQL); + + String sqlString = SQLUtils.toSQLString(tableCommentStatement); + + assertEquals("COMMENT ON TABLE PUBLIC.dual IS 'test'", sqlString); + + } + @Test void testCreateCommentStatement() { @@ -24,7 +36,7 @@ void testCreateCommentStatement() { Table table = new Table(); table.setName(DSLName.of("dual")); - SQLCommentStatement commentStatement = DDLSQLSupport.createCommentStatement(columnDef, table, DbType.postgresql); + SQLCommentStatement commentStatement = DDLSQLSupport.createCommentStatement(columnDef, table, DBType.POSTGRESQL); String sqlString = SQLUtils.toSQLString(commentStatement);