Search in sources :

Example 1 with LookupException

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

the class CuEinvoiceDaoOjb method queryVendors.

protected ResultSet queryVendors(String searchCriteria) {
    ResultSet queryResults;
    try {
        Connection connection = getPersistenceBroker(true).serviceConnectionManager().getConnection();
        PreparedStatement query = connection.prepareCall(buildParameterizedVendorNumberQueryByVendorNameAndDunsNumber());
        String formattedSearchCriteria = KFSConstants.PERCENTAGE_SIGN + StringUtils.upperCase(searchCriteria).trim() + KFSConstants.PERCENTAGE_SIGN;
        query.setString(1, formattedSearchCriteria);
        query.setString(2, formattedSearchCriteria);
        queryResults = query.executeQuery();
    } catch (DataAccessResourceFailureException | LookupException | IllegalStateException | SQLException e) {
        LOG.error("queryVendors, there was an error querying the database: ", e);
        throw new RuntimeException(e);
    }
    return queryResults;
}
Also used : LookupException(org.apache.ojb.broker.accesslayer.LookupException) DataAccessResourceFailureException(org.springframework.dao.DataAccessResourceFailureException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 2 with LookupException

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

the class ActionListDAOOjbImpl method getCount.

public int getCount(final String workflowId) {
    return (Integer) getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() {

        public Object doInPersistenceBroker(PersistenceBroker broker) {
            PreparedStatement statement = null;
            ResultSet resultSet = null;
            try {
                Connection connection = broker.serviceConnectionManager().getConnection();
                statement = connection.prepareStatement(ACTION_LIST_COUNT_QUERY);
                statement.setString(1, workflowId);
                resultSet = statement.executeQuery();
                if (!resultSet.next()) {
                    throw new WorkflowRuntimeException("Error determining Action List Count.");
                }
                return resultSet.getInt(1);
            } catch (SQLException | LookupException e) {
                throw new WorkflowRuntimeException("Error determining Action List Count.", e);
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (SQLException e) {
                    // should we be logging something?
                    }
                }
                if (resultSet != null) {
                    try {
                        resultSet.close();
                    } catch (SQLException e) {
                    // should we be logging something?
                    }
                }
            }
        }
    });
}
Also used : PersistenceBroker(org.apache.ojb.broker.PersistenceBroker) LookupException(org.apache.ojb.broker.accesslayer.LookupException) SQLException(java.sql.SQLException) PersistenceBrokerCallback(org.springmodules.orm.ojb.PersistenceBrokerCallback) ResultSet(java.sql.ResultSet) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) WorkflowRuntimeException(org.kuali.kfs.kew.api.WorkflowRuntimeException)

Example 3 with LookupException

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

the class ActionListDAOOjbImpl method getMaxActionItemDateAssignedAndCountForUser.

/**
 * Gets the max action item id and count doe a given user.
 *
 * @return A List with the first value being the maxActionItemId and the second value being the count
 */
public List<Object> getMaxActionItemDateAssignedAndCountForUser(final String principalId) {
    return (List<Object>) getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() {

        public Object doInPersistenceBroker(PersistenceBroker broker) {
            PreparedStatement statement = null;
            ResultSet resultSet = null;
            List<Object> result = new ArrayList<Object>();
            try {
                Connection connection = broker.serviceConnectionManager().getConnection();
                statement = connection.prepareStatement(MAX_ACTION_ITEM_DATE_ASSIGNED_AND_ACTION_LIST_COUNT_AND_QUERY);
                statement.setString(1, principalId);
                resultSet = statement.executeQuery();
                if (!resultSet.next()) {
                    throw new WorkflowRuntimeException("Error determining Action List Count and Max Action Item Id.");
                } else {
                    result.add(resultSet.getTimestamp(1));
                    result.add(resultSet.getInt(2));
                }
                return result;
            } catch (SQLException e) {
                throw new WorkflowRuntimeException("Error determining Action List Count and Max Action Item Id.", e);
            } catch (LookupException e) {
                throw new WorkflowRuntimeException("Error determining Action List Count and Max Action Item Id.", e);
            } finally {
                if (statement != null) {
                    try {
                        statement.close();
                    } catch (SQLException e) {
                    // should we be logging something?
                    }
                }
                if (resultSet != null) {
                    try {
                        resultSet.close();
                    } catch (SQLException e) {
                    // should we be logging something?
                    }
                }
            }
        }
    });
}
Also used : PersistenceBroker(org.apache.ojb.broker.PersistenceBroker) LookupException(org.apache.ojb.broker.accesslayer.LookupException) SQLException(java.sql.SQLException) PersistenceBrokerCallback(org.springmodules.orm.ojb.PersistenceBrokerCallback) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ArrayList(java.util.ArrayList) List(java.util.List) PreparedStatement(java.sql.PreparedStatement) WorkflowRuntimeException(org.kuali.kfs.kew.api.WorkflowRuntimeException)

Example 4 with LookupException

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

the class DocumentRouteHeaderDAOOjbImpl method findPendingByResponsibilityIds.

public Collection<String> findPendingByResponsibilityIds(Set<String> responsibilityIds) {
    Collection<String> documentIds = new ArrayList<>();
    if (responsibilityIds.isEmpty()) {
        return documentIds;
    }
    PersistenceBroker broker = null;
    Connection conn = null;
    Statement statement = null;
    ResultSet rs = null;
    try {
        broker = getPersistenceBroker(false);
        conn = broker.serviceConnectionManager().getConnection();
        String respIds = "('";
        int index = 0;
        for (String responsibilityId : responsibilityIds) {
            respIds += responsibilityId + (index == responsibilityIds.size() - 1 ? "" : "','");
            index++;
        }
        respIds += "')";
        String query = "SELECT DISTINCT(doc_hdr_id) FROM KREW_ACTN_RQST_T " + "WHERE (STAT_CD='" + ActionRequestStatus.INITIALIZED.getCode() + "' OR STAT_CD='" + ActionRequestStatus.ACTIVATED.getCode() + "') AND RSP_ID IN " + respIds;
        LOG.debug("Query to find pending documents for requeue: " + query);
        statement = conn.createStatement();
        rs = statement.executeQuery(query);
        while (rs.next()) {
            documentIds.add(rs.getString(1));
        }
    } 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 {
        if (rs != null) {
            try {
                rs.close();
            } catch (SQLException e) {
                LOG.warn("Could not close result set.");
            }
        }
        if (statement != null) {
            try {
                statement.close();
            } catch (SQLException e) {
                LOG.warn("Could not close statement.");
            }
        }
        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) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) 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)

Example 5 with LookupException

use of org.apache.ojb.broker.accesslayer.LookupException 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)5 PreparedStatement (java.sql.PreparedStatement)5 ResultSet (java.sql.ResultSet)5 SQLException (java.sql.SQLException)5 LookupException (org.apache.ojb.broker.accesslayer.LookupException)5 PersistenceBroker (org.apache.ojb.broker.PersistenceBroker)4 WorkflowRuntimeException (org.kuali.kfs.kew.api.WorkflowRuntimeException)4 ArrayList (java.util.ArrayList)3 OptimisticLockException (org.apache.ojb.broker.OptimisticLockException)2 LockingException (org.kuali.kfs.kew.api.exception.LockingException)2 CannotAcquireLockException (org.springframework.dao.CannotAcquireLockException)2 PersistenceBrokerCallback (org.springmodules.orm.ojb.PersistenceBrokerCallback)2 Statement (java.sql.Statement)1 Collection (java.util.Collection)1 List (java.util.List)1 DataAccessResourceFailureException (org.springframework.dao.DataAccessResourceFailureException)1