com.rt.service.beans.BatchUpdate Maven / Gradle / Ivy
The newest version!
/*
* Created on 2008/08/21
* 业务层公用业务逻辑
* 感觉用处不大,考虑跟weblogic合并后删除当前类
*/
package com.rt.service.beans;
import com.json.JSONArray;
import com.json.JSONObject;
import com.rt.core.constant.RTConst;
import com.rt.core.util.RTUtil;
/**
* Batch Update bean
*
* @author msc
* @deprecated 请使用新的JdbcContext进行批量数据操作.
*/
public class BatchUpdate {
private JSONArray batchArray;
public static final String DB_METHOD = "db_m";
public static final String SQL = "sql";
public static final String UPD_MAP = "updMap";
public static final String PARAM = "param";
public static final String DB_TABLE_NAME = "db_t";
public static final String METHOD_INS = "ins";
public static final String METHOD_UPD = "upd";
public static final String METHOD_SAVE = "save";
public static final String METHOD_SF_UPD = "sfUpd";
public static final String METHOD_DEL = "del";
public static BatchUpdate build() {
return new BatchUpdate();
}
public JSONArray getBatchArray() {
if (batchArray == null) {
batchArray = new JSONArray();
}
return batchArray;
}
/**
* add data
*
* @param tableName tableName
* @param entity entity
* @return BatchUpdate
*/
public BatchUpdate add(String tableName, JSONObject entity) {
entity.put(DB_TABLE_NAME, tableName);
entity.put(DB_METHOD, METHOD_INS);
getBatchArray().add(entity);
return this;
}
/**
* upd data
*
* @param tableName tableName
* @param entity entity
* @return BatchUpdate
*/
public BatchUpdate upd(String tableName, JSONObject entity) {
entity.put(DB_TABLE_NAME, tableName);
entity.put(DB_METHOD, METHOD_UPD);
getBatchArray().add(entity);
return this;
}
/**
* save data insert or update
*
* @param tableName tableName
* @param entity entity
* @return BatchUpdate
*/
public BatchUpdate save(String tableName, JSONObject entity) {
entity.put(DB_TABLE_NAME, tableName);
entity.put(DB_METHOD, METHOD_SAVE);
getBatchArray().add(entity);
return this;
}
/**
* select for upd data
*
* @param sql sql
* @param param param
* @param updateSqlMap key=updateSql value=updateParam if updateParam is null, use param.
* @param returnSelectData returnSelectData
* @return BatchUpdate
*/
public JSONObject selectForUpdate(String sql, JSONObject param, JSONObject updateSqlMap, boolean returnSelectData) {
JSONObject entity = new JSONObject();
entity.setId(RTUtil.getUUID());
entity.put(DB_METHOD, METHOD_SF_UPD);
entity.put(SQL, sql);
entity.put(PARAM, param);
entity.put(UPD_MAP, updateSqlMap);
entity.put(RTConst.RETURN, returnSelectData);
getBatchArray().add(entity);
return entity;
}
/**
* del
*
* @param tableName tableName
* @param entity entity
* @return BatchUpdate
*/
public BatchUpdate del(String tableName, JSONObject entity) {
entity.put(DB_TABLE_NAME, tableName);
entity.put(DB_METHOD, METHOD_DEL);
getBatchArray().add(entity);
return this;
}
/**
* del
*
* @param tableName tableName
* @param id id
* @return BatchUpdate
*/
public BatchUpdate del(String tableName, String id) {
JSONObject entity = new JSONObject();
entity.put(DB_TABLE_NAME, tableName);
entity.put(DB_METHOD, METHOD_DEL);
entity.setId(id);
getBatchArray().add(entity);
return this;
}
}