Search in sources :

Example 16 with DAOException

use of org.eweb4j.orm.dao.DAOException in project eweb4j-framework by laiweiwei.

the class UpdateDAOImpl method batchUpdate.

public <T> Number[] batchUpdate(T[] ts, String[] fields, Object[] values) 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, 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("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)

Example 17 with DAOException

use of org.eweb4j.orm.dao.DAOException in project eweb4j-framework by laiweiwei.

the class DivPageDAOImpl method nextOne.

public <T> T nextOne(T t) throws DAOException {
    if (t != null) {
        @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) t.getClass();
        Connection con = null;
        try {
            con = ds.getConnection();
            List<T> list = JdbcUtil.getList(con, clazz, SqlFactory.getSelectSql(t, dbType).nextOne());
            return list != null && !list.isEmpty() ? list.get(0) : null;
        } catch (Exception e) {
            throw new DAOException("nextOne exception ", e);
        }
    }
    return null;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException)

Example 18 with DAOException

use of org.eweb4j.orm.dao.DAOException in project eweb4j-framework by laiweiwei.

the class DivPageDAOImpl method preOne.

public <T> T preOne(T t) throws DAOException {
    if (t != null) {
        Connection con = null;
        try {
            con = ds.getConnection();
            @SuppressWarnings("unchecked") List<T> list = JdbcUtil.getList(con, (Class<T>) t.getClass(), SqlFactory.getSelectSql(t, dbType).preOne());
            return list != null && !list.isEmpty() ? list.get(0) : null;
        } catch (Exception e) {
            throw new DAOException("preOne exception ", e);
        }
    }
    return null;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException)

Example 19 with DAOException

use of org.eweb4j.orm.dao.DAOException in project eweb4j-framework by laiweiwei.

the class DivPageDAOImpl method divPageByFieldNotLikeValue.

public <T> List<T> divPageByFieldNotLikeValue(Class<T> clazz, String[] fields, String[] values, int likeType, String orderField, int orderType, int currPage, int numPerPage, boolean isOR) throws DAOException {
    List<T> list = null;
    if (clazz != null) {
        Connection con = null;
        try {
            con = ds.getConnection();
            String sql = SqlFactory.getSelectSql(clazz.newInstance(), dbType).selectWhere(fields, values, likeType, true, true, isOR, orderField, orderType, currPage, numPerPage);
            list = JdbcUtil.getList(con, clazz, sql);
        } catch (Exception e) {
            throw new DAOException("divPageByFieldNotLikeValue exception ", e);
        }
    }
    return list;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException)

Example 20 with DAOException

use of org.eweb4j.orm.dao.DAOException in project eweb4j-framework by laiweiwei.

the class DivPageDAOImpl method divPageByFieldIsValue.

public <T> List<T> divPageByFieldIsValue(Class<T> clazz, String[] fields, String[] values, String orderField, int orderType, int currPage, int numPerPage, boolean isOR) throws DAOException {
    List<T> list = null;
    if (clazz != null) {
        Connection con = null;
        try {
            con = ds.getConnection();
            String sql = SqlFactory.getSelectSql(clazz.newInstance(), dbType).selectWhere(fields, values, -2, false, false, isOR, orderField, orderType, currPage, numPerPage);
            list = JdbcUtil.getList(con, clazz, sql);
        } catch (Exception e) {
            throw new DAOException("divPageByFieldIsValue exception ", e);
        }
    }
    return list;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException)

Aggregations

DAOException (org.eweb4j.orm.dao.DAOException)56 Connection (java.sql.Connection)42 Sql (org.eweb4j.orm.sql.Sql)13 Method (java.lang.reflect.Method)9 ReflectUtil (org.eweb4j.util.ReflectUtil)9 Field (java.lang.reflect.Field)7 ArrayList (java.util.ArrayList)6 JoinColumn (javax.persistence.JoinColumn)6 JoinTable (javax.persistence.JoinTable)6 ManyToMany (javax.persistence.ManyToMany)3 ManyToOne (javax.persistence.ManyToOne)3 OneToMany (javax.persistence.OneToMany)3 Trans (org.eweb4j.orm.jdbc.transaction.Trans)3 Master (test.po.Master)3 List (java.util.List)2 OrderBy (javax.persistence.OrderBy)2 Pet (test.po.Pet)2 OneToOne (javax.persistence.OneToOne)1