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