Search in sources :

Example 36 with DAOException

use of org.eweb4j.orm.dao.DAOException 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 id = 0;
    if (clazz != null && fields != null && values != null && fields.length == values.length) {
        Connection con = null;
        try {
            con = ds.getConnection();
            Sql[] sqls = SqlFactory.getDeleteSql(new Object[] { clazz.newInstance() }).delete(fields, values);
            id = JdbcUtil.updateWithArgs(con, sqls[0].sql, sqls[0].args.toArray());
        } 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 37 with DAOException

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

the class UpdateDAOImpl method updateBySQLWithArgs.

public <T> Number[] updateBySQLWithArgs(String[] sqls, Object[][] args) throws DAOException {
    Number[] result = null;
    Connection con = null;
    try {
        con = ds.getConnection();
        result = JdbcUtil.updateWithArgs(con, sqls, args);
    } catch (Exception e) {
        throw new DAOException("updateBySQLWithArgs exception ", e);
    }
    return result;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException)

Example 38 with DAOException

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

the class UpdateDAOImpl method updateBySQL.

public <T> Number[] updateBySQL(String... sqls) throws DAOException {
    Number[] result = null;
    Connection con = null;
    try {
        con = ds.getConnection();
        result = JdbcUtil.update(con, sqls);
    } catch (Exception e) {
        throw new DAOException("updateBySQL exception ", e);
    }
    return result;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException)

Example 39 with DAOException

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

the class UpdateDAOImpl method updateByFieldIsValue.

public <T> Number[] updateByFieldIsValue(T[] ts, String[] fields, String[] values) throws DAOException {
    Number[] ids = null;
    if (ts != null && ts.length > 0 && fields != null && fields.length > 0) {
        Connection con = null;
        ids = new Number[ts.length];
        try {
            Sql[] sqls = SqlFactory.getUpdateSql(ts).update(fields, values);
            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("updateByFieldIsValue exception ", 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 40 with DAOException

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

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