Search in sources :

Example 21 with DAOException

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

the class SearchDAOImpl method search.

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

Example 22 with DAOException

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

the class SearchDAOImpl method searchByDivPage.

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

Example 23 with DAOException

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

the class SelectDAOImpl method selectCount.

public <T> long selectCount(Class<T> clazz, String condition) throws DAOException {
    long result = -1;
    Connection con = null;
    try {
        con = ds.getConnection();
        if (clazz != null) {
            T t = clazz.newInstance();
            String sql = SqlFactory.getSelectSql(t, dbType).selectCount(ORMConfigBeanUtil.parseQuery(condition, clazz));
            String str = String.valueOf(JdbcUtil.getObject(con, sql));
            if (CommonUtil.isNumeric(str)) {
                result = Integer.parseInt(str);
            }
        }
    } catch (Exception e) {
        throw new DAOException("", e);
    }
    return result;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException)

Example 24 with DAOException

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

the class SelectDAOImpl method selectOne.

public <T> T selectOne(T t, String... fields) throws DAOException {
    T result = 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);
            List<T> list = JdbcUtil.getList(con, clazz, sql);
            if (list != null && !list.isEmpty()) {
                result = list.get(0);
            }
        } catch (Exception e) {
            throw new DAOException("", e);
        }
    }
    return result;
}
Also used : DAOException(org.eweb4j.orm.dao.DAOException) Connection(java.sql.Connection) DAOException(org.eweb4j.orm.dao.DAOException)

Example 25 with DAOException

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

the class SelectDAOImpl method selectWhere.

public <T> List<T> selectWhere(Class<T> clazz, String condition, Object... args) throws DAOException {
    List<T> result = null;
    Connection con = null;
    try {
        con = ds.getConnection();
        T t = clazz.newInstance();
        String sql = SqlFactory.getSelectSql(t, dbType).select(ORMConfigBeanUtil.parseQuery(condition, clazz));
        result = JdbcUtil.getListWithArgs(con, clazz, sql, args);
    } catch (Exception e) {
        throw new DAOException("", e);
    }
    return result;
}
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