Search in sources :

Example 71 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class TransactionEngine method updateTransactionStatusToInProcess.

/**
 * Updates the input transaction's status to I.
 * NOTE: The processing happens within the scope of a local new UOW.
 *
 * @param transaction the Transaction to update.
 * @throws FrameworkException    Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
public void updateTransactionStatusToInProcess(Transaction transaction) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        uow = new UOW();
        transaction.setUOW(uow);
        updateTransactionStatusToInProcess(uow, transaction);
        uow.commit();
    } catch (Exception e) {
        throw ExceptionHelper.throwAFR(e);
    } finally {
        if (uow != null) {
            uow.rollback();
        }
    }
}
Also used : UOW(org.jaffa.persistence.UOW) DomainObjectChangedException(org.jaffa.exceptions.DomainObjectChangedException) FrameworkException(org.jaffa.exceptions.FrameworkException) MessagingException(javax.mail.MessagingException) ApplicationException(org.jaffa.exceptions.ApplicationException) DomainObjectNotFoundException(org.jaffa.exceptions.DomainObjectNotFoundException)

Example 72 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class LockingService method checkLock.

/**
 * Browses all Transactions looking for the locks, as specified in the transaction-configuration for the input dataBean.
 * Creates a new UOW to perform the lock check.
 * Throws an ApplicationException, if any matching Transaction is found.
 *
 * @param dataBean Any serializable object.
 * @throws FrameworkException    Indicates some system error.
 * @throws ApplicationExceptions Indicates application error(s).
 */
public static void checkLock(Object dataBean) throws FrameworkException, ApplicationExceptions {
    UOW uow = null;
    try {
        uow = new UOW();
        checkLock(uow, dataBean);
    } finally {
        if (uow != null) {
            try {
                uow.rollback();
            } catch (Exception e) {
                // UOW unable to be rolledback
                log.error("UOW unable to be rolled back");
            }
        }
    }
}
Also used : UOW(org.jaffa.persistence.UOW) FrameworkException(org.jaffa.exceptions.FrameworkException) ApplicationException(org.jaffa.exceptions.ApplicationException)

Example 73 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method resubmitMessage.

/**
 * NOTE: Each graph is expected to contain messageId. It may also contain the optional queueMetaData.queueSystemId and type, which may help optimize the process.
 */
public MessageAdminResponse[] resubmitMessage(MessageGraph[] graphs) {
    if (log.isDebugEnabled()) {
        log.debug("Input to resubmitMessage: " + Arrays.toString(graphs));
    }
    Collection<MessageAdminResponse> output = null;
    String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
    Arrays.sort(types);
    for (MessageGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            if (graph.getType() == null || (types != null && Arrays.binarySearch(types, graph.getType()) >= 0)) {
                UOW uow = null;
                try {
                    String graphType = graph.getType();
                    String messageId = graph.getMessageId();
                    if (graphType != null && !TransactionEngine.getInstance().hasAdminAccess(graphType)) {
                        throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graphType }));
                    }
                    uow = new UOW();
                    Transaction transaction = transactionDAO.getTransaction(messageId);
                    if (transaction != null) {
                        if (!TransactionEngine.getInstance().hasAdminAccess(transaction.getType())) {
                            throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { transaction.getType() }));
                        }
                        if (Transaction.Status.E.toString().equals(transaction.getStatus())) {
                            if (log.isDebugEnabled()) {
                                log.debug("Resubmitting ERROR message " + messageId);
                            }
                            transaction.setStatus(Transaction.Status.O.toString());
                            transaction.setErrorMessage(null);
                            transactionDAO.save(uow, transaction);
                            if (null != transactionWorkDAO) {
                                boolean isSingletonType = ConfigurationService.getInstance().isTypeSingleton(transaction.getType());
                                if (isSingletonType) {
                                    transactionWorkDAO.addToSingletonQueue(transaction.getType(), transaction.getId());
                                } else {
                                    transactionWorkDAO.addToReadyQueue(transaction.getId());
                                }
                            }
                            uow.commit();
                        } else {
                            if (log.isDebugEnabled()) {
                                log.debug("Resubmission cannot be performed since message " + messageId + " is not in ERROR status anymore");
                            }
                        }
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("Resubmission cannot be performed since message " + messageId + " not found");
                        }
                    }
                } catch (Exception e) {
                    MessageAdminResponse response = new MessageAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Error while resubmitting Message " + graph, appExps);
                        }
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while resubmitting Message " + graph, e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null) {
                        output = new LinkedList<MessageAdminResponse>();
                    }
                    output.add(response);
                } finally {
                    if (uow != null) {
                        try {
                            uow.rollback();
                        } catch (Exception ignore) {
                        }
                    }
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Message " + graph + " will not be resubmitted by this implementation, since the queue does not belong to this implementation");
                }
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Message " + graph + " will not be resubmitted by this implementation, since the input queueSystemId does not match this system");
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Output from resubmitMessage: " + output);
    }
    return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) MessageAdminResponse(org.jaffa.qm.apis.data.MessageAdminResponse) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) LinkedList(java.util.LinkedList) ApplicationException(org.jaffa.exceptions.ApplicationException) Transaction(org.jaffa.transaction.domain.Transaction) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) UOW(org.jaffa.persistence.UOW)

Example 74 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method invokeHandler.

/**
 * Invokes the intended handler. This Handler must implement the IMessageHandler Interface in order to be invoked.
 *
 * @param uow
 * @param transaction
 * @param methodName
 * @throws JaffaMessagingFrameworkException
 */
private static void invokeHandler(UOW uow, Transaction transaction, String methodName) throws Exception {
    try {
        TransactionPayload tp = transaction.getTransactionPayloadObject();
        Object dataBean = tp != null ? tp.moldInternalPayload() : null;
        if (dataBean != null) {
            // Load transaction configuration
            TransactionInfo transactionInfo = ConfigurationService.getInstance().getTransactionInfo(tp.getInternalMessageClass());
            if (transactionInfo == null) {
                throw new JaffaMessagingFrameworkException(JaffaTransactionFrameworkException.TRANSACTION_INFO_MISSING, new Object[] { tp.getInternalMessageClass() });
            }
            // Obtain the handlerClass
            if (transactionInfo.getToClass() == null || transactionInfo.getToClass().length() == 0) {
                if (log.isDebugEnabled()) {
                    log.debug(methodName + " toClass is not defined in data bean configuration: " + transactionInfo.getDataBean());
                }
                return;
            }
            Class handlerClass = Class.forName(transactionInfo.getToClass());
            // Class dataBeanClass = Class.forName(transactionInfo.getDataBean());
            if (IMessageHandler.class.isAssignableFrom(handlerClass)) {
                // Unmarshals the Message payload into a dataBean using the dataBeanClassName
                Method handlerMethod = null;
                Object handlerObject = null;
                // Obtain the handler method
                try {
                    handlerMethod = handlerClass.getMethod(methodName, new Class[] { UOW.class, Map.class, Object.class });
                } catch (NoSuchMethodException e) {
                    // Hence use the dataBeanClass specified in the messageInfo to get the appropriate handlerMethod
                    if (log.isDebugEnabled()) {
                        log.debug(methodName + " method not found in " + handlerClass.getName());
                    }
                    return;
                }
                handlerObject = handlerClass.newInstance();
                Map<String, String> headerMap = new HashMap<String, String>();
                // Sets the transactionField elements as defined in the configuration file.
                TransactionField[] fields = transaction.getTransactionFieldArray();
                if (fields != null) {
                    for (TransactionField field : fields) {
                        headerMap.put(field.getFieldName(), field.getValue());
                    }
                }
                // Invoke the handler
                if (log.isDebugEnabled()) {
                    log.debug("Invoking the handler " + handlerMethod);
                }
                handlerMethod.invoke(handlerObject, new Object[] { uow, headerMap, dataBean });
            }
        }
    } catch (Exception e) {
        // Just log the error
        log.error("Exception thrown while deleting the transaction. Transaction was: " + transaction, e);
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) TransactionField(org.jaffa.transaction.domain.TransactionField) Method(java.lang.reflect.Method) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) TransactionInfo(org.jaffa.transaction.services.configdomain.TransactionInfo) TransactionPayload(org.jaffa.transaction.domain.TransactionPayload) UOW(org.jaffa.persistence.UOW) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 75 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class TransactionAdmin method deleteMessage.

// ///////////////////////////////// Add in intercept for delete
/**
 * NOTE: Each graph is expected to contain messageId. It may also contain the optional queueMetaData.queueSystemId and type, which may help optimize the process.
 */
public MessageAdminResponse[] deleteMessage(MessageGraph[] graphs) {
    if (log.isDebugEnabled()) {
        log.debug("Input to deleteMessage: " + Arrays.toString(graphs));
    }
    Collection<MessageAdminResponse> output = null;
    String[] types = TransactionEngine.getInstance().getAccessibleTypeNames();
    Arrays.sort(types);
    for (MessageGraph graph : graphs) {
        if (graph.getQueueMetaData() == null || graph.getQueueMetaData().getQueueSystemId() == null || graph.getQueueMetaData().getQueueSystemId().equals(QUEUE_SYSTEM_ID)) {
            if (graph.getType() == null || (types != null && Arrays.binarySearch(types, graph.getType()) >= 0)) {
                UOW uow = null;
                try {
                    String graphType = graph.getType();
                    String messageId = graph.getMessageId();
                    if (graphType != null && !TransactionEngine.getInstance().hasAdminAccess(graphType)) {
                        throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { graphType }));
                    }
                    uow = new UOW();
                    Transaction transaction = transactionDAO.getTransaction(messageId);
                    if (transaction != null) {
                        String transactionType = transaction.getType();
                        if (!TransactionEngine.getInstance().hasAdminAccess(transactionType)) {
                            throw new ApplicationExceptions(new ApplicationException("error.Jaffa.Transaction.Transaction.noAdminAccess", new Object[] { transactionType }));
                        }
                        // Invoke Message Handler class to perform onDelete process
                        invokeHandler(uow, transaction, "onDelete");
                        if (log.isDebugEnabled()) {
                            log.debug("Deleting message " + messageId);
                        }
                        transactionDAO.delete(uow, transaction);
                        uow.commit();
                    } else {
                        if (log.isDebugEnabled()) {
                            log.debug("Delete cannot be performed since message " + messageId + " not found");
                        }
                    }
                } catch (Exception e) {
                    MessageAdminResponse response = new MessageAdminResponse();
                    response.setSource(graph);
                    ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
                    if (appExps != null) {
                        if (log.isDebugEnabled()) {
                            log.debug("Error while deleting Message " + graph, appExps);
                        }
                        response.setErrors(ServiceError.generate(appExps));
                    } else {
                        log.error("Internal Error while deleting Message " + graph, e);
                        response.setErrors(ServiceError.generate(e));
                    }
                    if (output == null) {
                        output = new LinkedList<MessageAdminResponse>();
                    }
                    output.add(response);
                } finally {
                    if (uow != null) {
                        try {
                            uow.rollback();
                        } catch (Exception ignore) {
                        }
                    }
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Message " + graph + " will not be deleted by this implementation, since the queue does not belong to this implementation");
                }
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Message " + graph + " will not be deleted by this implementation, since the input queueSystemId does not match this system");
            }
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Output from deleteMessage: " + output);
    }
    return output != null && output.size() > 0 ? output.toArray(new MessageAdminResponse[output.size()]) : null;
}
Also used : ApplicationExceptions(org.jaffa.exceptions.ApplicationExceptions) ApplicationException(org.jaffa.exceptions.ApplicationException) Transaction(org.jaffa.transaction.domain.Transaction) MessageAdminResponse(org.jaffa.qm.apis.data.MessageAdminResponse) MessageGraph(org.jaffa.qm.apis.data.MessageGraph) UOW(org.jaffa.persistence.UOW) IllegalPersistentStateRuntimeException(org.jaffa.persistence.exceptions.IllegalPersistentStateRuntimeException) JaffaMessagingFrameworkException(org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException) PostLoadFailedException(org.jaffa.persistence.exceptions.PostLoadFailedException) FrameworkException(org.jaffa.exceptions.FrameworkException) QueryFailedException(org.jaffa.persistence.exceptions.QueryFailedException) ApplicationException(org.jaffa.exceptions.ApplicationException) LinkedList(java.util.LinkedList)

Aggregations

UOW (org.jaffa.persistence.UOW)260 Criteria (org.jaffa.persistence.Criteria)139 FrameworkException (org.jaffa.exceptions.FrameworkException)99 ApplicationException (org.jaffa.exceptions.ApplicationException)88 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)87 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)82 Iterator (java.util.Iterator)47 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)33 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)33 ArrayList (java.util.ArrayList)19 Transaction (org.jaffa.transaction.domain.Transaction)19 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)13 HashMap (java.util.HashMap)12 DateTime (org.jaffa.datatypes.DateTime)11 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)10 IPersistent (org.jaffa.persistence.IPersistent)10 Method (java.lang.reflect.Method)9 Collection (java.util.Collection)8 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)8