io.github.davidchild.bitter.op.read.ExecuteQuery Maven / Gradle / Ivy
package io.github.davidchild.bitter.op.read;
import io.github.davidchild.bitter.BaseModel;
import io.github.davidchild.bitter.basequery.BaseQuery;
import io.github.davidchild.bitter.basequery.ExecuteEnum;
import io.github.davidchild.bitter.bitterlist.BMap;
import io.github.davidchild.bitter.dbtype.KeyInfo;
import io.github.davidchild.bitter.parbag.ExecuteParBagExecute;
import io.github.davidchild.bitter.tools.BitterLogUtil;
import java.sql.SQLException;
import java.util.*;
public class ExecuteQuery extends BaseQuery {
private ExecuteParBagExecute bag;
public ExecuteQuery(String commandText, Object... params) {
executeParBag = new ExecuteParBagExecute();
executeParBag.setExecuteEnum(ExecuteEnum.ExecuteQuery);
((ExecuteParBagExecute) executeParBag).setCommandText(commandText);
((ExecuteParBagExecute) executeParBag).setParaMap(new LinkedHashMap<>());
if (params != null && params.length > 0) {
Arrays.stream(params).forEach((v) -> {
((ExecuteParBagExecute) executeParBag).getParaMap().put(UUID.randomUUID().toString(), v);
});
}
}
protected ExecuteQuery(Class extends BaseModel> clazz) {
executeParBag = new ExecuteParBagExecute();
executeParBag.setExecuteEnum(ExecuteEnum.ExecuteQuery);
((ExecuteParBagExecute) executeParBag).setCommandText(commandText);
((ExecuteParBagExecute) executeParBag).setType(clazz);
((ExecuteParBagExecute) executeParBag).setParaMap(new LinkedHashMap<>());
}
///
/// 追加 where 1=1
///
///
public ExecuteQuery beginWhere(String beginWhere, Object... params) {
StringBuilder strBuild = new StringBuilder(((ExecuteParBagExecute) executeParBag).getCommandText());
strBuild.append(" where " + beginWhere);
((ExecuteParBagExecute) executeParBag).setCommandText(strBuild.toString());
if (params != null && params.length > 0) {
Arrays.stream(params).forEach((v) -> {
((ExecuteParBagExecute) executeParBag).getParaMap().put(UUID.randomUUID().toString(), v);
});
}
return this;
}
public ExecuteQuery andWhere(String andWhere, Object... params) {
StringBuilder strBuild = new StringBuilder(((ExecuteParBagExecute) executeParBag).getCommandText());
strBuild.append(" and (" + andWhere + ") ");
((ExecuteParBagExecute) executeParBag).setCommandText(strBuild.toString());
if (params != null && params.length > 0) {
Arrays.stream(params).forEach((v) -> {
((ExecuteParBagExecute) executeParBag).getParaMap().put(UUID.randomUUID().toString(), v);
});
}
return this;
}
public ExecuteQuery addParams(Object... params) {
if (params != null && params.length > 0) {
Arrays.stream(params).forEach((v) -> {
((ExecuteParBagExecute) executeParBag).getParaMap().put(UUID.randomUUID().toString(), v);
});
}
return this;
}
public BMap find() {
this.convert();
try {
List