Search in sources :

Example 1 with Filter

use of org.jaffa.transaction.services.configdomain.Filter 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)

Aggregations

Collection (java.util.Collection)1 ApplicationException (org.jaffa.exceptions.ApplicationException)1 FrameworkException (org.jaffa.exceptions.FrameworkException)1 TransactionMessageDAO (org.jaffa.transaction.daos.TransactionMessageDAO)1 TransactionMessageService (org.jaffa.transaction.daos.TransactionMessageService)1 Transaction (org.jaffa.transaction.domain.Transaction)1 Filter (org.jaffa.transaction.services.configdomain.Filter)1 Param (org.jaffa.transaction.services.configdomain.Param)1