Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
* 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.provider;
import com.mybatisflex.core.FlexConsts;
import com.mybatisflex.core.dialect.DialectFactory;
import com.mybatisflex.core.exception.FlexAssert;
import com.mybatisflex.core.query.CPI;
import com.mybatisflex.core.query.QueryTable;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.core.table.TableInfo;
import com.mybatisflex.core.table.TableInfoFactory;
import com.mybatisflex.core.util.ArrayUtil;
import com.mybatisflex.core.util.CollectionUtil;
import com.mybatisflex.core.util.StringUtil;
import org.apache.ibatis.builder.annotation.ProviderContext;
import java.io.Serializable;
import java.util.*;
@SuppressWarnings({"rawtypes", "DuplicatedCode"})
public class EntitySqlProvider {
/**
* 不让实例化,使用静态方法的模式,效率更高,非静态方法每次都会实例化当前类
* 参考源码: {{@link org.apache.ibatis.builder.annotation.ProviderSqlSource#getBoundSql(Object)}
*/
private EntitySqlProvider() {
}
/**
* insert 的 SQL 构建。
*
* @param params 方法参数
* @param context 上下文对象
* @return SQL 语句
* @see com.mybatisflex.core.BaseMapper#insert(Object)
*/
public static String insert(Map params, ProviderContext context) {
Object entity = ProviderUtil.getEntity(params);
FlexAssert.notNull(entity, "entity");
boolean ignoreNulls = ProviderUtil.isIgnoreNulls(params);
TableInfo tableInfo = ProviderUtil.getTableInfo(context);
//设置乐观锁版本字段的初始化数据
tableInfo.initVersionValueIfNecessary(entity);
//设置租户ID
tableInfo.initTenantIdIfNecessary(entity);
//设置逻辑删除字段的出初始化数据
tableInfo.initLogicDeleteValueIfNecessary(entity);
//执行 onInsert 监听器
tableInfo.invokeOnInsertListener(entity);
Object[] values = tableInfo.buildInsertSqlArgs(entity, ignoreNulls);
ProviderUtil.setSqlArgs(params, values);
return DialectFactory.getDialect().forInsertEntity(tableInfo, entity, ignoreNulls);
}
/**
* insertWithPk 的 SQL 构建。
*
* @param params 方法参数
* @param context 上下文对象
* @return SQL 语句
* @see com.mybatisflex.core.BaseMapper#insertWithPk(Object, boolean)
*/
public static String insertWithPk(Map params, ProviderContext context) {
Object entity = ProviderUtil.getEntity(params);
FlexAssert.notNull(entity, "entity");
boolean ignoreNulls = ProviderUtil.isIgnoreNulls(params);
TableInfo tableInfo = ProviderUtil.getTableInfo(context);
//设置乐观锁版本字段的初始化数据
tableInfo.initVersionValueIfNecessary(entity);
//设置租户ID
tableInfo.initTenantIdIfNecessary(entity);
//设置逻辑删除字段的出初始化数据
tableInfo.initLogicDeleteValueIfNecessary(entity);
//执行 onInsert 监听器
tableInfo.invokeOnInsertListener(entity);
Object[] values = tableInfo.buildInsertSqlArgsWithPk(entity, ignoreNulls);
ProviderUtil.setSqlArgs(params, values);
return DialectFactory.getDialect().forInsertEntityWithPk(tableInfo, entity, ignoreNulls);
}
/**
* insertBatch 的 SQL 构建。
*
* @param params 方法参数
* @param context 上下文对象
* @return SQL 语句
* @see com.mybatisflex.core.BaseMapper#insertBatch(Collection)
* @see com.mybatisflex.core.FlexConsts#METHOD_INSERT_BATCH
*/
public static String insertBatch(Map params, ProviderContext context) {
Collection