use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class UserContextWrapper method readUserRoles.
/**
* Read the roles for the user from the database
*
* @param userId the user id.
* @return the roles for the user.
* @throws FrameworkException if any internal error occurs.
*/
protected String[] readUserRoles(String userId) throws FrameworkException {
UOW uow = null;
List<String> roleList = new ArrayList<String>();
try {
uow = new UOW();
Criteria c = new Criteria();
c.setTable(UserRoleMeta.getName());
c.addCriteria(UserRoleMeta.USER_NAME, userId);
Collection roles = uow.query(c);
for (Iterator it = roles.iterator(); it.hasNext(); ) {
UserRole role = (UserRole) it.next();
roleList.add(role.getRoleName());
}
} catch (UOWException e) {
// Log the error
log.error("Can't Get The Roles for User - " + userId, e);
} finally {
// Attempt to rollback any open transaction
try {
if (uow != null) {
uow.rollback();
}
} catch (UOWException e) {
log.error("Rollback", e);
}
}
return (String[]) roleList.toArray(new String[0]);
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getTransactionPayloadByTransactionId.
/**
* Gets the TransactionPayload of the Transaction with the input ID.
*
* @param transactionId the ID of the Transaction to return the TransactionPayload of
* @return the TransactionPayload of the Transaction with the input ID
* @throws FrameworkException
*/
@Override
public TransactionPayload getTransactionPayloadByTransactionId(String transactionId) throws FrameworkException {
UOW uow = null;
TransactionPayload result = null;
try {
uow = new UOW();
Criteria criteria = new Criteria();
criteria.setTable(TransactionPayloadMeta.getName());
criteria.addCriteria(TransactionPayloadMeta.ID, transactionId);
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
result = (TransactionPayload) itr.next();
}
} finally {
if (uow != null) {
uow.close();
}
}
return result;
}
use of org.jaffa.persistence.UOW 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.persistence.UOW in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method getTransactionField.
/**
* Gets the TransactionField with the input Transaction ID and field name.
*
* @param transactionId the ID of the Transaction the TransactionField is part of
* @param fieldName the field name of the TransactionField to return
* @return the TransactionField with the input Transaction ID and field name
* @throws FrameworkException
*/
@Override
public TransactionField getTransactionField(String transactionId, String fieldName) throws FrameworkException {
UOW uow = null;
TransactionField field = null;
try {
uow = new UOW();
Criteria criteria = new Criteria();
criteria.setTable(TransactionFieldMeta.getName());
criteria.addCriteria(TransactionFieldMeta.TRANSACTION_ID, transactionId);
criteria.addCriteria(TransactionFieldMeta.FIELD_NAME, fieldName);
for (Object result : uow.query(criteria)) {
if (result instanceof TransactionField) {
field = (TransactionField) result;
break;
}
}
} finally {
if (uow != null) {
uow.close();
}
}
return field;
}
use of org.jaffa.persistence.UOW 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;
}
Aggregations