diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/CommonsDialectImpl.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/CommonsDialectImpl.java index 40f324e7..31a07fff 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/CommonsDialectImpl.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/dialect/CommonsDialectImpl.java @@ -195,11 +195,17 @@ public class CommonsDialectImpl implements IDialect { } @Override - public String forUpdateByQuery(String tableName, Row row, QueryWrapper queryWrapper) { + public String forUpdateByQuery(QueryWrapper queryWrapper, Row row) { StringBuilder sql = new StringBuilder(); Set modifyAttrs = row.obtainModifyAttrs(); + List queryTables = CPI.getQueryTables(queryWrapper); + if (queryTables == null || queryTables.size() != 1) { + throw FlexExceptions.wrap("update sql must need 1 table."); + } + + String tableName = queryTables.get(0).getName(); sql.append("UPDATE ").append(wrap(tableName)).append(" SET "); int index = 0; for (String modifyAttr : modifyAttrs) { 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 b37c0816..67a191a0 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 @@ -37,7 +37,7 @@ public interface IDialect { String forUpdateById(String tableName, Row row); - String forUpdateByQuery(String tableName, Row data, QueryWrapper queryWrapper); + String forUpdateByQuery(QueryWrapper queryWrapper, Row data); String forUpdateBatchById(String tableName, List rows); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java index b9312381..a78c59bc 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/provider/RowSqlProvider.java @@ -144,7 +144,7 @@ public class RowSqlProvider { public static String deleteByQuery(Map params) { String tableName = ProviderUtil.getTableName(params); QueryWrapper queryWrapper = ProviderUtil.getQueryWrapper(params); - queryWrapper.from(tableName); + CPI.setFromIfNecessary(queryWrapper,tableName); Object[] valueArray = CPI.getValueArray(queryWrapper); ProviderUtil.setSqlArgs(params, valueArray); @@ -177,15 +177,16 @@ public class RowSqlProvider { public static String updateByQuery(Map params) { String tableName = ProviderUtil.getTableName(params); Row data = ProviderUtil.getRow(params); - QueryWrapper queryWrapper = ProviderUtil.getQueryWrapper(params); + QueryWrapper queryWrapper = ProviderUtil.getQueryWrapper(params); + CPI.setFromIfNecessary(queryWrapper, tableName); Object[] modifyValues = data.obtainModifyValues(); Object[] valueArray = CPI.getValueArray(queryWrapper); ProviderUtil.setSqlArgs(params, ArrayUtil.concat(modifyValues, valueArray)); - return DialectFactory.getDialect().forUpdateByQuery(tableName, data, queryWrapper); + return DialectFactory.getDialect().forUpdateByQuery(queryWrapper, data); } @@ -241,7 +242,7 @@ public class RowSqlProvider { public static String selectListByQuery(Map params) { String tableName = ProviderUtil.getTableName(params); QueryWrapper queryWrapper = ProviderUtil.getQueryWrapper(params); - queryWrapper.from(tableName); + CPI.setFromIfNecessary(queryWrapper, tableName); Object[] valueArray = CPI.getValueArray(queryWrapper); ProviderUtil.setSqlArgs(params, valueArray); @@ -259,8 +260,9 @@ public class RowSqlProvider { */ public static String selectCountByQuery(Map params) { String tableName = ProviderUtil.getTableName(params); + QueryWrapper queryWrapper = ProviderUtil.getQueryWrapper(params); - queryWrapper.from(tableName); + CPI.setFromIfNecessary(queryWrapper, tableName); Object[] valueArray = CPI.getValueArray(queryWrapper); ProviderUtil.setSqlArgs(params, valueArray); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java index 0c1a27a4..7f4ee598 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/CPI.java @@ -17,6 +17,7 @@ package com.mybatisflex.core.query; import com.mybatisflex.core.dialect.IDialect; import com.mybatisflex.core.util.CollectionUtil; +import com.mybatisflex.core.util.StringUtil; import java.util.List; @@ -71,7 +72,7 @@ public class CPI { return queryWrapper.getJoinTables(); } - public static void setJoinTables(QueryWrapper queryWrapper,List joinTables) { + public static void setJoinTables(QueryWrapper queryWrapper, List joinTables) { queryWrapper.setJoinTables(joinTables); } @@ -121,16 +122,17 @@ public class CPI { } - public static String toConditionSql(QueryColumn queryColumn,List queryTables, IDialect dialect) { - return queryColumn.toConditionSql(queryTables,dialect); + public static String toConditionSql(QueryColumn queryColumn, List queryTables, IDialect dialect) { + return queryColumn.toConditionSql(queryTables, dialect); } - public static String toSelectSql(QueryColumn queryColumn,List queryTables, IDialect dialect) { - return queryColumn.toSelectSql(queryTables,dialect); + public static String toSelectSql(QueryColumn queryColumn, List queryTables, IDialect dialect) { + return queryColumn.toSelectSql(queryTables, dialect); } - public static void setFromIfNecessary(QueryWrapper queryWrapper,String tableName){ - if (CollectionUtil.isEmpty(queryWrapper.getQueryTables())){ + public static void setFromIfNecessary(QueryWrapper queryWrapper, String tableName) { + if (StringUtil.isNotBlank(tableName) + && CollectionUtil.isEmpty(queryWrapper.getQueryTables())) { queryWrapper.from(tableName); } } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java index 3c4ad15c..909bd8c1 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryWrapper.java @@ -19,6 +19,7 @@ import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.table.TableDef; import com.mybatisflex.core.util.ArrayUtil; import com.mybatisflex.core.util.CollectionUtil; +import com.mybatisflex.core.util.StringUtil; import java.util.ArrayList; import java.util.Arrays; @@ -51,6 +52,9 @@ public class QueryWrapper extends BaseQueryWrapper { public QueryWrapper from(String... tables) { for (String table : tables) { + if (StringUtil.isBlank(table)) { + throw new IllegalArgumentException("table must not be null or blank."); + } from(new QueryTable(table)); } return this; diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java index 9c593070..8e5f5998 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/Db.java @@ -16,8 +16,11 @@ package com.mybatisflex.core.row; import com.mybatisflex.core.FlexGlobalConfig; +import com.mybatisflex.core.exception.FlexExceptions; import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.query.CPI; import com.mybatisflex.core.query.QueryCondition; +import com.mybatisflex.core.query.QueryTable; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.transaction.TransactionContext; import com.mybatisflex.core.transaction.TransactionalManager; @@ -157,7 +160,7 @@ public class Db { * @param whereColumns where 条件 */ public static int deleteByMap(String tableName, Map whereColumns) { - return invoker().deleteByMap(tableName, whereColumns); + return invoker().deleteByQuery(tableName, new QueryWrapper().where(whereColumns)); } @@ -168,7 +171,7 @@ public class Db { * @param condition 条件内容 */ public static int deleteByCondition(String tableName, QueryCondition condition) { - return invoker().deleteByCondition(tableName, condition); + return invoker().deleteByQuery(tableName, new QueryWrapper().where(condition)); } /** @@ -211,7 +214,7 @@ public class Db { * @param whereColumns where 条件 */ public static int updateByMap(String tableName, Row data, Map whereColumns) { - return invoker().updateByMap(tableName, data, whereColumns); + return invoker().updateByQuery(tableName, data, new QueryWrapper().where(whereColumns)); } /** @@ -222,7 +225,7 @@ public class Db { * @param condition 条件 */ public static int updateByCondition(String tableName, Row data, QueryCondition condition) { - return invoker().updateByCondition(tableName, data, condition); + return invoker().updateByQuery(tableName, data, new QueryWrapper().where(condition)); } @@ -290,7 +293,7 @@ public class Db { * @param whereColumns where条件 */ public static Row selectOneByMap(String tableName, Map whereColumns) { - return invoker().selectOneByMap(tableName, whereColumns); + return invoker().selectOneByQuery(tableName, new QueryWrapper().where(whereColumns)); } /** @@ -300,7 +303,7 @@ public class Db { * @param condition 条件 */ public static Row selectOneByCondition(String tableName, QueryCondition condition) { - return invoker().selectOneByCondition(tableName, condition); + return invoker().selectOneByQuery(tableName, new QueryWrapper().where(condition)); } @@ -315,6 +318,20 @@ public class Db { } + /** + * 直接根据 queryWrapper 查询 1 条数据 + * + * @param queryWrapper 必须带有 from 的 queryWrapper + */ + public static Row selectOneByQuery(QueryWrapper queryWrapper) { + List queryTables = CPI.getQueryTables(queryWrapper); + if (queryTables == null || queryTables.isEmpty()) { + throw FlexExceptions.wrap("table must not be null or empty in Db.selectOneByQuery"); + } + return invoker().selectOneByQuery(null, queryWrapper); + } + + /** * 通过 sql 来查询多条数据 * @@ -333,7 +350,7 @@ public class Db { * @param whereColumns where 条件 */ public static List selectListByMap(String tableName, Map whereColumns) { - return invoker().selectListByMap(tableName, whereColumns); + return invoker().selectListByQuery(tableName, new QueryWrapper().where(whereColumns)); } /** @@ -344,7 +361,7 @@ public class Db { * @param count 数据量 */ public static List selectListByMap(String tableName, Map whereColumns, int count) { - return invoker().selectListByMap(tableName, whereColumns, count); + return invoker().selectListByQuery(tableName, new QueryWrapper().where(whereColumns).limit(count)); } @@ -355,7 +372,7 @@ public class Db { * @param condition where 条件 */ public static List selectListByCondition(String tableName, QueryCondition condition) { - return invoker().selectListByCondition(tableName, condition); + return invoker().selectListByQuery(tableName, new QueryWrapper().where(condition)); } /** @@ -366,7 +383,7 @@ public class Db { * @param count 数据量 */ public static List selectListByCondition(String tableName, QueryCondition condition, int count) { - return invoker().selectListByCondition(tableName, condition, count); + return invoker().selectListByQuery(tableName, new QueryWrapper().where(condition).limit(count)); } @@ -380,6 +397,20 @@ public class Db { return invoker().selectListByQuery(tableName, queryWrapper); } + + /** + * 通过 query 来查询数据列表 + * + * @param queryWrapper 必须带有 from 的 queryWrapper + */ + public static List selectListByQuery(QueryWrapper queryWrapper) { + List queryTables = CPI.getQueryTables(queryWrapper); + if (queryTables == null || queryTables.isEmpty()) { + throw FlexExceptions.wrap("table must not be null or empty in Db.selectListByQuery"); + } + return invoker().selectListByQuery(null, queryWrapper); + } + /** * 查询某张表的所有数据 * @@ -430,7 +461,7 @@ public class Db { * @param condition 条件 */ public static long selectCountByCondition(String tableName, QueryCondition condition) { - return invoker().selectCountByCondition(tableName, condition); + return invoker().selectCountByQuery(tableName, new QueryWrapper().where(condition)); } @@ -445,6 +476,48 @@ public class Db { } + /** + * 直接根据 query 来查询数据量 + * + * @param queryWrapper 必须带有表名的 queryWrapper + * @return 数据量 + */ + public static long selectCountByQuery(QueryWrapper queryWrapper) { + List queryTables = CPI.getQueryTables(queryWrapper); + if (queryTables == null || queryTables.isEmpty()) { + throw FlexExceptions.wrap("table must not be null or empty in Db.selectCountByQuery"); + } + return invoker().selectCountByQuery(null, queryWrapper); + } + + + /** + * 分页查询 + * + * @param tableName 表名 + * @param pageNumber 当前的页码 + * @param pageSize 每页的数据量 + * @param condition 条件 + */ + public static Page paginate(String tableName, int pageNumber, int pageSize, QueryCondition condition) { + return invoker().paginate(tableName, new Page<>(pageNumber, pageSize), QueryWrapper.create().where(condition)); + } + + + /** + * 分页查询 + * + * @param tableName 表名 + * @param pageNumber 当前的页码 + * @param pageSize 每页的数据量 + * @param totalRow 数据总量 + * @param condition 条件 + */ + public static Page paginate(String tableName, int pageNumber, int pageSize, int totalRow, QueryCondition condition) { + return invoker().paginate(tableName, new Page<>(pageNumber, pageSize, totalRow), QueryWrapper.create().where(condition)); + } + + /** * 分页查询 * @@ -454,7 +527,21 @@ public class Db { * @param queryWrapper 条件 */ public static Page paginate(String tableName, int pageNumber, int pageSize, QueryWrapper queryWrapper) { - return invoker().paginate(tableName, pageNumber, pageSize, queryWrapper); + return invoker().paginate(tableName, new Page<>(pageNumber, pageSize), queryWrapper); + } + + + /** + * 分页查询 + * + * @param tableName 表名 + * @param pageNumber 当前的页码 + * @param pageSize 每页的数据量 + * @param totalRow 数据总量 + * @param queryWrapper 条件 + */ + public static Page paginate(String tableName, int pageNumber, int pageSize, int totalRow, QueryWrapper queryWrapper) { + return invoker().paginate(tableName, new Page<>(pageNumber, pageSize, totalRow), queryWrapper); } @@ -470,6 +557,11 @@ public class Db { } + /** + * 进行事务操作 + * + * @param supplier + */ public static boolean tx(Supplier supplier) { //上一级事务的id,支持事务嵌套 String higherXID = TransactionContext.getXID(); diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapper.java index b3471264..d1bf5a0c 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapper.java @@ -21,7 +21,6 @@ import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.provider.RowSqlProvider; import com.mybatisflex.core.query.CPI; import com.mybatisflex.core.query.QueryColumn; -import com.mybatisflex.core.query.QueryCondition; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.util.StringUtil; import org.apache.ibatis.annotations.*; @@ -122,36 +121,6 @@ public interface RowMapper { @DeleteProvider(value = RowSqlProvider.class, method = "deleteBatchByIds") int deleteBatchByIds(@Param(FlexConsts.TABLE_NAME) String tableName, @Param(FlexConsts.PRIMARY_KEY) String primaryKey, @Param(FlexConsts.PRIMARY_VALUE) Collection ids); - /** - * 根据 map 来构建条件删除数据 - *

- * 注意: - * 删除 map 不允许为 null 或者 空内容,否则可能造成数据全部删除的情况 - * 若想删除全部数据,请执行 {@link RowMapper#deleteBySql(String, Object...)} 方法 - * - * @param tableName 表名 - * @param whereConditions 条件,通过 map 的 key:value 来构建,都是 and 的关系 - * @return 执行影响的行数 - */ - default int deleteByMap(String tableName, Map whereConditions) { - if (whereConditions == null || whereConditions.isEmpty()) { - throw FlexExceptions.wrap("whereConditions can not be null or empty."); - } - return deleteByQuery(tableName, new QueryWrapper().where(whereConditions)); - } - - - /** - * 根据 condition 来删除数据 - * - * @param tableName 表名 - * @param condition 数据 - * @return 执行影响的行数 - */ - default int deleteByCondition(String tableName, QueryCondition condition) { - return deleteByQuery(tableName, new QueryWrapper().where(condition)); - } - /** * 根据 queryWrapper 构建 where 条件来删除数据 @@ -190,32 +159,6 @@ public interface RowMapper { int updateById(@Param(FlexConsts.TABLE_NAME) String tableName, @Param(FlexConsts.ROW) Row row); - /** - * 根据 map 来更新数据 - * - * @param tableName 表名 - * @param data 要更新的数据 - * @param whereConditions 条件,通过 map 的 key:value 来构建,都是 and 的关系 - * @return 执行影响的行数 - */ - default int updateByMap(String tableName, Row data, Map whereConditions) { - return updateByQuery(tableName, data, new QueryWrapper().where(whereConditions)); - } - - - /** - * 根据 condition 来更新数据 - * - * @param tableName 表名 - * @param data 要更新的数据 - * @param condition 更新条件 - * @return 执行影响的行数 - */ - default int updateByCondition(String tableName, Row data, QueryCondition condition) { - return updateByQuery(tableName, data, new QueryWrapper().where(condition)); - } - - /** * 根据 queryWrapper 来构建 where 条件更新数据 * @@ -289,27 +232,6 @@ public interface RowMapper { @SelectProvider(value = RowSqlProvider.class, method = "selectOneById") Row selectOneById(@Param(FlexConsts.TABLE_NAME) String tableName, @Param(FlexConsts.PRIMARY_KEY) String primaryKey, @Param(FlexConsts.PRIMARY_VALUE) Object id); - /** - * 根据 map 组成的条件查询 1 条数据 - * - * @param tableName - * @param whereConditions - */ - default Row selectOneByMap(String tableName, Map whereConditions) { - return selectOneByQuery(tableName, new QueryWrapper().where(whereConditions)); - } - - - /** - * 根据 condition 来查询数据 - * - * @param tableName 表名 - * @param condition 条件内容 - */ - default Row selectOneByCondition(String tableName, QueryCondition condition) { - return selectOneByQuery(tableName, new QueryWrapper().where(condition)); - } - /** * 根据 queryWrapper 来查询 1 条数据 @@ -338,54 +260,6 @@ public interface RowMapper { List selectListBySql(@Param(FlexConsts.SQL) String sql, @Param(FlexConsts.SQL_ARGS) Object... args); - /** - * 根据 map 来查询一个 Row 列表 - * - * @param tableName 表名 - * @param whereConditions 条件 - * @return row 列表 - */ - default List selectListByMap(String tableName, Map whereConditions) { - return selectListByQuery(tableName, new QueryWrapper().where(whereConditions)); - } - - /** - * 根据 map 来查询一个 Row 列表 - * - * @param tableName 表名 - * @param whereConditions 条件 - * @param count 数据量 - * @return row 列表 - */ - default List selectListByMap(String tableName, Map whereConditions, int count) { - return selectListByQuery(tableName, new QueryWrapper().where(whereConditions).limit(count)); - } - - - /** - * 根据 condition 来查询 Row 列表 - * - * @param tableName 表名 - * @param condition 条件 - * @return row 列表 - */ - default List selectListByCondition(String tableName, QueryCondition condition) { - return selectListByQuery(tableName, new QueryWrapper().where(condition)); - } - - /** - * 根据 condition 来查询 Row 列表 - * - * @param tableName 表名 - * @param condition 条件 - * @param count 数据量 - * @return row 列表 - */ - default List selectListByCondition(String tableName, QueryCondition condition, int count) { - return selectListByQuery(tableName, new QueryWrapper().where(condition).limit(count)); - } - - /** * 根据 queryWrapper 来查询一个 row 列表 * @@ -405,7 +279,7 @@ public interface RowMapper { * @return row 列表 */ default List selectAll(@Param(FlexConsts.TABLE_NAME) String tableName) { - return selectListByMap(tableName, null); + return selectListByQuery(tableName, QueryWrapper.create()); } /** @@ -449,16 +323,6 @@ public interface RowMapper { } } - /** - * 根据 condition 条件来查询数据量 - * - * @param tableName - * @param condition - * @return - */ - default long selectCountByCondition(String tableName, QueryCondition condition) { - return selectCountByQuery(tableName, new QueryWrapper().where(condition)); - } /** * 根据 queryWrapper 来查询数量 @@ -472,68 +336,6 @@ public interface RowMapper { long selectCountByQuery(@Param(FlexConsts.TABLE_NAME) String tableName, @Param(FlexConsts.QUERY) QueryWrapper queryWrapper); - /** - * 分页查询某张表的数据 - * - * @param tableName 表名 - * @param pageNumber 当前页码 - * @param pageSize 每页的数据量 - * @param queryWrapper 条件封装 - * @return 一页数据 - */ - default Page paginate(String tableName, int pageNumber, int pageSize, QueryWrapper queryWrapper) { - Page page = new Page<>(pageNumber, pageSize); - return paginate(tableName, page, queryWrapper); - } - - - /** - * 分页查询某张表的数据 - * - * @param tableName 表名 - * @param pageNumber 当前页码 - * @param pageSize 每页的数据量 - * @param condition 条件 - * @return - */ - default Page paginate(String tableName, int pageNumber, int pageSize, QueryCondition condition) { - Page page = new Page<>(pageNumber, pageSize); - return paginate(tableName, page, new QueryWrapper().where(condition)); - } - - - /** - * 分页查询某张表的数据 - * - * @param tableName 表名 - * @param pageNumber 当前页码 - * @param pageSize 每页的数据量 - * @param totalRow 数据总量 - * @param queryWrapper 条件封装 - * @return 一页数据 - */ - default Page paginate(String tableName, int pageNumber, int pageSize, int totalRow, QueryWrapper queryWrapper) { - Page page = new Page<>(pageNumber, pageSize, totalRow); - return paginate(tableName, page, queryWrapper); - } - - - /** - * 分页查询某张表的数据 - * - * @param tableName 表名 - * @param pageNumber 当前页码 - * @param pageSize 每页的数据量 - * @param totalRow 数据总量 - * @param condition 条件 - * @return - */ - default Page paginate(String tableName, int pageNumber, int pageSize, int totalRow, QueryCondition condition) { - Page page = new Page<>(pageNumber, pageSize, totalRow); - return paginate(tableName, page, new QueryWrapper().where(condition)); - } - - /** * 分页查询数据 * @@ -544,7 +346,6 @@ public interface RowMapper { */ default Page paginate(String tableName, Page page, QueryWrapper queryWrapper) { - List groupByColumns = CPI.getGroupByColumns(queryWrapper); // 只有 totalRow 小于 0 的时候才会去查询总量 diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapperInvoker.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapperInvoker.java index 0168a141..bc8471fe 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapperInvoker.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/row/RowMapperInvoker.java @@ -16,7 +16,6 @@ package com.mybatisflex.core.row; import com.mybatisflex.core.paginate.Page; -import com.mybatisflex.core.query.QueryCondition; import com.mybatisflex.core.query.QueryWrapper; import org.apache.ibatis.executor.BatchResult; import org.apache.ibatis.session.ExecutorType; @@ -25,7 +24,6 @@ import org.apache.ibatis.session.SqlSessionFactory; import java.util.Collection; import java.util.List; -import java.util.Map; import java.util.function.Function; public class RowMapperInvoker { @@ -112,13 +110,6 @@ public class RowMapperInvoker { return execute(mapper -> mapper.deleteBatchByIds(tableName, primaryKey, ids)); } - public int deleteByMap(String tableName, Map whereColumns) { - return execute(mapper -> mapper.deleteByMap(tableName, whereColumns)); - } - - public int deleteByCondition(String tableName, QueryCondition condition) { - return execute(mapper -> mapper.deleteByCondition(tableName, condition)); - } public int deleteByQuery(String tableName, QueryWrapper queryWrapper) { return execute(mapper -> mapper.deleteByQuery(tableName, queryWrapper)); @@ -132,14 +123,6 @@ public class RowMapperInvoker { return execute(mapper -> mapper.updateById(tableName, row)); } - public int updateByMap(String tableName, Row data, Map whereColumns) { - return execute(mapper -> mapper.updateByMap(tableName, data, whereColumns)); - } - - public int updateByCondition(String tableName, Row data, QueryCondition condition) { - return execute(mapper -> mapper.updateByCondition(tableName, data, condition)); - } - public int updateByQuery(String tableName, Row data, QueryWrapper queryWrapper) { return execute(mapper -> mapper.updateByQuery(tableName, data, queryWrapper)); } @@ -160,14 +143,6 @@ public class RowMapperInvoker { return execute(mapper -> mapper.selectOneById(tableName, primaryKey, id)); } - public Row selectOneByMap(String tableName, Map whereColumns) { - return execute(mapper -> mapper.selectOneByMap(tableName, whereColumns)); - } - - public Row selectOneByCondition(String tableName, QueryCondition condition) { - return execute(mapper -> mapper.selectOneByCondition(tableName, condition)); - } - public Row selectOneByQuery(String tableName, QueryWrapper queryWrapper) { return execute(mapper -> mapper.selectOneByQuery(tableName, queryWrapper)); } @@ -176,23 +151,6 @@ public class RowMapperInvoker { return execute(mapper -> mapper.selectListBySql(sql, args)); } - public List selectListByMap(String tableName, Map whereColumns) { - return execute(mapper -> mapper.selectListByMap(tableName, whereColumns)); - } - - public List selectListByMap(String tableName, Map whereColumns, int count) { - return execute(mapper -> mapper.selectListByMap(tableName, whereColumns, count)); - } - - public List selectListByCondition(String tableName, QueryCondition condition) { - return execute(mapper -> mapper.selectListByCondition(tableName, condition)); - } - - public List selectListByCondition(String tableName, QueryCondition condition, int count) { - return execute(mapper -> mapper.selectListByCondition(tableName, condition, count)); - } - - public List selectListByQuery(String tableName, QueryWrapper queryWrapper) { return execute(mapper -> mapper.selectListByQuery(tableName, queryWrapper)); } @@ -213,18 +171,11 @@ public class RowMapperInvoker { return execute(mapper -> mapper.selectCount(sql, args)); } - public long selectCountByCondition(String tableName, QueryCondition condition) { - return execute(mapper -> mapper.selectCountByCondition(tableName, condition)); - } public long selectCountByQuery(String tableName, QueryWrapper queryWrapper) { return execute(mapper -> mapper.selectCountByQuery(tableName, queryWrapper)); } - public Page paginate(String tableName, int pageNumber, int pageSize, QueryWrapper queryWrapper) { - return execute(mapper -> mapper.paginate(tableName, pageNumber, pageSize, queryWrapper)); - } - public Page paginate(String tableName, Page page, QueryWrapper queryWrapper) { return execute(mapper -> mapper.paginate(tableName, page, queryWrapper)); } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/CollectionUtil.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/CollectionUtil.java index 13c46311..090fe0e2 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/CollectionUtil.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/CollectionUtil.java @@ -22,18 +22,18 @@ import java.util.function.Function; public class CollectionUtil { - public static boolean isEmpty(Collection coll) { - return (coll == null || coll.isEmpty()); + public static boolean isEmpty(Collection collection) { + return collection == null || collection.isEmpty(); } - public static boolean isNotEmpty(Collection coll) { - return !isEmpty(coll); + public static boolean isNotEmpty(Collection collection) { + return !isEmpty(collection); } public static boolean isEmpty(Map map) { - return (map == null || map.isEmpty()); + return map == null || map.isEmpty(); }