com.rt.orm.jdbc.JdbcBean Maven / Gradle / Ivy
The newest version!
package com.rt.orm.jdbc;
import com.json.JSONObject;
import com.rt.core.constant.RTConst;
import com.rt.core.util.RTUtil;
import com.rt.logic.beans.LogicBean;
import java.io.Serializable;
import java.util.Map;
public class JdbcBean extends LogicBean {
public static final String TYPE_QUERY = "query";
public static final String TYPE_GET_ENTITY = "getEntity";
public static final String TYPE_INSERT = "insert";
public static final String TYPE_INSERT_ENTITY = "insertEntity";
public static final String TYPE_UPDATE = "update";
public static final String TYPE_UPDATE_ENTITY = "updateEntity";
public static final String TYPE_DELETE = "delete";
public static final String TYPE_DELETE_ENTITY = "deleteEntity";
public static final String TYPE_SAVE = "save";
public static final String TYPE_SAVE_ENTITY = "saveEntity";
public static final String TYPE_SQL = "sql";
public JdbcBean() {
}
public JdbcBean(String string) throws Exception {
super(string);
}
public JdbcBean(Map map) {
super(map);
}
public String getSql() {
return this.getString("sql");
}
public String getTableName() {
return this.getString("tableName");
}
public boolean isIgnoreError() {
return this.getBoolean("ignoreError");
}
public String getDependDataId() {
return this.getString("dependDataId");
}
public void setDependDataId(String id) {
this.put("dependDataId", id);
}
/**
* 最多返回记录数
*
* @return the maxRow
*/
public long getMaxRow() {
return getlong("maxRow");
}
/**
* 最多返回记录
*
* @param maxRow the maxRow to set
*/
public void setMaxRow(long maxRow) {
put("maxRow", maxRow);
}
/**
* 开始记录数
*
* @return the startRow
*/
public long getStartRow() {
return getlong("startRow");
}
/**
* 开始记录数
*
* @param startRow the startRow to set
*/
public void setStartRow(long startRow) {
put("startRow", startRow);
}
/**
* 新建 Builder 对象
*
* @return JdbcBeanBuilder
*/
public static JdbcBeanBuilder newBuilder() {
return new JdbcBeanBuilder();
}
/**
* JdbcBean对象生成器
*/
static class JdbcBeanBuilder {
private static String KEY_TYPE = "type";
private static String KEY_SQL = "sql";
private static String KEY_PARAM = "param";
private static String KEY_TABLE_NAME = "tableName";
private static String KEY_START_ROW = "startRow";
private static String KEY_MAX_ROW = "maxRow";
private static String KEY_IGNORE_ERROR = "ignoreError";
private static String KEY_DEPEND_DATA_ID = "dependDataId";
private String id;
private String type;
private String sql;
private JSONObject param;
private String tableName;
private Long startRow;
private Long maxRow;
private String ignoreError;
private String dependDataId;
public JdbcBean build() {
JdbcBean op = new JdbcBean();
op.setId(id);
if (RTUtil.isNotEmpty(type)) op.put(KEY_TYPE, type);
if (RTUtil.isNotEmpty(sql)) op.put(KEY_SQL, sql);
if (RTUtil.isNotEmpty(param)) op.put(KEY_PARAM, param);
if (RTUtil.isNotEmpty(tableName)) op.put(KEY_TABLE_NAME, tableName);
if (RTUtil.isNotEmpty(startRow)) op.put(KEY_START_ROW, startRow);
if (RTUtil.isNotEmpty(maxRow)) op.put(KEY_MAX_ROW, maxRow);
if (RTUtil.isNotEmpty(ignoreError)) op.put(KEY_IGNORE_ERROR, ignoreError);
if (RTUtil.isNotEmpty(dependDataId)) op.put(KEY_DEPEND_DATA_ID, dependDataId);
return op;
}
public JdbcBeanBuilder() {
id = RTUtil.getUUID();
ignoreError = RTConst.FALSE;
}
public JdbcBeanBuilder withId(String id) {
this.id = id;
return this;
}
public JdbcBeanBuilder withIgnoreError(String ignoreError) {
this.ignoreError = ignoreError;
return this;
}
/**
* 通用type生成方法
*
* @param type type
* @return JdbcBeanBuilder
*/
public JdbcBeanBuilder withType(String type) {
this.type = type;
return this;
}
// 特定 type 生成方法 BEGIN
public JdbcBeanBuilder withQueryType() {
this.type = JdbcBean.TYPE_QUERY;
return this;
}
public JdbcBeanBuilder withGetEntityType() {
this.type = JdbcBean.TYPE_GET_ENTITY;
return this;
}
public JdbcBeanBuilder withInsertType() {
this.type = JdbcBean.TYPE_INSERT;
return this;
}
public JdbcBeanBuilder withInsertEntityType() {
this.type = JdbcBean.TYPE_INSERT_ENTITY;
return this;
}
public JdbcBeanBuilder withUpdateType() {
this.type = JdbcBean.TYPE_UPDATE;
return this;
}
public JdbcBeanBuilder withUpdateEntityType() {
this.type = JdbcBean.TYPE_UPDATE_ENTITY;
return this;
}
public JdbcBeanBuilder withDeleteType() {
this.type = JdbcBean.TYPE_DELETE;
return this;
}
public JdbcBeanBuilder withDeleteEntityType() {
this.type = JdbcBean.TYPE_DELETE_ENTITY;
return this;
}
public JdbcBeanBuilder withSaveType() {
this.type = JdbcBean.TYPE_SAVE;
return this;
}
public JdbcBeanBuilder withSaveEntityType() {
this.type = JdbcBean.TYPE_SAVE_ENTITY;
return this;
}
public JdbcBeanBuilder withSqlType() {
this.type = JdbcBean.TYPE_SQL;
return this;
}
// 特定 type 生成方法 END
public JdbcBeanBuilder withSql(String sql) {
this.sql = sql;
return this;
}
public JdbcBeanBuilder withTableName(String tableName) {
this.tableName = tableName;
return this;
}
public JdbcBeanBuilder withParams(JSONObject param) {
this.param = param;
return this;
}
public JdbcBeanBuilder withStartRow(Long startRow) {
this.startRow = startRow;
return this;
}
public JdbcBeanBuilder withMaxRow(Long maxRow) {
this.maxRow = maxRow;
return this;
}
public JdbcBeanBuilder withDependDataId(String dependDataId) {
this.dependDataId = dependDataId;
return this;
}
public JdbcBeanBuilder withParam(String key, Serializable value) {
if (RTUtil.isEmpty(param)) {
param = new JSONObject();
}
param.put(key, value);
return this;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getSql() {
return sql;
}
public void setSql(String sql) {
this.sql = sql;
}
public JSONObject getParam() {
return param;
}
public void setParam(JSONObject param) {
this.param = param;
}
public String getTableName() {
return tableName;
}
public void setTableName(String tableName) {
this.tableName = tableName;
}
public String getIgnoreError() {
return ignoreError;
}
public void setIgnoreError(String ignoreError) {
this.ignoreError = ignoreError;
}
public String getDependDataId() {
return dependDataId;
}
public void setDependDataId(String dependDataId) {
this.dependDataId = dependDataId;
}
}
}