Search in sources :

Example 6 with TransactionCriteria

use of org.jaffa.transaction.apis.data.TransactionCriteria in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method findByFieldValueOrderByCreatedOnDesc.

/**
 * Gets all Transactions with the input field-value and returns them ordered descending by the createdOn parameter.
 *
 * @param field the field to check the value of
 * @param value the input value of the field we are looking for
 * @return all Transactions with the input field-value and returns them ordered by the createdOn parameter
 * @throws FrameworkException
 */
@Override
public List<Transaction> findByFieldValueOrderByCreatedOnDesc(String field, String value) throws FrameworkException {
    UOW uow = null;
    List<Transaction> transactions = new ArrayList<Transaction>();
    try {
        uow = new UOW();
        Criteria transactionCriteria = new Criteria();
        transactionCriteria.setTable(TransactionMeta.getName());
        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);
        transactionCriteria.addAggregate(joinCriteria);
        transactionCriteria.addOrderBy(TransactionMeta.CREATED_ON);
        for (Object result : uow.query(transactionCriteria)) {
            if (!(result instanceof Transaction)) {
                continue;
            }
            transactions.add((Transaction) result);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transactions;
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) ArrayList(java.util.ArrayList) Criteria(org.jaffa.persistence.Criteria) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) UOW(org.jaffa.persistence.UOW)

Aggregations

UOW (org.jaffa.persistence.UOW)6 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)6 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)6 Transaction (org.jaffa.transaction.domain.Transaction)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 LinkedHashMap (java.util.LinkedHashMap)5 Map (java.util.Map)5 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)5 Criteria (org.jaffa.persistence.Criteria)5 Serializable (java.io.Serializable)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 StringCriteriaField (org.jaffa.components.finder.StringCriteriaField)1 TransactionService (org.jaffa.transaction.apis.TransactionService)1 TransactionGraph (org.jaffa.transaction.apis.data.TransactionGraph)1 TransactionQueryResponse (org.jaffa.transaction.apis.data.TransactionQueryResponse)1