Search in sources :

Example 51 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionByFieldsAndBeginsWithFields.

/**
 * Gets the Transaction that has the specified fields-values and also fields that begin with
 * the specified values.  If multiple beginsWith values are defined for a field, the field will be checked against
 * them all.
 *
 * @param fields     the field name/value pairs
 * @param beginsWith the field name/begins-with values
 * @return the Transaction that contains the specified fields with the input values
 * @throws FrameworkException
 */
@Override
public Transaction getTransactionByFieldsAndBeginsWithFields(HashMap<String, String> fields, HashMap<String, String> beginsWith) throws FrameworkException {
    UOW uow = null;
    Transaction transaction = null;
    try {
        uow = new UOW();
        TransactionCriteria transactionCriteria = new TransactionCriteria();
        List<TransactionFieldCriteria> tranFieldCriteriaList = new ArrayList<TransactionFieldCriteria>();
        // add all of the field criteria
        for (Map.Entry<String, String> field : fields.entrySet()) {
            TransactionFieldCriteria fieldCriteria = new TransactionFieldCriteria();
            fieldCriteria.setFieldName(field.getKey());
            StringCriteriaField stringCriteria = StringCriteriaField.getStringCriteriaField(StringCriteriaField.RELATIONAL_EQUALS, field.getValue(), null);
            fieldCriteria.setValue(stringCriteria);
            tranFieldCriteriaList.add(fieldCriteria);
        }
        // add all of the begins with criteria
        for (Map.Entry<String, String> beginsWithField : beginsWith.entrySet()) {
            TransactionFieldCriteria beginsWithCriteria = new TransactionFieldCriteria();
            beginsWithCriteria.setFieldName(beginsWithField.getKey());
            StringCriteriaField stringCriteria = StringCriteriaField.getStringCriteriaField(StringCriteriaField.RELATIONAL_BEGINS_WITH, beginsWithField.getValue(), null);
            beginsWithCriteria.setValue(stringCriteria);
            tranFieldCriteriaList.add(beginsWithCriteria);
        }
        // set all of the field criteria on the transaction criteria
        TransactionFieldCriteria[] criteriaArray = new TransactionFieldCriteria[tranFieldCriteriaList.size()];
        criteriaArray = tranFieldCriteriaList.toArray(criteriaArray);
        transactionCriteria.setTransactionFields(criteriaArray);
        // call the transaction service for a response to the query
        TransactionService transactionService = new TransactionService();
        TransactionQueryResponse response = transactionService.query(transactionCriteria);
        // return a transaction from the response
        for (TransactionGraph transactionGraph : response.getGraphs()) {
            if ((transactionGraph != null) && (transactionGraph.getId() != null)) {
                transaction = getTransaction(transactionGraph.getId());
            }
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return transaction;
}
Also used : TransactionService(org.jaffa.transaction.apis.TransactionService) TransactionFieldCriteria(org.jaffa.transaction.apis.data.TransactionFieldCriteria) ArrayList(java.util.ArrayList) TransactionQueryResponse(org.jaffa.transaction.apis.data.TransactionQueryResponse) TransactionCriteria(org.jaffa.transaction.apis.data.TransactionCriteria) Transaction(org.jaffa.transaction.domain.Transaction) TransactionGraph(org.jaffa.transaction.apis.data.TransactionGraph) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringCriteriaField(org.jaffa.components.finder.StringCriteriaField)

Example 52 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getDependencySweeperViewsIfOpenNoDependsOnTx.

/**
 * Returns all of the TransactionDependencySweeperViews of the TransactionDependencies in the Open state that have
 * no dependsOn Transaction or have a dependsOn Transaction in the S state.
 * The TransactionDependencySweeperView is a subset of the TransactionDependency model.
 *
 * @return all TransactionSweeperViews created from the Transactions in the Hold state that have
 *         no TransactionDependency in the Open state.
 * @throws FrameworkException
 */
@Override
public Collection<TransactionDependencySweeperView> getDependencySweeperViewsIfOpenNoDependsOnTx() throws FrameworkException {
    UOW uow = null;
    Collection<TransactionDependencySweeperView> results = new ArrayList<TransactionDependencySweeperView>();
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionDependencySweeperViewMeta.getName());
        // create a list of transactionDependencySweeperViews from the results
        for (Object result : uow.query(criteria)) {
            if (!(result instanceof TransactionDependencySweeperView)) {
                continue;
            }
            results.add((TransactionDependencySweeperView) result);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
Also used : TransactionDependencySweeperView(org.jaffa.transaction.domain.TransactionDependencySweeperView) 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 53 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionsByTypeSubTypeFieldsOrderBy.

/**
 * Gets an ordered list of Transaction that match the input type, subType and fields.
 * If more than one value is defined for a field, that field will be checked against all values to see if it
 * matched any of them (they will be OR-ed).
 *
 * @param type    the type of Transactions to return
 * @param subType the subType of Transactions to return
 * @param fields  the fields to check the Transaction for, if multiple values are defined for a field, the
 *                field will be checked to see if it matches any of the values (they will be OR-ed)
 * @param orderBy the fields to sort the return list by, each field has a boolean value that determines the
 *                direction.  True for ascending and false for descending.
 * @return an ordered list of Transactions that match the input type, subType and fields
 * @throws FrameworkException
 */
@Override
public List<Transaction> getTransactionsByTypeSubTypeFieldsOrderBy(String type, String subType, HashMap<String, List<String>> fields, LinkedHashMap<String, Boolean> orderBy) throws FrameworkException {
    List<Transaction> results = new ArrayList<Transaction>();
    UOW uow = null;
    try {
        uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(TransactionMeta.getName());
        // query on type and subType
        StringCriteriaField typeField = StringCriteriaField.getStringCriteriaField(CriteriaField.RELATIONAL_EQUALS, type, null);
        StringCriteriaField subTypeField = StringCriteriaField.getStringCriteriaField(CriteriaField.RELATIONAL_EQUALS, subType, null);
        FinderTx.addCriteria(typeField, TransactionMeta.TYPE, c);
        FinderTx.addCriteria(subTypeField, TransactionMeta.SUB_TYPE, c);
        // add the fields
        for (Map.Entry<String, List<String>> entry : fields.entrySet()) {
            Criteria joinCriteria = new Criteria();
            joinCriteria.setTable(TransactionFieldMeta.getName());
            joinCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
            // the key is the field name
            joinCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, entry.getKey());
            // the values are OR-ed together
            AtomicCriteria ac = new AtomicCriteria();
            for (String value : entry.getValue()) {
                if (value == null) {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
                    }
                } else {
                    if ((ac.getCriteriaEntries() == null) || ac.getCriteriaEntries().isEmpty()) {
                        ac.addCriteria(TransactionFieldMeta.VALUE, value);
                    } else {
                        ac.addOrCriteria(TransactionFieldMeta.VALUE, value);
                    }
                }
            }
            joinCriteria.addAtomic(ac);
            c.addAggregate(joinCriteria);
        }
        // add the orderBy
        for (Map.Entry<String, Boolean> entry : orderBy.entrySet()) {
            int sort = Criteria.ORDER_BY_ASC;
            if (entry.getValue() != null && !entry.getValue()) {
                sort = Criteria.ORDER_BY_DESC;
            }
            c.addOrderBy(entry.getKey(), sort);
        }
        // add the query results to the return list
        for (Object o : uow.query(c)) {
            results.add((Transaction) o);
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
Also used : ArrayList(java.util.ArrayList) 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) Transaction(org.jaffa.transaction.domain.Transaction) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) UOW(org.jaffa.persistence.UOW) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StringCriteriaField(org.jaffa.components.finder.StringCriteriaField)

Example 54 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getDependenciesByDependsOnId.

/**
 * Gets all TransactionDependencies in any state that depend on the Transaction with the input ID.
 *
 * @param transactionId the ID of the Transaction
 * @return all TransactionDependencies in any state that depend on the Transaction with the input ID
 * @throws FrameworkException
 */
@Override
public Collection<TransactionDependency> getDependenciesByDependsOnId(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);
        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 55 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class JaffaTransactionMessageService method getTransactionCountPerStatusByType.

/**
 * Gets the count per status of all open Transaction with the input type
 *
 * @param type the type to filter on
 * @return the count of all open Transaction with the input type
 * @throws FrameworkException
 */
@Override
public TransactionStatusCount getTransactionCountPerStatusByType(String type) throws FrameworkException {
    UOW uow = null;
    TransactionStatusCount result = new TransactionStatusCount();
    try {
        uow = new UOW();
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
        criteria.addCriteria(TransactionMeta.TYPE, type);
        criteria.addGroupBy(TransactionMeta.STATUS, TransactionMeta.STATUS);
        long openCount = 0L, successCount = 0L, errorCount = 0L, holdCount = 0L, inProcessCount = 0L, interruptedCount = 0L;
        for (Object queryResult : uow.query(criteria)) {
            if (!(queryResult instanceof Map)) {
                continue;
            }
            Map row = (Map) queryResult;
            String status = (String) row.get(TransactionMeta.STATUS);
            if (status != null) {
                Transaction.Status enumeratedStatus = Transaction.Status.valueOf(status);
                Number count = (Number) row.get(Criteria.ID_FUNCTION_COUNT);
                switch(enumeratedStatus) {
                    case O:
                        openCount += count.longValue();
                        break;
                    case S:
                        successCount += count.longValue();
                        break;
                    case E:
                        errorCount += count.longValue();
                        break;
                    case H:
                        holdCount += count.longValue();
                        break;
                    case I:
                        inProcessCount += count.longValue();
                        break;
                    case INT:
                        interruptedCount += count.longValue();
                        break;
                }
            }
        }
        result.setOpenCount(openCount);
        result.setSuccessCount(successCount);
        result.setErrorCount(errorCount);
        result.setHoldCount(holdCount);
        result.setInProcessCount(inProcessCount);
        result.setInterruptedCount(interruptedCount);
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return result;
}
Also used : TransactionStatusCount(org.jaffa.transaction.domain.TransactionStatusCount) Transaction(org.jaffa.transaction.domain.Transaction) 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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

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