use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.
the class DeleteDAOImpl method deleteByFieldIsValue.
public <T> Number[] deleteByFieldIsValue(Class<T>[] clazz, String[] fields, String[] values) throws DAOException {
Number[] ids = null;
Connection con = null;
if (clazz == null || clazz.length == 0)
return ids;
ids = new Number[clazz.length];
try {
con = ds.getConnection();
Object[] ts = new Object[clazz.length];
for (int i = 0; i < clazz.length; ++i) {
ts[i] = clazz[i].newInstance();
}
Sql[] sqls = SqlFactory.getDeleteSql(ts).delete(fields, values);
List<Object[]> argList = new ArrayList<Object[]>(ts.length);
for (Sql sql : sqls) {
argList.add(sql.args.toArray());
}
Object[][] args = new Object[argList.size()][];
for (int i = 0; i < argList.size(); i++) {
args[i] = argList.get(i);
}
ids = JdbcUtil.batchUpdateWithArgs(con, sqls[0].sql, args);
} catch (Exception e) {
throw new DAOException("", e);
}
return ids;
}
use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.
the class DeleteDAOImpl method deleteByFields.
public <T> Number deleteByFields(T t, String[] fields) throws DAOException {
Number id = 0;
if (t != null) {
Connection con = null;
try {
con = ds.getConnection();
Sql[] sqls = SqlFactory.getDeleteSql(new Object[] { t }).delete(fields);
id = JdbcUtil.updateWithArgs(con, sqls[0].sql, sqls[0].args.toArray());
} catch (Exception e) {
throw new DAOException("", e);
}
}
return id;
}
use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.
the class InsertDAOImpl method batchInsert.
public <T> Number[] batchInsert(T[] ts, String[] fields, Object[] values) throws DAOException {
Number[] ids = null;
Connection con = null;
if (ts == null || ts.length == 0)
return ids;
try {
con = ds.getConnection();
Sql[] sqls = SqlFactory.getInsertSql(ts).createByFieldsIsValues(fields, values);
List<Object[]> argList = new ArrayList<Object[]>(ts.length);
for (Sql sql : sqls) {
argList.add(sql.args.toArray());
}
Object[][] args = new Object[argList.size()][];
for (int i = 0; i < argList.size(); i++) {
args[i] = argList.get(i);
}
ids = JdbcUtil.batchUpdateWithArgs(con, sqls[0].sql, args);
} catch (Exception e) {
throw new DAOException("", e);
}
return ids;
}
use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.
the class InsertDAOImpl method insertByCondition.
public <T> Number[] insertByCondition(T[] ts, String condition) throws DAOException {
Number[] ids = null;
Connection con = null;
if (ts == null || ts.length == 0)
return ids;
ids = new Number[ts.length];
try {
Sql[] sqls = SqlFactory.getInsertSql(ts).create(condition);
for (int i = 0; i < ts.length; i++) {
con = ds.getConnection();
ids[i] = JdbcUtil.updateWithArgs(con, sqls[i].sql, sqls[i].args.toArray());
}
} catch (Exception e) {
throw new DAOException("", e);
}
return ids;
}
use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.
the class InsertDAOImpl method batchInsert.
public <T> Number[] batchInsert(T[] ts, String... fields) throws DAOException {
Number[] ids = null;
Connection con = null;
if (ts == null || ts.length == 0)
return ids;
try {
con = ds.getConnection();
Sql[] sqls = null;
if (fields != null && fields.length > 0)
sqls = SqlFactory.getInsertSql(ts).createByFields(fields);
else
sqls = SqlFactory.getInsertSql(ts).create();
List<Object[]> argList = new ArrayList<Object[]>(ts.length);
for (Sql sql : sqls) {
argList.add(sql.args.toArray());
}
Object[][] args = new Object[argList.size()][];
for (int i = 0; i < argList.size(); i++) {
args[i] = argList.get(i);
}
ids = JdbcUtil.batchUpdateWithArgs(con, sqls[0].sql, args);
} catch (Exception e) {
throw new DAOException("", e);
}
return ids;
}
Aggregations