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.
/*
* Copyright (c) 2023, 杭州坦信科技有限公司 (https://www.mybatis-easy.com).
* 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.mybatiseasy.core.provider;
import com.mybatiseasy.core.consts.MethodParam;
import com.mybatiseasy.core.enums.StatementType;
import com.mybatiseasy.core.session.EntityField;
import com.mybatiseasy.core.session.Entity;
import com.mybatiseasy.core.sqlbuilder.QueryWrapper;
import com.mybatiseasy.core.type.Record;
import com.mybatiseasy.core.utils.MetaObjectUtil;
import com.mybatiseasy.core.utils.SqlUtil;
import com.mybatiseasy.core.utils.TypeUtil;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.type.UnknownTypeHandler;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* 获得insert和update语句
*/
public class SqlBuilder {
private List insertSymbolList = new ArrayList<>();
private List> insertValuesList = new ArrayList<>();
private List updateValueList = new ArrayList<>();
/**
* 拼接insert字段
* @param columnList List
* @return 字段列表
*/
private List getInsertColumnSymbolList(List columnList) {
return columnList.stream().map(EntityField::getColumn).collect(Collectors.toList());
}
/**
* 根据实体表获取insert语句 字段
* @param map 参数
* @param entity 实体映射
* @param entityObj 传入的实体对象
* @return List
*/
private List getInsertValues(Map map, Entity entity, MetaObject entityObj){
List valueList = new ArrayList<>();
String name;
Object value;
String insertDefault;
for (EntityField fieldMap: entity.getEntityFieldMapList()
) {
if(fieldMap.isForeign()) continue;;
name = fieldMap.getName();
value = null;
if(entityObj.hasGetter(name)) value = entityObj.getValue(name);
else{
String otherName = SqlUtil.removeBackquote(fieldMap.getColumn());
if(entityObj.hasGetter(otherName)) value = entityObj.getValue(otherName);
}
if(value != null) {
map.put(name, value);
valueList.add(getColumnValue(fieldMap, name));
}else{
insertDefault = fieldMap.getInsertDefault();
if(!insertDefault.isEmpty()){
map.put(name, insertDefault);
valueList.add(getColumnValue(fieldMap, name, insertDefault));
}
}
}
return valueList;
}
/**
* 根据实体表获取批量insert语句 字段
* @param map 上下文
* @param entityList 实体列表
* @param insertColumnList 插入的column字段
* @return List<(#{value1}, #{value2}, ...)>
*/
private List> getInsertValuesList(Map map, List