Search in sources :

Example 1 with TransactionMessageDAO

use of org.jaffa.transaction.daos.TransactionMessageDAO in project jaffa-framework by jaffa-projects.

the class TransactionDependency method postUpdate.

@Override
public void postUpdate() throws PostUpdateFailedException {
    super.postUpdate();
    // then UPDATE TRANSACTIONS SET STATUS='O' WHERE ID={thisTransactionDependency.transactionId} and STATUS='H'
    if (isModified(TransactionDependencyMeta.STATUS) && Status.S.toString().equals(getStatus())) {
        try {
            if (log.isDebugEnabled()) {
                log.debug("TransactionDependency status has changed to S. 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 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 PostUpdateFailedException(new String[] { s }, e);
        }
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Transaction(org.jaffa.transaction.domain.Transaction) TransactionMessageDAO(org.jaffa.transaction.daos.TransactionMessageDAO) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) DuplicateKeyException(org.jaffa.exceptions.DuplicateKeyException) FrameworkException(org.jaffa.exceptions.FrameworkException) RelatedDomainObjectFoundException(org.jaffa.exceptions.RelatedDomainObjectFoundException)

Example 2 with TransactionMessageDAO

use of org.jaffa.transaction.daos.TransactionMessageDAO in project jaffa-framework by jaffa-projects.

the class TransactionEngine method createTransactionDependency.

public void createTransactionDependency(UOW uow, Transaction transaction, String dependsOnId) throws ApplicationException, ApplicationExceptions, FrameworkException {
    TransactionDependency transactionDependency = null;
    if (transaction != null && dependsOnId != null) {
        transactionDependency = new TransactionDependency();
        transactionDependency.setTransactionId(transaction.getId());
        transactionDependency.setDependsOnId(dependsOnId);
        transactionDependency.setStatus(Transaction.Status.O.toString());
        TransactionMessageDAO transactionDAO = getTransactionDAO();
        transactionDAO.save(uow, transactionDependency);
        // Set the transaction to hold status. This will get fulfilled once the transaction dependency is satisfied
        transaction.setStatus(Transaction.Status.H.toString());
        transactionDAO.save(uow, transaction);
    }
    if (log.isDebugEnabled()) {
        log.debug("Created TransactionDependency " + transactionDependency);
    }
}
Also used : TransactionMessageDAO(org.jaffa.transaction.daos.TransactionMessageDAO) TransactionDependency(org.jaffa.transaction.domain.TransactionDependency)

Example 3 with TransactionMessageDAO

use of org.jaffa.transaction.daos.TransactionMessageDAO 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);
        }
    }
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Transaction(org.jaffa.transaction.domain.Transaction) TransactionMessageDAO(org.jaffa.transaction.daos.TransactionMessageDAO) InvalidForeignKeyException(org.jaffa.datatypes.exceptions.InvalidForeignKeyException) DuplicateKeyException(org.jaffa.exceptions.DuplicateKeyException) FrameworkException(org.jaffa.exceptions.FrameworkException) RelatedDomainObjectFoundException(org.jaffa.exceptions.RelatedDomainObjectFoundException)

Example 4 with TransactionMessageDAO

use of org.jaffa.transaction.daos.TransactionMessageDAO 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);
            }
        }
    }
}
Also used : Transaction(org.jaffa.transaction.domain.Transaction) Filter(org.jaffa.transaction.services.configdomain.Filter) TransactionMessageDAO(org.jaffa.transaction.daos.TransactionMessageDAO) Param(org.jaffa.transaction.services.configdomain.Param) Collection(java.util.Collection) TransactionMessageService(org.jaffa.transaction.daos.TransactionMessageService) FrameworkException(org.jaffa.exceptions.FrameworkException) ApplicationException(org.jaffa.exceptions.ApplicationException)

Example 5 with TransactionMessageDAO

use of org.jaffa.transaction.daos.TransactionMessageDAO 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"));
                }
            }
        }
    }
}
Also used : ApplicationException(org.jaffa.exceptions.ApplicationException) ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) Transaction(org.jaffa.transaction.domain.Transaction) TransactionMessageDAO(org.jaffa.transaction.daos.TransactionMessageDAO)

Aggregations

TransactionMessageDAO (org.jaffa.transaction.daos.TransactionMessageDAO)5 Transaction (org.jaffa.transaction.domain.Transaction)4 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)3 FrameworkException (org.jaffa.exceptions.FrameworkException)3 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)2 ApplicationException (org.jaffa.exceptions.ApplicationException)2 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)2 RelatedDomainObjectFoundException (org.jaffa.exceptions.RelatedDomainObjectFoundException)2 Collection (java.util.Collection)1 TransactionMessageService (org.jaffa.transaction.daos.TransactionMessageService)1 TransactionDependency (org.jaffa.transaction.domain.TransactionDependency)1 Filter (org.jaffa.transaction.services.configdomain.Filter)1 Param (org.jaffa.transaction.services.configdomain.Param)1