Search in sources :

Example 26 with Sql

use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.

the class DeleteDAOImpl method deleteWhere.

public <T> Number deleteWhere(Class<T> clazz, String condition, Object[] args) throws DAOException {
    Number id = 0;
    if (clazz != null) {
        Connection con = null;
        try {
            con = ds.getConnection();
            Sql sql = SqlFactory.getDeleteSql(new Object[] { clazz.newInstance() }).deleteWhere(ORMConfigBeanUtil.parseQuery(condition, clazz));
            id = JdbcUtil.updateWithArgs(con, sql.sql, args);
        // 缓存
        } catch (Exception e) {
            throw new DAOException("", e);
        }
    }
    return id;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException) Sql(org.eweb4j.orm.sql.Sql)

Example 27 with Sql

use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.

the class InsertDAOImpl method insertByFields.

public <T> Number[] insertByFields(T[] ts, String[] fields) 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).createByFields(fields);
        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;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException) Sql(org.eweb4j.orm.sql.Sql)

Example 28 with Sql

use of org.eweb4j.orm.sql.Sql in project eweb4j-framework by laiweiwei.

the class UpdateDAOImpl method batchUpdate.

public <T> Number[] batchUpdate(T[] ts, String... fields) throws DAOException {
    Number[] ids = null;
    if (ts != null && ts.length > 0) {
        Connection con = null;
        ids = new Number[ts.length];
        try {
            con = ds.getConnection();
            Sql[] sqls = SqlFactory.getUpdateSql(ts).update(fields);
            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("batchUpdate exception ", e);
        }
    }
    return ids;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) DAOException(org.eweb4j.orm.dao.DAOException) Sql(org.eweb4j.orm.sql.Sql)

Aggregations

Sql (org.eweb4j.orm.sql.Sql)28 Connection (java.sql.Connection)13 DAOException (org.eweb4j.orm.dao.DAOException)13 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)6 Master (test.po.Master)4 HashMap (java.util.HashMap)3 Pet (test.po.Pet)3