use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class JaffaTransactionMessageService method findByFieldValueOrderByCreatedOnDesc.
/**
* Gets all Transactions with the input field-value and returns them ordered descending by the createdOn parameter.
*
* @param field the field to check the value of
* @param value the input value of the field we are looking for
* @return all Transactions with the input field-value and returns them ordered by the createdOn parameter
* @throws FrameworkException
*/
@Override
public List<Transaction> findByFieldValueOrderByCreatedOnDesc(String field, String value) throws FrameworkException {
UOW uow = null;
List<Transaction> transactions = new ArrayList<Transaction>();
try {
uow = new UOW();
Criteria transactionCriteria = new Criteria();
transactionCriteria.setTable(TransactionMeta.getName());
Criteria joinCriteria = new Criteria();
joinCriteria.setTable(TransactionFieldMeta.getName());
joinCriteria.addInnerCriteria(TransactionFieldMeta.TRANSACTION_ID, TransactionMeta.ID);
joinCriteria.addCriteria(TransactionFieldMeta.FIELD_NAME, field);
joinCriteria.addCriteria(TransactionFieldMeta.VALUE, value);
transactionCriteria.addAggregate(joinCriteria);
transactionCriteria.addOrderBy(TransactionMeta.CREATED_ON);
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 postDelete.
@Override
public void postDelete() throws PostDeleteFailedException {
super.postDelete();
// then UPDATE TRANSACTIONS SET STATUS='O' WHERE ID={thisTransactionDependency.transactionId} and STATUS='H'
if (Status.O.toString().equals(getStatus())) {
try {
if (log.isDebugEnabled()) {
log.debug("An Open TransactionDependency status has been deleted. Will Open parent Transaction if no other Open TransactionDependency record exists");
}
TransactionMessageDAO transactionDAO = getTransactionDAO();
Transaction transaction = transactionDAO.getTransaction(getTransactionId());
if ((transaction != null) && Transaction.Status.H.toString().equals(transaction.getStatus())) {
long count = transactionDAO.getOpenTransactionDependencyCount(transaction.getId());
if (count == 0) {
transaction.setStatus(Transaction.Status.O.toString());
getUOW().update(transaction);
}
}
} catch (Exception e) {
String s = "Exception in opening parent Transaction when the associated dependencies have all been satisfied. This is being done for the deleted TransactionDependency instance " + this;
ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
if (appExps != null) {
if (log.isDebugEnabled())
log.debug(s, appExps);
} else {
log.error(s, e);
}
throw new PostDeleteFailedException(new String[] { s }, e);
}
}
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class TransactionDependency method findDependsOnTransactionObject.
/**
* 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 findDependsOnTransactionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
// TODO this is generated code...
if (m_dependsOnTransactionObject == null && getDependsOnId() != null) {
Transaction transaction = getTransactionDAO().getTransaction(getDependsOnId());
Number count = null;
if (checkExistenceOnly) {
if (transaction != null) {
count = 1;
}
} else {
m_dependsOnTransactionObject = transaction;
}
if ((m_dependsOnTransactionObject == null) && ((count == null) || (count.intValue() <= 0))) {
throw new InvalidForeignKeyException(TransactionDependencyMeta.META_DEPENDS_ON_ID.getLabelToken(), new Object[] { TransactionMeta.getLabelToken(), TransactionMeta.META_ID.getLabelToken() });
}
}
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class LockingService method checkOrDeleteLockingTransactions.
/**
* Browses all Transactions looking for the locks, as specified in the transaction-configuration for the input dataBean.
* Calls any specified lock-check filter class if one has been defined
* Throws an ApplicationException, if any matching Transaction is found, and if the input argument 'deleteLockingTransaction' is false.
* Deletes all matching Transactions, if the input argument 'deleteLockingTransaction' is true.
*
* @param uow The UOW.
* @param dataBean Any serializable object.
* @param transactionInfo the corresponding TransactionInfo object, as specified in the configuration file.
* @param deleteLockingTransaction determines if the matching Transactions are to be deleted.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
private static void checkOrDeleteLockingTransactions(UOW uow, Object dataBean, TransactionInfo transactionInfo, boolean deleteLockingTransaction, String transactionId) throws FrameworkException, ApplicationExceptions {
// Check if lock checks exists for the message
if (transactionInfo.getLockCheck() != null) {
Filter filterConfig = transactionInfo.getLockCheck().getFilter();
// Load the appropriate class
if (filterConfig != null) {
try {
Class<ILockCheckFilter> filterClass = (Class<ILockCheckFilter>) Class.forName(filterConfig.getClassName());
TransactionMessageService transactionService = TransactionMessageDAOFactory.getTransactionMessageService();
Collection<Transaction> transactions = filterClass.newInstance().getFilteredResults(dataBean, transactionService);
deleteLockCheck(uow, transactions, deleteLockingTransaction, transactionId);
} catch (Exception e) {
throw ExceptionHelper.throwAFR(e);
}
// load the load check parameters directly from the message config
} else if (transactionInfo.getLockCheck().getParam() != null) {
TransactionMessageDAO transactionDAO = TransactionMessageDAOFactory.getTransactionMessageDAO();
// Run this logic for each Param
for (Param param : transactionInfo.getLockCheck().getParam()) {
String value = TransactionEngine.obtainParamValue(param, dataBean);
Collection<Transaction> transactions = transactionDAO.getTransactionsByField(param.getName(), value);
deleteLockCheck(uow, transactions, deleteLockingTransaction, transactionId);
}
}
}
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class LockingService method deleteLockCheck.
/**
* @param uow The UOW.
* @param transactions the transactions the check
* @param deleteLockingTransaction determines if the matching Transactions are to be deleted.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
private static void deleteLockCheck(UOW uow, Collection<Transaction> transactions, boolean deleteLockingTransaction, String transactionId) throws FrameworkException, ApplicationExceptions {
// Now perform the checking based on the flag
if (deleteLockingTransaction) {
TransactionMessageDAO transactionDAO = TransactionMessageDAOFactory.getTransactionMessageDAO();
for (Transaction transaction : transactions) {
if (Transaction.Status.I.toString().equals(transaction.getStatus())) {
// Interrupt an In-Process Transaction
try {
transaction.setStatus(Transaction.Status.INT.toString());
transactionDAO.save(uow, transaction);
} catch (ApplicationException e) {
if (log.isDebugEnabled()) {
log.debug("Exception thrown while Interrupting an In-Process Transaction", e);
}
throw new ApplicationExceptions(e);
}
} else if (!Transaction.Status.INT.toString().equals(transaction.getStatus())) {
// Ignore an Interrupted Transaction
// Delete the Transaction
transactionDAO.delete(uow, transaction);
}
}
} else {
for (Transaction transaction : transactions) {
if (!Transaction.Status.S.toString().equals(transaction.getStatus())) {
// Should throw an exception. This also prevents a message from locking itself out
if ((transactionId == null) || !transaction.getId().equals(transactionId)) {
if (log.isDebugEnabled()) {
log.debug("Found Transaction record(s) that match the lock criteria");
}
throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.lockError"));
}
}
}
}
}
Aggregations