use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class TransactionDependencySweeper method updateTransaction.
/**
* Updated missed Transaction records
* @param tdv
* @param databean
*/
private void updateTransaction(TransactionSweeperView tdv, TransactionDependencySweeper databean) {
UOW innerUow = null;
try {
innerUow = new UOW();
Transaction transaction = Transaction.findByPK(innerUow, tdv.getId());
if (transaction == null) {
log.info("Transaction '" + tdv.getId() + "' not found; cannot update it's status to O");
throw new DomainObjectNotFoundException(TransactionDependencyMeta.getLabelToken());
} else {
transaction.setStatus(Transaction.Status.O.toString());
transactionMessageDAO.save(innerUow, transaction);
innerUow.commit();
}
} catch (Exception e) {
// Write to business event log
MDC.put(BusinessEventLogMeta.SCHEDULED_TASK_ID, databean.getScheduleTaskId());
MDC.put(BusinessEventLogMeta.LOGGED_BY, databean.getLoggedBy());
log.error("Exception thrown during update of Transaction record" + e);
} finally {
if (innerUow != null) {
try {
innerUow.rollback();
} catch (Exception e) {
log.error("Unable to rollback inner UOW in updating Transaction");
}
}
}
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class TransactionEngine method updateTransactionStatusToError.
/**
* Retrieves the Transaction and update it's status to E.
* NOTE: The processing happens within the scope of a local new UOW.
*
* @param id the Transaction Id.
* @param exception the cause for the error.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
public void updateTransactionStatusToError(String id, Exception exception) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
uow = new UOW();
Transaction transaction = getTransaction(uow, id);
if (transaction == null) {
log.error("Transaction '" + id + "' not found; cannot update it's status to E");
throw new DomainObjectNotFoundException(TransactionMeta.getLabelToken());
} else {
if (log.isDebugEnabled()) {
log.debug("Updating Transaction '" + transaction.getId() + "' to status E");
}
transaction.stampError(exception);
getTransactionDAO().save(uow, transaction);
uow.commit();
try {
sendFailureNotification(transaction, exception);
} catch (Exception e) {
log.error("Error in sending transaction failure notification", e);
}
}
} catch (Exception e) {
log.error("Failed to set failed transaction id " + id + " to E", e);
throw ExceptionHelper.throwAFR(e);
} finally {
if (uow != null) {
uow.rollback();
}
}
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class TransactionEngine method updateTransactionStatusToSatisfied.
/**
* Retrieves the Transaction and update it's status to S.
* NOTE: The processing happens within the scope of the input UOW.
*
* @param uow The UOW.
* @param id the Transaction Id.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
public void updateTransactionStatusToSatisfied(UOW uow, String id) throws FrameworkException, ApplicationExceptions {
try {
Transaction transaction = getTransaction(uow, id);
if (transaction == null) {
log.error("Transaction '" + id + "' not found; cannot update it's status to S");
throw new DomainObjectNotFoundException(TransactionMeta.getLabelToken());
} else {
if (log.isDebugEnabled()) {
log.debug("Updating Transaction '" + transaction.getId() + "' to status S");
}
transaction.setStatus(Transaction.Status.S.toString());
getTransactionDAO().save(uow, transaction);
}
} catch (Exception e) {
throw ExceptionHelper.throwAFR(e);
}
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class TransactionEngine method updateTransactionStatusToInProcess.
/**
* Retrieves the Transaction and update it's status to I.
* This method should only be used during a synchronous transaction as the the entire transaction must be scoped within the same UOW
* NOTE: The processing happens within the scope of the input UOW.
*
* @param uow the input UOW.
* @param id the Transaction Id.
* @throws FrameworkException Indicates some system error.
* @throws ApplicationExceptions Indicates application error(s).
*/
public void updateTransactionStatusToInProcess(UOW uow, String id) throws FrameworkException, ApplicationExceptions {
Transaction transaction = getTransaction(uow, id);
updateTransactionStatusToInProcess(uow, transaction);
}
use of org.jaffa.transaction.domain.Transaction in project jaffa-framework by jaffa-projects.
the class TransactionMessagingEngine method processTransactions.
/**
* Any internally queued {@link Transaction} needs a corresponding JMS message submitted.
* Prior versions did this in the postAdd() of the Transaction domain object.
* <p/>
* This location is now one of a few places that should be using the JmsClientHelper.send() method.
* The other place(s) are:
* - In the drl files for sending messages to topic queues (resources/rules/jaffa/soa/SOAEventService.drl)
*/
private void processTransactions() throws FrameworkException, ApplicationExceptions {
log.debug("Need to Write JMS for buffered Transactions. BufferSize=" + m_transactions.size());
// send each transaction to the JmsClientHelper
for (Transaction transaction : m_transactions.values()) {
// if the transaction is not defined, skip it
if (transaction == null) {
continue;
}
// if the direction is not "IN", skip this transaction
if ((transaction.getDirection() != null) && !Direction.IN.toString().equals(transaction.getDirection())) {
log.debug("Transaction: " + transaction.getId() + " is not an IN transaction, it will be skipped.");
continue;
}
// if the status is not "O", skip this transaction
if ((transaction.getStatus() != null) && !Status.O.toString().equals(transaction.getStatus())) {
log.debug("Transaction: " + transaction.getId() + " is not OPEN, it will be skipped.");
continue;
}
// try to submit the transaction
try {
// see if a scheduled ID is defined for this transaction
String scheduledId = null;
TransactionField[] transactionFields = transaction.getTransactionFieldArray();
if (transactionFields != null) {
for (TransactionField field : transaction.getTransactionFieldArray()) {
if ("JaffaTransactionInvokerScheduledTaskId".equals(field.getFieldName())) {
scheduledId = field.getValue();
break;
}
}
}
// send the transaction to the JMS queue to be consumed
getSender().send(new TransactionMessage(transaction), transaction.getCreatedBy(), scheduledId, null);
} catch (Exception e) {
// If there is a failure to put the transaction in the JMS queue, set the transaction to error
Boolean postImmediate = Parser.parseBoolean((String) ContextManagerFactory.instance().getProperty(Transaction.RULE_POST_IMMEDIATE));
if (postImmediate == null || !postImmediate.booleanValue()) {
TransactionEngine.getInstance().updateTransactionStatusToError(transaction.getId(), e);
}
// Handle case where an application exception caused the issue
ApplicationExceptions appExps = ExceptionHelper.extractApplicationExceptions(e);
if (appExps != null) {
log.error(MessageHelper.findMessage("exception.org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException.jmsTransactionError", new Object[] { transaction }), appExps);
TransactionEngine.getInstance().updateTransactionStatusToError(transaction.getId(), appExps);
throw appExps;
}
// If the originating exception is not an application exception log it
log.error(MessageHelper.findMessage("exception.org.jaffa.modules.messaging.services.JaffaMessagingFrameworkException.jmsTransactionError", new Object[] { transaction }), e);
// Create a framework exception and rethrow
FrameworkException frameworkException = new JaffaMessagingFrameworkException(JaffaMessagingFrameworkException.JMS_TRANSACTION_ERROR, new Object[] { transaction }, e);
if (postImmediate == null || !postImmediate.booleanValue()) {
TransactionEngine.getInstance().updateTransactionStatusToError(transaction.getId(), frameworkException);
}
// Throw the framework exception and exit
throw frameworkException;
}
}
}
Aggregations