mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
optimize Db.java
This commit is contained in:
parent
ed6dbff6eb
commit
b7fff23e8a
@ -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<String> modifyAttrs = row.obtainModifyAttrs();
|
||||
|
||||
List<QueryTable> 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) {
|
||||
|
||||
@ -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<Row> rows);
|
||||
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -130,7 +131,8 @@ public class CPI {
|
||||
}
|
||||
|
||||
public static void setFromIfNecessary(QueryWrapper queryWrapper, String tableName) {
|
||||
if (CollectionUtil.isEmpty(queryWrapper.getQueryTables())){
|
||||
if (StringUtil.isNotBlank(tableName)
|
||||
&& CollectionUtil.isEmpty(queryWrapper.getQueryTables())) {
|
||||
queryWrapper.from(tableName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<QueryWrapper> {
|
||||
|
||||
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;
|
||||
|
||||
@ -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<String, Object> 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<String, Object> 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<QueryTable> 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<Row> selectListByMap(String tableName, Map<String, Object> 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<Row> selectListByMap(String tableName, Map<String, Object> 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<Row> 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<Row> 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<Row> selectListByQuery(QueryWrapper queryWrapper) {
|
||||
List<QueryTable> 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<QueryTable> 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<Row> 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<Row> 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<Row> 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<Row> 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<Boolean> supplier) {
|
||||
//上一级事务的id,支持事务嵌套
|
||||
String higherXID = TransactionContext.getXID();
|
||||
|
||||
@ -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 来构建条件删除数据
|
||||
* <p>
|
||||
* <b>注意:</b>
|
||||
* 删除 map 不允许为 null 或者 空内容,否则可能造成数据全部删除的情况
|
||||
* 若想删除全部数据,请执行 {@link RowMapper#deleteBySql(String, Object...)} 方法
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param whereConditions 条件,通过 map 的 key:value 来构建,都是 and 的关系
|
||||
* @return 执行影响的行数
|
||||
*/
|
||||
default int deleteByMap(String tableName, Map<String, Object> 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<String, Object> 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<Row> selectListBySql(@Param(FlexConsts.SQL) String sql, @Param(FlexConsts.SQL_ARGS) Object... args);
|
||||
|
||||
|
||||
/**
|
||||
* 根据 map 来查询一个 Row 列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param whereConditions 条件
|
||||
* @return row 列表
|
||||
*/
|
||||
default List<Row> selectListByMap(String tableName, Map<String, Object> whereConditions) {
|
||||
return selectListByQuery(tableName, new QueryWrapper().where(whereConditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 map 来查询一个 Row 列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param whereConditions 条件
|
||||
* @param count 数据量
|
||||
* @return row 列表
|
||||
*/
|
||||
default List<Row> selectListByMap(String tableName, Map<String, Object> whereConditions, int count) {
|
||||
return selectListByQuery(tableName, new QueryWrapper().where(whereConditions).limit(count));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据 condition 来查询 Row 列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 条件
|
||||
* @return row 列表
|
||||
*/
|
||||
default List<Row> selectListByCondition(String tableName, QueryCondition condition) {
|
||||
return selectListByQuery(tableName, new QueryWrapper().where(condition));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 condition 来查询 Row 列表
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param condition 条件
|
||||
* @param count 数据量
|
||||
* @return row 列表
|
||||
*/
|
||||
default List<Row> 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<Row> 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<Row> paginate(String tableName, int pageNumber, int pageSize, QueryWrapper queryWrapper) {
|
||||
Page<Row> page = new Page<>(pageNumber, pageSize);
|
||||
return paginate(tableName, page, queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询某张表的数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param pageNumber 当前页码
|
||||
* @param pageSize 每页的数据量
|
||||
* @param condition 条件
|
||||
* @return
|
||||
*/
|
||||
default Page<Row> paginate(String tableName, int pageNumber, int pageSize, QueryCondition condition) {
|
||||
Page<Row> 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<Row> paginate(String tableName, int pageNumber, int pageSize, int totalRow, QueryWrapper queryWrapper) {
|
||||
Page<Row> page = new Page<>(pageNumber, pageSize, totalRow);
|
||||
return paginate(tableName, page, queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询某张表的数据
|
||||
*
|
||||
* @param tableName 表名
|
||||
* @param pageNumber 当前页码
|
||||
* @param pageSize 每页的数据量
|
||||
* @param totalRow 数据总量
|
||||
* @param condition 条件
|
||||
* @return
|
||||
*/
|
||||
default Page<Row> paginate(String tableName, int pageNumber, int pageSize, int totalRow, QueryCondition condition) {
|
||||
Page<Row> page = new Page<>(pageNumber, pageSize, totalRow);
|
||||
return paginate(tableName, page, new QueryWrapper().where(condition));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页查询数据
|
||||
*
|
||||
@ -544,7 +346,6 @@ public interface RowMapper {
|
||||
*/
|
||||
default Page<Row> paginate(String tableName, Page<Row> page, QueryWrapper queryWrapper) {
|
||||
|
||||
|
||||
List<QueryColumn> groupByColumns = CPI.getGroupByColumns(queryWrapper);
|
||||
|
||||
// 只有 totalRow 小于 0 的时候才会去查询总量
|
||||
|
||||
@ -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<String, Object> 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<String, Object> 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<Row> selectListByMap(String tableName, Map<String, Object> whereColumns) {
|
||||
return execute(mapper -> mapper.selectListByMap(tableName, whereColumns));
|
||||
}
|
||||
|
||||
public List<Row> selectListByMap(String tableName, Map<String, Object> whereColumns, int count) {
|
||||
return execute(mapper -> mapper.selectListByMap(tableName, whereColumns, count));
|
||||
}
|
||||
|
||||
public List<Row> selectListByCondition(String tableName, QueryCondition condition) {
|
||||
return execute(mapper -> mapper.selectListByCondition(tableName, condition));
|
||||
}
|
||||
|
||||
public List<Row> selectListByCondition(String tableName, QueryCondition condition, int count) {
|
||||
return execute(mapper -> mapper.selectListByCondition(tableName, condition, count));
|
||||
}
|
||||
|
||||
|
||||
public List<Row> 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<Row> paginate(String tableName, int pageNumber, int pageSize, QueryWrapper queryWrapper) {
|
||||
return execute(mapper -> mapper.paginate(tableName, pageNumber, pageSize, queryWrapper));
|
||||
}
|
||||
|
||||
public Page<Row> paginate(String tableName, Page<Row> page, QueryWrapper queryWrapper) {
|
||||
return execute(mapper -> mapper.paginate(tableName, page, queryWrapper));
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user