Commit 61044206 authored by Quxl's avatar Quxl

x

parent 99c11b6b
......@@ -285,6 +285,14 @@ public class JdbcTemplate extends org.springframework.jdbc.core.JdbcTemplate {
return delete_count;
}
public int batchDelete(Object... objs) {
Sql desc = dialect.argsDelete(obj);
}
public int batchDelete(List<Object> objs) {
return this.batchDelete(objs.toArray());
}
public int deleteByField(Object obj, String... byFields) {
Desc desc = dialect.getDesc(obj.getClass());
Map<String, Object> columnsMap = dialect.getColumnValueByField(obj, byFields);
......
......@@ -124,6 +124,33 @@ public abstract class AbstractDialect implements Dialect {
return new Sql(sql, args.toArray());
}
public Sql batchDelete(Object[] objs) {
if(objs.length > 0) {
Class<?> clz = objs[0].getClass();
Desc i_table = new Desc(clz);
String table_name = i_table.getName();
String[] pk_fields = i_table.getFieldPkNames();
String[] pk_columns = i_table.getColumnPkNames();
Object[][] vals = new Object[objs.length][];
for(int k = 0; k < objs.length; k++) {
Object obj = objs[k];
List<Object> args = new ArrayList<Object>();
for(int i = 0; i < pk_fields.length; i++) {
Object arg = ReflexUtil.readField(pk_fields[i], obj);
if(arg != null && arg instanceof Date) {
arg = new Timestamp(((Date)arg).getTime());
}
args.add(arg);
}
vals[k] = args.toArray();
}
String sql = "delete from " + table_name + StringUtil.join(" = ? and ", " where ", " = ?", pk_columns);
return new Sql(sql, vals);
} else {
throw new RuntimeException("DataArray can't be null");
}
}
public Sql argsUpdate(Object obj) {
Class<?> clz = obj.getClass();
Desc i_table = new Desc(clz);
......
......@@ -60,6 +60,8 @@ public interface Dialect {
*/
public Sql argsDelete(Object obj);
public Sql batchDelete(Object[] obj);
/**
* 生成删除SQL语句
* @param tableName
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment