rename BaseMapper.insertBatchWithFirstEntityColumns to insertBatch

This commit is contained in:
开源海哥 2023-03-02 13:24:10 +08:00
parent b75699e73e
commit 05aad515d2
6 changed files with 14 additions and 10 deletions

View File

@ -46,10 +46,11 @@ public interface BaseMapper<T> {
* *
* @param entities 插入的数据列表 * @param entities 插入的数据列表
* @return 返回影响的行数 * @return 返回影响的行数
* @see com.mybatisflex.core.provider.EntitySqlProvider#insertBatchWithFirstEntityColumns(Map, ProviderContext) * @see com.mybatisflex.core.provider.EntitySqlProvider#insertBatch(Map, ProviderContext)
* @see com.mybatisflex.core.FlexConsts#METHOD_INSERT_BATCH
*/ */
@InsertProvider(type = EntitySqlProvider.class, method = "insertBatchWithFirstEntityColumns") @InsertProvider(type = EntitySqlProvider.class, method = FlexConsts.METHOD_INSERT_BATCH)
int insertBatchWithFirstEntityColumns(@Param(FlexConsts.ENTITIES) List<T> entities); int insertBatch(@Param(FlexConsts.ENTITIES) List<T> entities);
/** /**
* 根据 id 删除数据 * 根据 id 删除数据

View File

@ -36,4 +36,6 @@ public class FlexConsts {
public static final String ENTITY = "$$entity"; public static final String ENTITY = "$$entity";
public static final String ENTITIES = "$$entities"; public static final String ENTITIES = "$$entities";
public static final String IGNORE_NULLS = "$$ignoreNulls"; public static final String IGNORE_NULLS = "$$ignoreNulls";
public static final String METHOD_INSERT_BATCH = "insertBatch";
} }

View File

@ -374,7 +374,7 @@ public class CommonsDialectImpl implements IDialect {
} }
@Override @Override
public String forInsertBatchWithFirstEntityColumns(TableInfo tableInfo, List<Object> entities) { public String forInsertEntityBatch(TableInfo tableInfo, List<Object> entities) {
StringBuilder sql = new StringBuilder(); StringBuilder sql = new StringBuilder();
sql.append("INSERT INTO ").append(wrap(tableInfo.getTableName())); sql.append("INSERT INTO ").append(wrap(tableInfo.getTableName()));
String[] insertColumns = tableInfo.obtainInsertColumns(); String[] insertColumns = tableInfo.obtainInsertColumns();

View File

@ -61,7 +61,7 @@ public interface IDialect {
//////for entity ///// //////for entity /////
String forInsertEntity(TableInfo tableInfo, Object entity); String forInsertEntity(TableInfo tableInfo, Object entity);
String forInsertBatchWithFirstEntityColumns(TableInfo tableInfo, List<Object> entities); String forInsertEntityBatch(TableInfo tableInfo, List<Object> entities);
String forDeleteEntityById(TableInfo tableInfo); String forDeleteEntityById(TableInfo tableInfo);

View File

@ -101,7 +101,7 @@ public class FlexConfiguration extends Configuration {
ms = replaceRowKeyGenerator(ms); ms = replaceRowKeyGenerator(ms);
} }
//entity insert methods //entity insert methods
else if (StringUtil.endsWithAny(ms.getId(), "insert", "insertBatchWithFirstEntityColumns") else if (StringUtil.endsWithAny(ms.getId(), "insert", FlexConsts.METHOD_INSERT_BATCH)
&& ms.getKeyGenerator() == NoKeyGenerator.INSTANCE) { && ms.getKeyGenerator() == NoKeyGenerator.INSTANCE) {
ms = replaceEntityKeyGenerator(ms); ms = replaceEntityKeyGenerator(ms);
} }
@ -208,7 +208,7 @@ public class FlexConfiguration extends Configuration {
} }
//批量插入 //批量插入
if (ms.getId().endsWith("insertBatchWithFirstEntityColumns")) { if (ms.getId().endsWith(FlexConsts.METHOD_INSERT_BATCH)) {
keyGenerator = new MultiEntityKeyGenerator(keyGenerator); keyGenerator = new MultiEntityKeyGenerator(keyGenerator);
} }

View File

@ -68,9 +68,10 @@ public class EntitySqlProvider {
* @param params * @param params
* @param context * @param context
* @return sql * @return sql
* @see com.mybatisflex.core.BaseMapper#insertBatchWithFirstEntityColumns(List) * @see com.mybatisflex.core.BaseMapper#insertBatch(List)
* @see com.mybatisflex.core.FlexConsts#METHOD_INSERT_BATCH
*/ */
public static String insertBatchWithFirstEntityColumns(Map params, ProviderContext context) { public static String insertBatch(Map params, ProviderContext context) {
List<Object> entities = ProviderUtil.getEntities(params); List<Object> entities = ProviderUtil.getEntities(params);
if (CollectionUtil.isEmpty(entities)) { if (CollectionUtil.isEmpty(entities)) {
throw FlexExceptions.wrap("entities can not be null or empty."); throw FlexExceptions.wrap("entities can not be null or empty.");
@ -84,7 +85,7 @@ public class EntitySqlProvider {
ProviderUtil.setSqlArgs(params, values); ProviderUtil.setSqlArgs(params, values);
return DialectFactory.getDialect().forInsertBatchWithFirstEntityColumns(tableInfo, entities); return DialectFactory.getDialect().forInsertEntityBatch(tableInfo, entities);
} }