Skip to content

Commit

Permalink
Merge pull request #27 from ClearXs/1.1.x
Browse files Browse the repository at this point in the history
fix: downgrade jdk version to 21 and fix postgresql ddl comment problem
  • Loading branch information
ClearXs authored Aug 3, 2024
2 parents bb9aff2 + 8a12964 commit 7a3952e
Show file tree
Hide file tree
Showing 18 changed files with 132 additions and 47 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</modules>

<properties>
<java.version>22</java.version>
<java.version>21</java.version>
<drools.version>9.44.0.Final</drools.version>
<reactor-bom>2023.0.6</reactor-bom>
<spring.boot.version>3.3.0</spring.boot.version>
Expand Down Expand Up @@ -204,4 +204,4 @@
<url>https://packages.aliyun.com/maven/repository/2300285-snapshot-JAW5GT/</url>
</snapshotRepository>
</distributionManagement>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,16 @@ default T groupByOne(Collection<String> fieldNames) {
// ====================== advanced method ======================

/**
* build tree query operator
*
* @param query the build tree query base query operator
* @return self
*/
T tree(QueryOperator<?> query);

/**
* <b>recursive tree select</b>
*
* build tree query operator
* <p><b>the entity field muse contains id and parent_id</b></p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private Table obtainTable() {
TableResolver tableResolver =
TABLE_RESOLVES.computeIfAbsent(
pojoClass,
_ -> {
p -> {
Class<? extends TableResolver> tableResolverClass = tableResolve.value();
return Optional.ofNullable(tableResolverClass)
.map(ClassUtils::newInstance)
Expand Down Expand Up @@ -244,7 +244,7 @@ private List<ColumnDef> obtainColumnDefs() {
ColumnDefListResolver columnDefListResolver =
CLASS_COLUMN_LIST_RESOLVERS.computeIfAbsent(
pojoClass,
_ -> {
f -> {
Class<? extends ColumnDefListResolver> columnDefResolverClass = columnDefListResolve.value();
return Optional.ofNullable(columnDefResolverClass)
.map(ClassUtils::newInstance)
Expand Down Expand Up @@ -302,7 +302,7 @@ private ColumnDef createColumnDef(Field field) {
.flatMap(c -> {
ColumnDefResolver columnDefResolver = COLUMN_RESOLVES.computeIfAbsent(
field,
_ -> {
k -> {
Class<? extends ColumnDefResolver> columnResolverClass = columnDefResolve.value();
return Optional.ofNullable(columnResolverClass)
.map(ClassUtils::newInstance)
Expand Down Expand Up @@ -500,7 +500,7 @@ private static PojoInspect getPojoInspection(Class<?> pojoClass) {
return Optional.ofNullable(pojoInspection)
.map(p -> {
Class<? extends PojoInspect> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ public MetaAcceptorQueryOperator groupByOnes(Collection<DSLName> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ public <T extends AggregateCommandExecutor> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,11 @@ public BaseQueryFilter groupByOnes(Collection<DSLName> fieldNames) {
return self();
}

@Override
public BaseQueryFilter tree(QueryOperator<?> query) {
return null;
}

@Override
public BaseQueryFilter tree(QueryOperator<?> baseQuery, QueryOperator<?> subQuery) {
queryOperator.tree(baseQuery, subQuery);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ public EsQueryOperator groupByOnes(Collection<DSLName> 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
Expand Down Expand Up @@ -246,4 +251,4 @@ private void addDefaultQuery() {
matchAll();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ public InfluxdbQueryOperator groupByOnes(Collection<DSLName> 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)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,13 @@ public MongodbQueryOperator groupByOnes(Collection<DSLName> 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public List<Operator<?>> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SQLCreateTableOperator implements CreateTableOperator<SQLCreateTabl
private Table table;
private SQLCreateTableStatement createTableStatement;
private String comment;
private final List<ColumnDef> columnDefs = Lists.newArrayList();
private final List<ColumnDef> commentColumnDefList = Lists.newArrayList();

public SQLCreateTableOperator() {
this(DBType.getSystemDbType());
Expand Down Expand Up @@ -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();
Expand All @@ -105,40 +106,39 @@ 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();
}

@Override
public SQLCreateTableOperator comment(String comment) {
this.comment = comment;
if (DBType.POSTGRESQL == dbType) {
this.comment = comment;
}

createTableStatement.setComment(new SQLIdentifierExpr(comment));
return self();
}

@Override
public List<Operator<?>> getPostOperatorList() {
List<Operator<?>> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ protected DSLTypeDelegate(DSLType sqlType, Integer precision, Integer scale) {
List<DSLType> 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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public class SQLQueryOperator extends SQLWhereOperatorImpl<SQLQueryOperator> imp
// select columns缓存
private final List<String> 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
* <p>
Expand Down Expand Up @@ -306,6 +311,17 @@ public SQLQueryOperator groupByOnes(Collection<DSLName> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
}
Expand Down
Loading

0 comments on commit 7a3952e

Please sign in to comment.