Search in sources :

Example 41 with DAOException

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

the class InsertDAOImpl method insertBySql.

public <T> Number insertBySql(Class<T> clazz, String sql, Object... args) throws DAOException {
    Number id = 0;
    if (sql == null)
        return -1;
    Connection con = null;
    try {
        con = ds.getConnection();
        id = JdbcUtil.updateWithArgs(con, sql, args);
    //			if (rs > 0) {
    //				id = DAOUtil.selectMaxId(clazz, ds.getConnection(), dbType);
    //			}
    } 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)

Example 42 with DAOException

use of org.eweb4j.orm.dao.DAOException 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 43 with DAOException

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

the class DivPageDAOImpl method divPageByFieldNotIsValue.

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

Example 44 with DAOException

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

the class DivPageDAOImpl method nextOne.

public <T> T nextOne(Class<T> clazz, String column, int value) throws DAOException {
    if (clazz != null) {
        Connection con = null;
        try {
            con = ds.getConnection();
            List<T> list = JdbcUtil.getList(con, clazz, SqlFactory.getSelectSql(clazz.newInstance(), dbType).nextOne(column, value));
            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 45 with DAOException

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

the class DivPageDAOImpl method divPageByFieldNotIsValues.

public <T> List<T> divPageByFieldNotIsValues(T t, String[] fields, int orderType, int currPage, int numPerPage, boolean isOR) throws DAOException {
    List<T> list = null;
    if (t != null) {
        @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) t.getClass();
        Connection con = null;
        try {
            con = ds.getConnection();
            String sql = SqlFactory.getSelectSql(t, dbType).selectWhere(fields, null, -2, false, true, isOR, null, orderType, currPage, numPerPage);
            list = JdbcUtil.getList(con, clazz, sql);
        } catch (Exception e) {
            throw new DAOException("divPageByFieldNotIsValues 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