Search in sources :

Example 16 with AtomicCriteria

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

the class CandidateKeyValidator method createCriteriaToDiscardCurrentObject.

/**
 *  Create a criteria such that the input object is not included in the search for candidate-key violations.
 */
private AtomicCriteria createCriteriaToDiscardCurrentObject(IPersistent targetObject, Map<String, Object> keyValueMap) throws FrameworkException {
    // No need to create a primary-key criteria for an IPersistent instance that has not been saved yet
    if (!targetObject.isDatabaseOccurence())
        return null;
    // Create the criteria
    if (keyValueMap != null && keyValueMap.size() > 0) {
        AtomicCriteria criteriaToDiscardCurrentObject = null;
        for (Map.Entry<String, Object> me : keyValueMap.entrySet()) {
            String key = me.getKey();
            Object value = me.getValue();
            if (value != null) {
                if (criteriaToDiscardCurrentObject == null) {
                    criteriaToDiscardCurrentObject = new AtomicCriteria();
                    criteriaToDiscardCurrentObject.addCriteria(StringHelper.getUpper1(key), Criteria.RELATIONAL_NOT_EQUALS, value);
                } else {
                    criteriaToDiscardCurrentObject.addOrCriteria(StringHelper.getUpper1(key), Criteria.RELATIONAL_NOT_EQUALS, value);
                }
                if (log.isDebugEnabled())
                    log.debug("Added to primary-key exclusion criteria: " + key + '=' + value);
            } else {
                // Do not create the criteria if any part of the key is null
                if (log.isDebugEnabled())
                    log.debug("The Key field " + key + " is null. The logic to discount the current object cannot be performed");
                criteriaToDiscardCurrentObject = null;
                break;
            }
        }
        return criteriaToDiscardCurrentObject;
    } else {
        return null;
    }
}
Also used : AtomicCriteria(org.jaffa.persistence.AtomicCriteria)

Example 17 with AtomicCriteria

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

the class TaskFinderTx method findLastError.

/**
 * Finds the last error for the input Task.
 * @param uow the UOW.
 * @param taskId the identifier for a Task.
 * @throws FrameworkException in case any internal error occurs.
 * @throws ApplicationExceptions Indicates application error(s).
 */
private String findLastError(UOW uow, String taskId) throws FrameworkException, ApplicationExceptions {
    // select message_text from j_business_event_logs where scheduled_task_id='{taskId}'
    // and (message_type='ERROR' or message_type='FATAL' order by logged_on desc
    Criteria c = new Criteria();
    c.setTable(BusinessEventLogMeta.getName());
    c.addCriteria(BusinessEventLogMeta.SCHEDULED_TASK_ID, taskId);
    AtomicCriteria ac = new AtomicCriteria();
    ac.addCriteria(BusinessEventLogMeta.MESSAGE_TYPE, Level.ERROR.toString());
    ac.addOrCriteria(BusinessEventLogMeta.MESSAGE_TYPE, Level.FATAL.toString());
    c.addAtomic(ac);
    c.addOrderBy(BusinessEventLogMeta.LOGGED_ON, Criteria.ORDER_BY_DESC);
    Iterator i = uow.query(c).iterator();
    if (i.hasNext())
        return ((BusinessEventLog) i.next()).getMessageText();
    else
        return null;
}
Also used : Iterator(java.util.Iterator) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria)

Example 18 with AtomicCriteria

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

the class JaffaTransactionMessageService method filterSetOfTxIdsToOpenOrInProgress.

/**
 * Takes the input list of Transaction IDs and filters it down to the Transactions that are either in
 * the Open or InProgress state.  The filtered list is returned.
 *
 * @param transactionIds the list of all Transaction IDs to check the status of
 * @return Transaction IDs of the input list that are in the Open or InProgress state
 * @throws FrameworkException
 */
@Override
public List<String> filterSetOfTxIdsToOpenOrInProgress(List<String> transactionIds) throws FrameworkException {
    UOW uow = null;
    List<String> results = new ArrayList<String>();
    try {
        uow = new UOW();
        AtomicCriteria ac = new AtomicCriteria();
        for (String transactionId : transactionIds) {
            ac.addOrCriteria(TransactionMeta.ID, transactionId);
        }
        AtomicCriteria ac1 = new AtomicCriteria();
        ac1.addCriteria(TransactionMeta.STATUS, Transaction.Status.O.toString());
        ac1.addOrCriteria(TransactionMeta.STATUS, Transaction.Status.I.toString());
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        criteria.addAtomic(ac);
        criteria.addAtomic(ac1);
        for (Object result : uow.query(criteria)) {
            if (!(result instanceof Transaction)) {
                continue;
            }
            results.add(((Transaction) result).getId());
        }
    } finally {
        if (uow != null) {
            uow.close();
        }
    }
    return results;
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) 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) UOW(org.jaffa.persistence.UOW)

Example 19 with AtomicCriteria

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

the class JaffaTransactionMessageService method getCountSatisfiedOrInError.

/**
 * Gets the count of all Transactions with the specified field-value and type that are in the Satisfied or
 * Error 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
 * @return count of all Transactions with the specified field-value that are in the Open or InProgress state
 * @throws FrameworkException
 */
@Override
public long getCountSatisfiedOrInError(String field, String value, String type) throws FrameworkException {
    UOW uow = null;
    long transactionCount = 0;
    try {
        uow = new UOW();
        Criteria c1 = new Criteria();
        c1.setTable(TransactionFieldMeta.getName());
        c1.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
        c1.addCriteria(TransactionFieldMeta.FIELD_NAME, field);
        c1.addCriteria(TransactionFieldMeta.VALUE, value);
        Criteria c = new Criteria();
        c.setTable(TransactionMeta.getName());
        c.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
        c.addCriteria(TransactionMeta.TYPE, type);
        AtomicCriteria statusCriteria = new AtomicCriteria();
        statusCriteria.addCriteria(TransactionMeta.STATUS, Criteria.RELATIONAL_EQUALS, Transaction.Status.S.toString());
        statusCriteria.addOrCriteria(TransactionMeta.STATUS, Criteria.RELATIONAL_EQUALS, Transaction.Status.E.toString());
        c.addAtomic(statusCriteria);
        // 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);
            if (count != null) {
                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 20 with AtomicCriteria

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

the class JaffaTransactionMessageService method getOpenInProgressLastChangedBefore.

/**
 * Gets all Transactions in the open or InProgress state that were last changed before the input time.
 *
 * @param input the time to compare Open and InProgress Transactions lastChangedTime to
 * @return all Transactions in the open or InProgress state that were last changed before the input time
 * @throws FrameworkException
 */
@Override
public Collection<Transaction> getOpenInProgressLastChangedBefore(DateTime input) throws FrameworkException {
    UOW uow = null;
    Collection<Transaction> results = new ArrayList<Transaction>();
    try {
        uow = new UOW();
        // get all transactions in the "O" or "I" state that are older than the configured age limit
        Criteria criteria = new Criteria();
        criteria.setTable(TransactionMeta.getName());
        // status can equal "O" or "I"
        AtomicCriteria statusCriteria = new AtomicCriteria();
        statusCriteria.addCriteria(TransactionMeta.STATUS, Criteria.RELATIONAL_EQUALS, Transaction.Status.O.toString());
        statusCriteria.addOrCriteria(TransactionMeta.STATUS, Criteria.RELATIONAL_EQUALS, Transaction.Status.I.toString());
        // last changed on should be older than (less than) the retryTime
        AtomicCriteria ageCriteria = new AtomicCriteria();
        ageCriteria.addCriteria(TransactionMeta.LAST_CHANGED_ON, Criteria.RELATIONAL_SMALLER_THAN, input);
        // add the two criteria to one query
        criteria.addAtomic(statusCriteria);
        criteria.addAtomic(ageCriteria);
        Collection transactions = uow.query(criteria);
        // create a list of transactions from the results
        for (Object result : transactions) {
            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) Collection(java.util.Collection) 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

AtomicCriteria (org.jaffa.persistence.AtomicCriteria)20 Criteria (org.jaffa.persistence.Criteria)14 UOW (org.jaffa.persistence.UOW)10 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)10 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)10 Transaction (org.jaffa.transaction.domain.Transaction)6 ArrayList (java.util.ArrayList)5 Iterator (java.util.Iterator)4 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 DateTime (org.jaffa.datatypes.DateTime)2 JaffaRulesFrameworkException (org.jaffa.rules.JaffaRulesFrameworkException)2 Serializable (java.io.Serializable)1 Collection (java.util.Collection)1 StringCriteriaField (org.jaffa.components.finder.StringCriteriaField)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)1