Search in sources :

Example 6 with PersistenceBroker

use of org.apache.ojb.broker.PersistenceBroker in project cu-kfs by CU-CommunityApps.

the class DocumentRouteHeaderDAOOjbImpl method findByDocTypeAndAppId.

public Collection findByDocTypeAndAppId(String documentTypeName, String appId) {
    Collection documentIds = new ArrayList<>();
    PersistenceBroker broker = null;
    Connection conn = null;
    ResultSet rs = null;
    try {
        broker = getPersistenceBroker(false);
        conn = broker.serviceConnectionManager().getConnection();
        String query = "SELECT DISTINCT " + "    (docHdr.doc_hdr_id) " + "FROM " + "    KREW_DOC_HDR_T docHdr, " + "    KREW_DOC_TYP_T docTyp " + "WHERE " + "    docHdr.APP_DOC_ID     = ? " + "    AND docHdr.DOC_TYP_ID = docTyp.DOC_TYP_ID " + "    AND docTyp.DOC_TYP_NM = ?";
        LOG.debug("Query to find documents by app id: " + query);
        PreparedStatement stmt = conn.prepareStatement(query);
        stmt.setString(1, appId);
        stmt.setString(2, documentTypeName);
        rs = stmt.executeQuery();
        while (rs.next()) {
            documentIds.add(new String(rs.getString(1)));
        }
        rs.close();
    } catch (SQLException sqle) {
        LOG.error("SQLException: " + sqle.getMessage(), sqle);
        throw new WorkflowRuntimeException(sqle);
    } catch (LookupException le) {
        LOG.error("LookupException: " + le.getMessage(), le);
        throw new WorkflowRuntimeException(le);
    } finally {
        try {
            if (broker != null) {
                OjbFactoryUtils.releasePersistenceBroker(broker, this.getPersistenceBrokerTemplate().getPbKey());
            }
        } catch (Exception e) {
            LOG.error("Failed closing connection: " + e.getMessage(), e);
        }
    }
    return documentIds;
}
Also used : PersistenceBroker(org.apache.ojb.broker.PersistenceBroker) LookupException(org.apache.ojb.broker.accesslayer.LookupException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Collection(java.util.Collection) PreparedStatement(java.sql.PreparedStatement) WorkflowRuntimeException(org.kuali.kfs.kew.api.WorkflowRuntimeException) LookupException(org.apache.ojb.broker.accesslayer.LookupException) WorkflowRuntimeException(org.kuali.kfs.kew.api.WorkflowRuntimeException) SQLException(java.sql.SQLException) OptimisticLockException(org.apache.ojb.broker.OptimisticLockException) CannotAcquireLockException(org.springframework.dao.CannotAcquireLockException) LockingException(org.kuali.kfs.kew.api.exception.LockingException)

Aggregations

Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 PersistenceBroker (org.apache.ojb.broker.PersistenceBroker)6 WorkflowRuntimeException (org.kuali.kfs.kew.api.WorkflowRuntimeException)6 LookupException (org.apache.ojb.broker.accesslayer.LookupException)4 PersistenceBrokerCallback (org.springmodules.orm.ojb.PersistenceBrokerCallback)4 ArrayList (java.util.ArrayList)3 Timestamp (java.sql.Timestamp)2 OptimisticLockException (org.apache.ojb.broker.OptimisticLockException)2 LockingException (org.kuali.kfs.kew.api.exception.LockingException)2 CannotAcquireLockException (org.springframework.dao.CannotAcquireLockException)2 Statement (java.sql.Statement)1 Collection (java.util.Collection)1 List (java.util.List)1