diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/IDialect.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/IDialect.java index 5fefcc4e..d7cc2829 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/IDialect.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/IDialect.java @@ -18,6 +18,7 @@ package com.mybatisflex.core.dialect; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Row; import com.mybatisflex.core.table.TableInfo; +import com.mybatisflex.core.table.TableManager; import java.util.List; @@ -25,6 +26,14 @@ public interface IDialect { String wrap(String keyword); + default String getRealTable(String table) { + return TableManager.getRealTable(table); + } + + default String getRealSchema(String schema) { + return TableManager.getRealSchema(schema); + } + String forHint(String hintString); String forInsertRow(String tableName, Row row); @@ -54,7 +63,6 @@ public interface IDialect { String buildWhereConditionSql(QueryWrapper queryWrapper); - //////for entity ///// String forInsertEntity(TableInfo tableInfo, Object entity, boolean ignoreNulls); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java index d0cb577e..c461acf9 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/impl/CommonsDialectImpl.java @@ -59,6 +59,7 @@ public class CommonsDialectImpl implements IDialect { return "*".equals(keyword) ? keyword : keywordWrap.wrap(keyword); } + @Override public String forHint(String hintString) { return StringUtil.isNotBlank(hintString) ? "/*+ " + hintString + " */ " : ""; @@ -81,7 +82,7 @@ public class CommonsDialectImpl implements IDialect { index++; } - String sql = "INSERT INTO " + wrap(tableName) + + String sql = "INSERT INTO " + wrap(getRealTable(tableName)) + "(" + fields + ") VALUES " + "(" + questions + ")"; return sql; @@ -111,7 +112,7 @@ public class CommonsDialectImpl implements IDialect { } } - String sql = "INSERT INTO " + wrap(tableName) + + String sql = "INSERT INTO " + wrap(getRealTable(tableName)) + "(" + fields + ") VALUES " + questions; return sql; } @@ -121,7 +122,7 @@ public class CommonsDialectImpl implements IDialect { public String forDeleteById(String tableName, String[] primaryKeys) { StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM "); - sql.append(wrap(tableName)); + sql.append(wrap(getRealTable(tableName))); sql.append(" WHERE "); for (int i = 0; i < primaryKeys.length; i++) { if (i > 0) { @@ -137,7 +138,7 @@ public class CommonsDialectImpl implements IDialect { public String forDeleteBatchByIds(String tableName, String[] primaryKeys, Object[] ids) { StringBuilder sql = new StringBuilder(); sql.append("DELETE FROM "); - sql.append(wrap(tableName)); + sql.append(wrap(getRealTable(tableName))); sql.append(" WHERE "); //多主键的场景 @@ -180,7 +181,7 @@ public class CommonsDialectImpl implements IDialect { Set modifyAttrs = row.obtainModifyAttrs(); String[] primaryKeys = RowCPI.obtainsPrimaryKeyStrings(row); - sql.append("UPDATE ").append(wrap(tableName)).append(" SET "); + sql.append("UPDATE ").append(wrap(getRealTable(tableName))).append(" SET "); int index = 0; for (Map.Entry e : row.entrySet()) { String colName = e.getKey(); @@ -215,7 +216,7 @@ public class CommonsDialectImpl implements IDialect { } String tableName = queryTables.get(0).getName(); - sql.append("UPDATE ").append(wrap(tableName)).append(" SET "); + sql.append("UPDATE ").append(wrap(getRealTable(tableName))).append(" SET "); int index = 0; for (String modifyAttr : modifyAttrs) { if (index > 0) { @@ -249,7 +250,7 @@ public class CommonsDialectImpl implements IDialect { @Override public String forSelectOneById(String tableName, String[] primaryKeys, Object[] primaryValues) { StringBuilder sql = new StringBuilder("SELECT * FROM "); - sql.append(wrap(tableName)).append(" WHERE "); + sql.append(wrap(getRealTable(tableName))).append(" WHERE "); for (int i = 0; i < primaryKeys.length; i++) { if (i > 0) { sql.append(" AND "); @@ -875,7 +876,7 @@ public class CommonsDialectImpl implements IDialect { || normalValueOfLogicDelete instanceof Boolean) { return normalValueOfLogicDelete; } - return "'" + normalValueOfLogicDelete.toString() + "'"; + return "'" + normalValueOfLogicDelete + "'"; } @@ -885,7 +886,7 @@ public class CommonsDialectImpl implements IDialect { || deletedValueOfLogicDelete instanceof Boolean) { return deletedValueOfLogicDelete; } - return "'" + deletedValueOfLogicDelete.toString() + "'"; + return "'" + deletedValueOfLogicDelete + "'"; } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryColumn.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryColumn.java index eac99e3c..708157e4 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryColumn.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryColumn.java @@ -18,10 +18,7 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.dialect.IDialect; import com.mybatisflex.core.table.TableDef; -import com.mybatisflex.core.util.LambdaGetter; -import com.mybatisflex.core.util.LambdaUtil; -import com.mybatisflex.core.util.SqlUtil; -import com.mybatisflex.core.util.StringUtil; +import com.mybatisflex.core.util.*; import java.io.Serializable; import java.util.Collection; @@ -45,9 +42,9 @@ public class QueryColumn implements Serializable { this.name = name; } - public QueryColumn(String tableName, String name) { + public QueryColumn(String schema, String tableName, String name) { SqlUtil.keepColumnSafely(name); - this.table = new QueryTable(tableName); + this.table = new QueryTable(schema, tableName); this.name = name; } @@ -358,25 +355,56 @@ public class QueryColumn implements Serializable { } - protected String wrap(IDialect dialect, String table, String column) { - if (StringUtil.isNotBlank(table)) { - return dialect.wrap(table) + "." + dialect.wrap(column); - } else { - return dialect.wrap(column); - } - } - String toConditionSql(List queryTables, IDialect dialect) { - String tableName = WrapperUtil.getColumnTableName(queryTables, table); - return wrap(dialect, tableName, name); + QueryTable selectTable = getSelectTable(queryTables, table); + if (selectTable == null) { + return dialect.wrap(name); + } else { + if (StringUtil.isNotBlank(selectTable.alias)) { + return dialect.wrap(selectTable.alias) + "." + dialect.wrap(name); + } else if (StringUtil.isNotBlank(selectTable.getSchema()) && StringUtil.isNotBlank(selectTable.getName())) { + return dialect.wrap(dialect.getRealSchema(selectTable.schema)) + "." + dialect.wrap(dialect.getRealTable(selectTable.getName())) + "." + dialect.wrap(name); + } else if (StringUtil.isNotBlank(selectTable.getName())) { + return dialect.wrap(dialect.getRealTable(selectTable.getName())) + "." + dialect.wrap(name); + } else { + return dialect.wrap(name); + } + } } String toSelectSql(List queryTables, IDialect dialect) { - String tableName = WrapperUtil.getColumnTableName(queryTables, table); - return wrap(dialect, tableName, name) + WrapperUtil.buildAsAlias(alias, dialect); + return toConditionSql(queryTables, dialect) + WrapperUtil.buildAsAlias(alias, dialect); } + + QueryTable getSelectTable(List queryTables, QueryTable columnTable) { + if (queryTables == null || queryTables.isEmpty()) { + return null; + } + + if (queryTables.size() == 1 && queryTables.get(0).isSameTable(columnTable)) { + //ignore table + return null; + } + + if (CollectionUtil.isEmpty(queryTables)) { + return columnTable; + } + + if (columnTable == null && queryTables.size() == 1) { + return queryTables.get(0); + } + + for (QueryTable table : queryTables) { + if (table.isSameTable(columnTable)) { + return table; + } + } + return columnTable; + } + + @Override public String toString() { return "QueryColumn{" + diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java index b69bb0f2..654ae009 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryCondition.java @@ -62,9 +62,9 @@ public class QueryCondition implements Serializable { } - public static QueryCondition create(String table, String column, String logic, Object value) { + public static QueryCondition create(String schema, String table, String column, String logic, Object value) { QueryCondition condition = new QueryCondition(); - condition.setColumn(new QueryColumn(table, column)); + condition.setColumn(new QueryColumn(schema, table, column)); condition.setLogic(logic); condition.setValue(value); return condition; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryTable.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryTable.java index e0d37121..c59e2019 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryTable.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryTable.java @@ -43,11 +43,25 @@ public class QueryTable implements Serializable { this.name = name; } - public QueryTable(String table, String alias) { + public QueryTable(String schema, String name) { + this.schema = schema; + this.name = name; + } + + public QueryTable(String schema, String table, String alias) { + this.schema = schema; this.name = table; this.alias = alias; } + public String getSchema() { + return schema; + } + + public void setSchema(String schema) { + this.schema = schema; + } + public String getName() { return name; } @@ -82,9 +96,9 @@ public class QueryTable implements Serializable { public String toSql(IDialect dialect) { String sql; if (StringUtil.isNotBlank(schema)) { - sql = dialect.wrap(schema) + "." + dialect.wrap(name) + WrapperUtil.buildAsAlias(alias, dialect); + sql = dialect.wrap(dialect.getRealSchema(schema)) + "." + dialect.wrap(dialect.getRealTable(name)) + WrapperUtil.buildAsAlias(alias, dialect); } else { - sql = dialect.wrap(name) + WrapperUtil.buildAsAlias(alias, dialect); + sql = dialect.wrap(dialect.getRealTable(name)) + WrapperUtil.buildAsAlias(alias, dialect); } return sql; } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java index cd089694..47cc19ec 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/WrapperUtil.java @@ -18,7 +18,6 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.dialect.IDialect; import com.mybatisflex.core.util.ClassUtil; -import com.mybatisflex.core.util.CollectionUtil; import com.mybatisflex.core.util.EnumWrapper; import com.mybatisflex.core.util.StringUtil; @@ -132,39 +131,7 @@ class WrapperUtil { } - public static String getColumnTableName(List queryTables, QueryTable queryTable) { - if (queryTables == null) { - return ""; - } - if (queryTables.size() == 1 && queryTables.get(0).isSameTable(queryTable)) { - return ""; - } - - QueryTable realTable = getRealTable(queryTables, queryTable); - if (realTable == null) { - return ""; - } - - return StringUtil.isNotBlank(realTable.alias) ? realTable.alias : realTable.name; - } - - public static QueryTable getRealTable(List queryTables, QueryTable queryTable) { - if (CollectionUtil.isEmpty(queryTables)) { - return queryTable; - } - - if (queryTable == null && queryTables.size() == 1) { - return queryTables.get(0); - } - - for (QueryTable table : queryTables) { - if (table.isSameTable(queryTable)) { - return table; - } - } - return queryTable; - } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicSchemaProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicSchemaProcessor.java new file mode 100644 index 00000000..80dc13ce --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicSchemaProcessor.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.mybatisflex.core.table; + +public interface DynamicSchemaProcessor { + String process(String schema); +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicTableProcessor.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicTableProcessor.java new file mode 100644 index 00000000..e33b29e8 --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/DynamicTableProcessor.java @@ -0,0 +1,20 @@ +/** + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.mybatisflex.core.table; + +public interface DynamicTableProcessor { + String process(String tableName); +} diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java index e70f79d2..a8803d2e 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableDef.java @@ -42,7 +42,7 @@ public class TableDef implements Serializable { } public QueryTable as(String alias) { - return new QueryTable(tableName, alias); + return new QueryTable(schema, tableName, alias); } 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 a90b46e3..83022002 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 @@ -577,12 +577,12 @@ public class TableInfo { if (versionValue == null) { throw FlexExceptions.wrap("The version value of entity[%s] must not be null.", entity); } - queryWrapper.and(QueryCondition.create(tableName, versionColumn, QueryCondition.LOGIC_EQUALS, versionValue)); + queryWrapper.and(QueryCondition.create(schema, tableName, versionColumn, QueryCondition.LOGIC_EQUALS, versionValue)); } //逻辑删除 if (StringUtil.isNotBlank(logicDeleteColumn)) { - queryWrapper.and(QueryCondition.create(tableName, logicDeleteColumn, QueryCondition.LOGIC_EQUALS + queryWrapper.and(QueryCondition.create(schema, tableName, logicDeleteColumn, QueryCondition.LOGIC_EQUALS , FlexGlobalConfig.getDefaultConfig().getNormalValueOfLogicDelete())); } @@ -590,9 +590,9 @@ public class TableInfo { Object[] tenantIdArgs = buildTenantIdArgs(); if (ArrayUtil.isNotEmpty(tenantIdArgs)) { if (tenantIdArgs.length == 1) { - queryWrapper.and(QueryCondition.create(tableName, tenantIdColumn, QueryCondition.LOGIC_EQUALS, tenantIdArgs[0])); + queryWrapper.and(QueryCondition.create(schema, tableName, tenantIdColumn, QueryCondition.LOGIC_EQUALS, tenantIdArgs[0])); } else { - queryWrapper.and(QueryCondition.create(tableName, tenantIdColumn, QueryCondition.LOGIC_IN, tenantIdArgs)); + queryWrapper.and(QueryCondition.create(schema, tableName, tenantIdColumn, QueryCondition.LOGIC_IN, tenantIdArgs)); } } @@ -647,7 +647,7 @@ public class TableInfo { public List getDefaultQueryColumn() { return Arrays.stream(defaultColumns) - .map(name -> new QueryColumn(getTableName(), name)) + .map(name -> new QueryColumn(schema, getTableName(), name)) .collect(Collectors.toList()); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableManager.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableManager.java new file mode 100644 index 00000000..ef97600c --- /dev/null +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/table/TableManager.java @@ -0,0 +1,110 @@ +/** + * Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com). + *

+ * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.mybatisflex.core.table; + +import com.mybatisflex.core.util.StringUtil; + +import java.util.HashMap; +import java.util.Map; + +public class TableManager { + + private static DynamicSchemaProcessor dynamicSchemaProcessor; + private static DynamicTableProcessor dynamicTableProcessor; + + private static final ThreadLocal> tableNameMappingTL = ThreadLocal.withInitial(HashMap::new); + private static final ThreadLocal> schemaMappingTL = ThreadLocal.withInitial(HashMap::new); + + + public static DynamicSchemaProcessor getDynamicSchemaProcessor() { + return dynamicSchemaProcessor; + } + + public static void setDynamicSchemaProcessor(DynamicSchemaProcessor dynamicSchemaProcessor) { + TableManager.dynamicSchemaProcessor = dynamicSchemaProcessor; + } + + public static DynamicTableProcessor getDynamicTableProcessor() { + return dynamicTableProcessor; + } + + public static void setDynamicTableProcessor(DynamicTableProcessor dynamicTableProcessor) { + TableManager.dynamicTableProcessor = dynamicTableProcessor; + } + + + public static void setHintTableMapping(String tableName, String mappingTable) { + tableNameMappingTL.get().put(tableName, mappingTable); + } + + public static String getHintTableMapping(String tableName) { + return tableNameMappingTL.get().get(tableName); + } + + public static void setHintSchemaMapping(String schema, String mappingSchema) { + schemaMappingTL.get().put(schema, mappingSchema); + } + + public static String getHintSchemaMapping(String schema) { + return schemaMappingTL.get().get(schema); + } + + + public static String getRealTable(String tableName) { + if (dynamicTableProcessor == null) { + return tableName; + } + + Map mapping = tableNameMappingTL.get(); + + String dynamicTableName = mapping.get(tableName); + if (StringUtil.isNotBlank(dynamicTableName)) { + return dynamicTableName; + } + + dynamicTableName = dynamicTableProcessor.process(tableName); + mapping.put(tableName, dynamicTableName); + return dynamicTableName; + } + + + public static String getRealSchema(String schema) { + if (dynamicSchemaProcessor == null) { + return schema; + } + + Map mapping = schemaMappingTL.get(); + String dynamiSchema = mapping.get(schema); + if (StringUtil.isNotBlank(dynamiSchema)) { + return dynamiSchema; + } + + dynamiSchema = dynamicSchemaProcessor.process(schema); + mapping.put(schema, dynamiSchema); + return dynamiSchema; + } + + +// public static void clear() { +// if (dynamicTableProcessor != null) { +// tableNameMappingTL.remove(); +// } +// if (dynamicSchemaProcessor != null) { +// schemaMappingTL.remove(); +// } +// } + +} diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account01.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account01.java index 7242448f..d33ffc95 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account01.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/Account01.java @@ -6,7 +6,7 @@ import com.mybatisflex.annotation.Table; import java.util.Date; -@Table(value = "tb_account",schema = "flex") +@Table(value = "tb_a01",schema = "flex") public class Account01 { @Id diff --git a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java index 02ea99d2..398295a1 100644 --- a/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java +++ b/mybatis-flex-core/src/test/java/com/mybatisflex/coretest/AccountSqlTester.java @@ -1,13 +1,14 @@ package com.mybatisflex.coretest; -import com.mybatisflex.core.dialect.impl.CommonsDialectImpl; import com.mybatisflex.core.dialect.IDialect; import com.mybatisflex.core.dialect.KeywordWrap; import com.mybatisflex.core.dialect.LimitOffsetProcessor; +import com.mybatisflex.core.dialect.impl.CommonsDialectImpl; import com.mybatisflex.core.query.CPI; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.table.TableInfo; import com.mybatisflex.core.table.TableInfoFactory; +import com.mybatisflex.core.table.TableManager; import org.junit.Test; import java.util.Arrays; @@ -42,6 +43,36 @@ public class AccountSqlTester { System.out.println(sql); } + @Test + public void testSelectWithSchemaSql01() { + QueryWrapper query = new QueryWrapper() + .select() + .from(ACCOUNT01).leftJoin(ACCOUNT).on(ACCOUNT01.ID.eq(ACCOUNT.ID)) + .where(ACCOUNT01.ID.ge(100)) + .and(ACCOUNT.SEX.eq(1)); + + TableManager.setDynamicTableProcessor(original -> original+"_01"); + TableManager.setDynamicTableProcessor(original -> original+"_01"); + + System.out.println(query.toDebugSQL()); + } + + + @Test + public void testSelectWithSchemaSql02() { + QueryWrapper query = new QueryWrapper() + .select() + .from(ACCOUNT01).as("a1").leftJoin(ACCOUNT).on(ACCOUNT01.ID.eq(ACCOUNT.ID)) + .where(ACCOUNT01.ID.ge(100)) + .and(ACCOUNT.SEX.eq(1)); + + TableManager.setDynamicTableProcessor(original -> original+"_01"); + TableManager.setDynamicTableProcessor(original -> original+"_01"); + + System.out.println(query.toDebugSQL()); + } + + @Test public void testSelectColumnsSql() { QueryWrapper query = new QueryWrapper() diff --git a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java index 5bebbbbf..aae6fe96 100644 --- a/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java +++ b/mybatis-flex-test/mybatis-flex-native-test/src/main/java/com/mybatisflex/test/EntityTestStarter.java @@ -21,15 +21,11 @@ import com.mybatisflex.core.audit.ConsoleMessageCollector; import com.mybatisflex.core.audit.MessageCollector; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.query.QueryWrapper; -import com.mybatisflex.core.row.Db; -import com.mybatisflex.core.row.RowUtil; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; import javax.sql.DataSource; -import java.util.List; -import static com.mybatisflex.core.query.QueryMethods.select; import static com.mybatisflex.test.table.AccountTableDef.ACCOUNT; import static com.mybatisflex.test.table.ArticleTableDef.ARTICLE; @@ -138,7 +134,7 @@ public class EntityTestStarter { .leftJoin(ACCOUNT).on(ARTICLE.ACCOUNT_ID.eq(ACCOUNT.ID)) .where(ARTICLE.ID.ge(0).or(ACCOUNT.ID.ge(0))); - RowUtil.printPretty(Db.selectListByQuery(asWrapper)); +// RowUtil.printPretty(Db.selectListByQuery(asWrapper)); // // List articleDTOS = accountMapper.selectListByQueryAs(asWrapper, ArticleDTO.class); // System.out.println(articleDTOS); @@ -195,15 +191,15 @@ public class EntityTestStarter { // .or(SYS_CONFIG.TYPE.like(word).when(StrChecker.isNotBlank(word))) // ); - List accounts = accountMapper.selectListByQuery( - select().where(ACCOUNT.AGE.ge(18).when(false)) - .and(ACCOUNT.USER_NAME.like("aaaa").when(false) - .or(ACCOUNT.USER_NAME.like("aaaa").when(false)) - .or(ACCOUNT.USER_NAME.like("aaaa").when(false)) - .or(ACCOUNT.USER_NAME.like("aaaa").when(false)) - ) - ); - System.out.println(accounts); +// List accounts = accountMapper.selectListByQuery( +// select().where(ACCOUNT.AGE.ge(18).when(false)) +// .and(ACCOUNT.USER_NAME.like("aaaa").when(false) +// .or(ACCOUNT.USER_NAME.like("aaaa").when(false)) +// .or(ACCOUNT.USER_NAME.like("aaaa").when(false)) +// .or(ACCOUNT.USER_NAME.like("aaaa").when(false)) +// ) +// ); +// System.out.println(accounts); // Page paginate = accountMapper.paginate(1, 10, QueryWrapper.create());