use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getOpenOutboundByTypeOrderByCreatedOnDesc.
/**
* Gets a list of all open inbound Transactions of the input type, ordered descending by the createdOn parameter.
*
* @param type the type of Transactions to return
* @return all open inbound Transactions of the input type, ordered by the createdOn parameter
* @throws FrameworkException
*/
@Override
public List<Transaction> getOpenOutboundByTypeOrderByCreatedOnDesc(String type) throws FrameworkException {
UOW uow = null;
List<Transaction> transactions = new ArrayList<Transaction>();
try {
uow = new UOW();
Criteria criteria = new Criteria();
criteria.setTable(TransactionMeta.getName());
criteria.addCriteria(TransactionMeta.DIRECTION, Transaction.Direction.OUT.toString());
criteria.addCriteria(TransactionMeta.TYPE, type);
criteria.addCriteria(TransactionMeta.STATUS, Transaction.Status.O.toString());
criteria.addOrderBy(TransactionMeta.CREATED_ON);
for (Object result : uow.query(criteria)) {
if (!(result instanceof Transaction)) {
continue;
}
transactions.add((Transaction) result);
}
} finally {
if (uow != null) {
uow.close();
}
}
return transactions;
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getCountOpenInProgress.
/**
* Gets the count of all Transactions with the specified field-value 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
* @return the count of all Transactions with the specified field-value that are in the Open or InProgress state
* @throws FrameworkException
*/
@Override
public long getCountOpenInProgress(String field, String value) throws FrameworkException {
UOW uow = null;
long transactionCount = 0;
try {
uow = new UOW();
Criteria criteria = new Criteria();
criteria.setTable(TransactionMeta.getName());
AtomicCriteria ac0 = new AtomicCriteria();
ac0.addCriteria(TransactionMeta.STATUS, Transaction.Status.O.toString());
ac0.addOrCriteria(TransactionMeta.STATUS, Transaction.Status.I.toString());
criteria.addAtomic(ac0);
Criteria transactionFieldCriteria = new Criteria();
transactionFieldCriteria.setTable(TransactionFieldMeta.getName());
transactionFieldCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
criteria.addAggregate(transactionFieldCriteria);
AtomicCriteria ac = new AtomicCriteria();
ac.addCriteria(TransactionFieldMeta.FIELD_NAME, field);
ac.addCriteria(TransactionFieldMeta.VALUE, value);
transactionFieldCriteria.addAtomic(ac);
// return the count, or zero
for (Object result : uow.query(criteria)) {
if (!(result instanceof Transaction)) {
continue;
}
transactionCount++;
}
} finally {
if (uow != null) {
uow.close();
}
}
return transactionCount;
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getTransactionsByFieldsOred.
/**
* Gets all Transactions that have any of the specified fields with the input values.
* If there are more than one value for a key, this will return fields that have any of the specified values.
*
* @param fields the field name/value pairs that a Transaction must have at least one of to ne returned
* @return a collection of Transactions that contain the specified fields with the input values
* @throws FrameworkException
*/
@Override
public Collection<Transaction> getTransactionsByFieldsOred(HashMap<String, Serializable> fields) throws FrameworkException {
UOW uow = null;
List<Transaction> results = new ArrayList<Transaction>();
try {
uow = new UOW();
Criteria transactionCriteria = new Criteria();
transactionCriteria.setTable(TransactionMeta.getName());
Criteria transactionFieldCriteria = new Criteria();
transactionFieldCriteria.setTable(TransactionFieldMeta.getName());
transactionFieldCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
transactionCriteria.addAggregate(transactionFieldCriteria);
AtomicCriteria ac = new AtomicCriteria();
// add each field in the field map to the query
AtomicCriteria firstCriteria = null;
for (Map.Entry<String, Serializable> field : fields.entrySet()) {
// if there is no field defined, skip to the next entry
if ((field.getKey() == null) || field.getKey().isEmpty()) {
continue;
}
AtomicCriteria ac1 = new AtomicCriteria();
ac1.addCriteria(TransactionFieldMeta.FIELD_NAME, field.getKey());
if (field.getValue() == null) {
ac1.addCriteria(TransactionFieldMeta.VALUE, Criteria.RELATIONAL_IS_NULL);
} else {
ac1.addCriteria(TransactionFieldMeta.VALUE, field.getValue());
}
if (firstCriteria != null) {
firstCriteria.addOrAtomic(ac1);
} else {
firstCriteria = ac1;
ac.addAtomic(firstCriteria);
}
}
transactionFieldCriteria.addAtomic(ac);
for (Object result : uow.query(transactionCriteria)) {
if (!(result instanceof Transaction)) {
continue;
}
results.add((Transaction) result);
}
} finally {
if (uow != null) {
uow.close();
}
}
return results;
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getInboundByTypeSubTypeAndFields.
/**
* Gets all inbound Transactions that have the specified type, subType and fields with the input values.
* If there are more than one value for a key, this will return fields that have any of the specified values.
*
* @param type the type of Transactions to return
* @param subType the subType of Transactions to return
* @param fields the field name/value pairs
* @return a collection of inbound Transactions of the input type and subType that contain the specified
* fields with the input values
* @throws FrameworkException
*/
@Override
public Collection<Transaction> getInboundByTypeSubTypeAndFields(String type, String subType, HashMap<String, String> fields) throws FrameworkException {
UOW uow = null;
Collection<Transaction> transactions = new ArrayList<Transaction>();
try {
uow = new UOW();
Criteria transactionCriteria = new Criteria();
// query for inbound Transaction with the input type and subType
transactionCriteria.setTable(TransactionMeta.getName());
transactionCriteria.addCriteria(TransactionMeta.TYPE, type);
transactionCriteria.addCriteria(TransactionMeta.SUB_TYPE, subType);
transactionCriteria.addCriteria(TransactionMeta.DIRECTION, Transaction.Direction.IN.name());
// add each field in the field map to the query
for (Map.Entry<String, String> field : fields.entrySet()) {
if ((field.getKey() == null) || field.getKey().isEmpty()) {
continue;
}
Criteria fieldCriteria = new Criteria();
fieldCriteria.setTable(TransactionFieldMeta.getName());
fieldCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
fieldCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, field.getKey());
fieldCriteria.addCriteria(TransactionFieldMeta.VALUE, field.getValue());
transactionCriteria.addAggregate(fieldCriteria);
}
for (Object result : uow.query(transactionCriteria)) {
if (!(result instanceof Transaction)) {
continue;
}
transactions.add((Transaction) result);
}
} finally {
if (uow != null) {
uow.close();
}
}
return transactions;
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class TransactionDependency method findTransactionObject.
/**
* Finds the related foreign Transaction object.
* If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
*/
private void findTransactionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
// TODO this is generated code...
if (m_transactionObject == null && getTransactionId() != null) {
Transaction transaction = getTransactionDAO().getTransaction(getTransactionId());
Number count = null;
if (checkExistenceOnly) {
if (transaction != null) {
count = 1;
}
} else {
m_transactionObject = transaction;
}
if ((m_transactionObject == null) && ((count == null) || (count.intValue() <= 0))) {
throw new InvalidForeignKeyException(TransactionDependencyMeta.META_TRANSACTION_ID.getLabelToken(), new Object[] { TransactionMeta.getLabelToken(), TransactionMeta.META_ID.getLabelToken() });
}
}
}
Aggregations