Search in sources :

Example 56 with UOW

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;
}
Also used : 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)

Example 57 with UOW

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;
}
Also used : 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) TransactionDependency(org.jaffa.transaction.domain.TransactionDependency)

Example 58 with UOW

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;
}
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)

Example 59 with UOW

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;
}
Also used : Iterator(java.util.Iterator) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) 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)

Example 60 with UOW

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;
}
Also used : Iterator(java.util.Iterator) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) 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)260 Criteria (org.jaffa.persistence.Criteria)139 FrameworkException (org.jaffa.exceptions.FrameworkException)99 ApplicationException (org.jaffa.exceptions.ApplicationException)88 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)87 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)82 Iterator (java.util.Iterator)47 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)33 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)33 ArrayList (java.util.ArrayList)19 Transaction (org.jaffa.transaction.domain.Transaction)19 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)13 HashMap (java.util.HashMap)12 DateTime (org.jaffa.datatypes.DateTime)11 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)10 IPersistent (org.jaffa.persistence.IPersistent)10 Method (java.lang.reflect.Method)9 Collection (java.util.Collection)8 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)8