From 89ea36d58ef7d8b9452ed23f9a13f037cd3be2e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Sat, 6 May 2023 16:23:24 +0800 Subject: [PATCH] v1.2.1 release (^.^)YYa!! --- .../com/mybatisflex/core/table/TableInfo.java | 29 +++++++++++++++---- .../core/table/TableInfoFactory.java | 2 +- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java index 132e421f..628ae344 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfo.java @@ -527,6 +527,25 @@ public class TableInfo { CPI.putContext(queryWrapper, APPEND_CONDITIONS_FLAG, Boolean.TRUE); } + //select * from (select ... from ) 中的子查询处理 + List queryTables = CPI.getQueryTables(queryWrapper); + if (queryTables != null && !queryTables.isEmpty()) { + for (QueryTable queryTable : queryTables) { + if (queryTable instanceof SelectQueryTable) { + QueryWrapper selectQueryWrapper = ((SelectQueryTable) queryTable).getQueryWrapper(); + List selectQueryTables = CPI.getQueryTables(selectQueryWrapper); + if (selectQueryTables != null && !selectQueryTables.isEmpty()) { + for (QueryTable selectQueryTable : selectQueryTables) { + TableInfo tableInfo = TableInfoFactory.ofTableName(selectQueryTable.getName()); + if (tableInfo != null) { + tableInfo.appendConditions(entity, selectQueryWrapper); + } + } + } + } + } + } + //添加乐观锁条件,只有在 update 的时候进行处理 if (StringUtil.isNotBlank(versionColumn) && entity != null) { Object versionValue = buildColumnSqlArg(entity, versionColumn); @@ -536,7 +555,7 @@ public class TableInfo { queryWrapper.and(QueryCondition.create(tableName, versionColumn, QueryCondition.LOGIC_EQUALS, versionValue)); } - //逻辑删除条件,已删除的数据不能被修改 + //逻辑删除 if (StringUtil.isNotBlank(logicDeleteColumn)) { queryWrapper.and(QueryCondition.create(tableName, logicDeleteColumn, QueryCondition.LOGIC_EQUALS , FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete())); @@ -556,8 +575,8 @@ public class TableInfo { List childSelects = CPI.getChildSelect(queryWrapper); if (CollectionUtil.isNotEmpty(childSelects)) { for (QueryWrapper childQueryWrapper : childSelects) { - List queryTables = CPI.getQueryTables(childQueryWrapper); - for (QueryTable queryTable : queryTables) { + List childQueryTables = CPI.getQueryTables(childQueryWrapper); + for (QueryTable queryTable : childQueryTables) { TableInfo tableInfo = TableInfoFactory.ofTableName(queryTable.getName()); if (tableInfo != null) { tableInfo.appendConditions(entity, childQueryWrapper); @@ -571,8 +590,8 @@ public class TableInfo { if (CollectionUtil.isNotEmpty(unions)) { for (UnionWrapper union : unions) { QueryWrapper unionQueryWrapper = union.getQueryWrapper(); - List queryTables = CPI.getQueryTables(unionQueryWrapper); - for (QueryTable queryTable : queryTables) { + List unionQueryTables = CPI.getQueryTables(unionQueryWrapper); + for (QueryTable queryTable : unionQueryTables) { TableInfo tableInfo = TableInfoFactory.ofTableName(queryTable.getName()); if (tableInfo != null) { tableInfo.appendConditions(entity, unionQueryWrapper); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java index 9885b723..8b25820e 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableInfoFactory.java @@ -89,7 +89,7 @@ public class TableInfoFactory { public static TableInfo ofTableName(String tableName) { - return tableInfoMap.get(tableName); + return StringUtil.isNotBlank(tableName) ? tableInfoMap.get(tableName) : null; }