use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getOpenTransactionDependencyCount.
/**
* Gets the count of TransactionDependencies of the input Transaction that are in the open state
*
* @param transactionId the ID of the Transaction to get the open TransactionDependency count for
* @return the count of open TransactionDependencies for the input Transaction
* @throws FrameworkException
*/
@Override
public long getOpenTransactionDependencyCount(String transactionId) throws FrameworkException {
UOW uow = null;
long dependencyCount = 0;
try {
uow = new UOW();
Criteria criteria = new Criteria();
criteria.setTable(TransactionDependencyMeta.getName());
criteria.addCriteria(TransactionDependencyMeta.TRANSACTION_ID, transactionId);
criteria.addCriteria(TransactionDependencyMeta.STATUS, TransactionDependency.Status.O.toString());
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Number count = (Number) ((Map) uow.query(criteria).iterator().next()).get(Criteria.ID_FUNCTION_COUNT);
if (count != null) {
dependencyCount = count.longValue();
}
} finally {
if (uow != null) {
uow.close();
}
}
return dependencyCount;
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getOpenDependenciesByDependsOnId.
/**
* Gets all TransactionDependencies in the open state that depend on the Transaction with the input ID.
*
* @param transactionId the ID of the Transaction
* @return all TransactionDependencies in the open state that depend on the Transaction with the input ID
* @throws FrameworkException
*/
@Override
public Collection<TransactionDependency> getOpenDependenciesByDependsOnId(String transactionId) throws FrameworkException {
UOW uow = null;
List<TransactionDependency> results = new ArrayList<TransactionDependency>();
try {
uow = new UOW();
Criteria criteria = new Criteria();
criteria.setTable(TransactionDependencyMeta.getName());
criteria.addCriteria(TransactionDependencyMeta.DEPENDS_ON_ID, transactionId);
criteria.addCriteria(TransactionDependencyMeta.STATUS, TransactionDependency.Status.O.toString());
for (Object result : uow.query(criteria)) {
results.add((TransactionDependency) result);
}
} finally {
if (uow != null) {
uow.close();
}
}
return results;
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getTransactionsByField.
/**
* Gets all Transactions that have the specified field with the input value.
*
* @param fieldName the field to check for the input value
* @param value the value to check against the field
* @return a collection of Transactions that contain the specified field with the input value
* @throws FrameworkException
*/
@Override
public Collection<Transaction> getTransactionsByField(String fieldName, String value) throws FrameworkException {
UOW uow = null;
Collection<Transaction> results = new ArrayList<Transaction>();
try {
uow = new UOW();
// set up a Transaction criteria
Criteria criteria = new Criteria();
criteria.setTable(TransactionMeta.getName());
// join to the TransactionField table
Criteria joinCriteria = new Criteria();
joinCriteria.setTable(TransactionFieldMeta.getName());
joinCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
joinCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, fieldName);
// either query for a value or relational null based on the input
if (value != null) {
joinCriteria.addCriteria(TransactionFieldMeta.VALUE, value);
} else {
joinCriteria.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
}
criteria.addAggregate(joinCriteria);
for (Object result : uow.query(criteria)) {
if (!(result instanceof Transaction)) {
continue;
}
results.add((Transaction) result);
}
} finally {
if (uow != null) {
uow.close();
}
}
return results;
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getCountInboundOpenInProgress.
/**
* Gets the count of inbound Transactions with the specified field-value, type and subType that
* are in the Open or InProgress state.
*
* @param field the field to check the value of
* @param value the input value of the field we are looking for
* @param type the type of the Transaction
* @param subType the subType of the Transaction
* @return the count of Transactions with the specified field-value, type and subType that are in the
* Open or inProgress state.
* @throws FrameworkException
*/
@Override
public long getCountInboundOpenInProgress(String field, String value, String type, String subType) throws FrameworkException {
UOW uow = null;
long transactionCount = 0;
try {
uow = new UOW();
AtomicCriteria ac = new AtomicCriteria();
// we want Open and In Progress
ac.addCriteria(TransactionMeta.STATUS, Transaction.Status.O.toString());
ac.addOrCriteria(TransactionMeta.STATUS, Transaction.Status.I.toString());
// add the field name and value
Criteria joinCriteria = new Criteria();
joinCriteria.setTable(TransactionFieldMeta.getName());
joinCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
joinCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, field);
joinCriteria.addCriteria(TransactionFieldMeta.VALUE, value);
// add the type, subType and direction
Criteria c = new Criteria();
c.setTable(TransactionMeta.getName());
c.addCriteria(TransactionMeta.TYPE, type);
c.addCriteria(TransactionMeta.SUB_TYPE, subType);
c.addCriteria(TransactionMeta.DIRECTION, Transaction.Direction.IN.toString());
c.addAtomic(ac);
c.addAggregate(joinCriteria);
c.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
// return the count, or zero
Iterator itr = uow.query(c).iterator();
if (itr.hasNext()) {
Number count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
transactionCount = count.longValue();
}
} finally {
if (uow != null) {
uow.close();
}
}
return transactionCount;
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getCountTxInError.
/**
* Gets the count of all Transactions in the input list of IDs that are in the error state.
*
* @param transactionIds the IDs of the Transactions to check for the error state
* @return the count of all Transactions in the error state
* @throws FrameworkException
*/
@Override
public long getCountTxInError(List<String> transactionIds) throws FrameworkException {
UOW uow = null;
long errorCount = 0;
try {
uow = new UOW();
AtomicCriteria ac = new AtomicCriteria();
for (String transactionId : transactionIds) {
ac.addOrCriteria(TransactionMeta.ID, transactionId);
}
Criteria criteria = new Criteria();
criteria.setTable(TransactionMeta.getName());
criteria.addCriteria(TransactionMeta.STATUS, Transaction.Status.E.toString());
criteria.addAtomic(ac);
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
Number count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
errorCount = count.longValue();
}
} finally {
if (uow != null) {
uow.close();
}
}
return errorCount;
}
Aggregations