use of org.apache.ojb.broker.PersistenceBroker 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?
}
}
}
}
});
}
use of org.apache.ojb.broker.PersistenceBroker 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?
}
}
}
}
});
}
use of org.apache.ojb.broker.PersistenceBroker in project cu-kfs by CU-CommunityApps.
the class ActionTakenDAOOjbImpl method getLastModifiedDate.
@Override
public Timestamp getLastModifiedDate(String documentId) {
return (Timestamp) getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() {
public Object doInPersistenceBroker(PersistenceBroker broker) {
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
Connection connection = broker.serviceConnectionManager().getConnection();
statement = connection.prepareStatement(LAST_MODIFIED_DATE_QUERY);
statement.setString(1, documentId);
resultSet = statement.executeQuery();
if (!resultSet.next()) {
return null;
} else {
return resultSet.getTimestamp(1);
}
} catch (Exception e) {
throw new WorkflowRuntimeException("Error determining Last Modified Date.", 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?
}
}
}
}
});
}
use of org.apache.ojb.broker.PersistenceBroker in project cu-kfs by CU-CommunityApps.
the class ActionTakenDAOOjbImpl method getLastActionTakenDate.
public Timestamp getLastActionTakenDate(final String documentId, final ActionType actionType) {
return (Timestamp) getPersistenceBrokerTemplate().execute(new PersistenceBrokerCallback() {
public Object doInPersistenceBroker(PersistenceBroker broker) {
PreparedStatement statement = null;
ResultSet resultSet = null;
try {
Connection connection = broker.serviceConnectionManager().getConnection();
statement = connection.prepareStatement(LAST_ACTION_TAKEN_DATE_QUERY);
statement.setString(1, documentId);
statement.setString(2, actionType.getCode());
resultSet = statement.executeQuery();
if (!resultSet.next()) {
return null;
} else {
return resultSet.getTimestamp(1);
}
} catch (Exception e) {
throw new WorkflowRuntimeException("Error determining Last Action Taken Date.", 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?
}
}
}
}
});
}
use of org.apache.ojb.broker.PersistenceBroker 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;
}
Aggregations