mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
refactor: optimize forInsertEntityBatch
This commit is contained in:
parent
792bfde75f
commit
9fcf4e20ea
@ -20,6 +20,7 @@ import com.mybatisflex.core.row.Row;
|
||||
import com.mybatisflex.core.table.TableInfo;
|
||||
import com.mybatisflex.core.table.TableManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -75,7 +76,7 @@ public interface IDialect {
|
||||
|
||||
String forInsertEntityWithPk(TableInfo tableInfo, Object entity, boolean ignoreNulls);
|
||||
|
||||
String forInsertEntityBatch(TableInfo tableInfo, List<?> entities);
|
||||
String forInsertEntityBatch(TableInfo tableInfo, Collection<?> entities);
|
||||
|
||||
String forDeleteEntityById(TableInfo tableInfo);
|
||||
|
||||
|
||||
@ -653,7 +653,7 @@ public class CommonsDialectImpl implements IDialect {
|
||||
|
||||
|
||||
@Override
|
||||
public String forInsertEntityBatch(TableInfo tableInfo, List<?> entities) {
|
||||
public String forInsertEntityBatch(TableInfo tableInfo, Collection<?> entities) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
sql.append(INSERT_INTO).append(tableInfo.getWrapSchemaAndTableName(this, OperateType.INSERT));
|
||||
String[] insertColumns = tableInfo.obtainInsertColumns(null, false);
|
||||
|
||||
@ -26,10 +26,7 @@ import com.mybatisflex.core.util.CollectionUtil;
|
||||
import com.mybatisflex.core.util.SqlUtil;
|
||||
import com.mybatisflex.core.util.StringUtil;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringJoiner;
|
||||
import java.util.*;
|
||||
|
||||
import static com.mybatisflex.core.constant.SqlConsts.*;
|
||||
|
||||
@ -100,7 +97,7 @@ public class OracleDialect extends CommonsDialectImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String forInsertEntityBatch(TableInfo tableInfo, List<?> entities) {
|
||||
public String forInsertEntityBatch(TableInfo tableInfo, Collection<?> entities) {
|
||||
/**
|
||||
* INSERT ALL
|
||||
* INTO t (col1, col2, col3) VALUES ('val1_1', 'val1_2', 'val1_3')
|
||||
|
||||
@ -119,11 +119,11 @@ public class EntitySqlProvider {
|
||||
* @param params 方法参数
|
||||
* @param context 上下文对象
|
||||
* @return SQL 语句
|
||||
* @see com.mybatisflex.core.BaseMapper#insertBatch(List)
|
||||
* @see com.mybatisflex.core.BaseMapper#insertBatch(Collection)
|
||||
* @see com.mybatisflex.core.FlexConsts#METHOD_INSERT_BATCH
|
||||
*/
|
||||
public static String insertBatch(Map params, ProviderContext context) {
|
||||
List<Object> entities = ProviderUtil.getEntities(params);
|
||||
Collection<Object> entities = ProviderUtil.getEntities(params);
|
||||
|
||||
FlexAssert.notEmpty(entities, "entities");
|
||||
|
||||
@ -263,7 +263,7 @@ public class EntitySqlProvider {
|
||||
boolean ignoreNulls = ProviderUtil.isIgnoreNulls(params);
|
||||
|
||||
QueryWrapper queryWrapper = ProviderUtil.getQueryWrapper(params);
|
||||
appendTableConditions(context,queryWrapper,false);
|
||||
appendTableConditions(context, queryWrapper, false);
|
||||
|
||||
TableInfo tableInfo = ProviderUtil.getTableInfo(context);
|
||||
|
||||
@ -280,7 +280,7 @@ public class EntitySqlProvider {
|
||||
Object[] values = tableInfo.buildUpdateSqlArgs(entity, ignoreNulls, true);
|
||||
Object[] queryParams = CPI.getConditionValueArray(queryWrapper);
|
||||
|
||||
Object[] paramValues = ArrayUtil.concat(joinValueArray,ArrayUtil.concat(values,queryParams));
|
||||
Object[] paramValues = ArrayUtil.concat(joinValueArray, ArrayUtil.concat(values, queryParams));
|
||||
|
||||
ProviderUtil.setSqlArgs(params, paramValues);
|
||||
|
||||
@ -288,7 +288,6 @@ public class EntitySqlProvider {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* selectOneById 的 SQL 构建。
|
||||
*
|
||||
|
||||
@ -119,8 +119,8 @@ class ProviderUtil {
|
||||
return params.get(FlexConsts.VALUE);
|
||||
}
|
||||
|
||||
public static List<Object> getEntities(Map params) {
|
||||
return (List<Object>) params.get(FlexConsts.ENTITIES);
|
||||
public static Collection<Object> getEntities(Map params) {
|
||||
return (Collection<Object>) params.get(FlexConsts.ENTITIES);
|
||||
}
|
||||
|
||||
public static boolean isIgnoreNulls(Map params) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user