use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class TransactionDependencySweeper method updateTransactionDependency.
/**
* Updates missed Transaction Dependency records
* @param tdsv
* @param databean
*/
private void updateTransactionDependency(TransactionDependencySweeperView tdsv, TransactionDependencySweeper databean) {
UOW innerUow = null;
try {
innerUow = new UOW();
TransactionDependency transactionDependency = TransactionDependency.findByPK(innerUow, tdsv.getTransactionId(), tdsv.getDependsOnId());
if (transactionDependency == null) {
log.info("TransactionDependency '" + tdsv.getTransactionId() + "/" + tdsv.getDependsOnId() + "' not found; cannot update it's status to S");
throw new DomainObjectNotFoundException(TransactionDependencyMeta.getLabelToken());
} else {
transactionDependency.setStatus(TransactionDependency.Status.S.toString());
transactionMessageDAO.save(innerUow, transactionDependency);
innerUow.commit();
}
} catch (Exception e) {
// Write to business event log
// Sets Log4J's MDC to enable BusinessEventLogging
MDC.put(BusinessEventLogMeta.SCHEDULED_TASK_ID, databean.getScheduleTaskId());
MDC.put(BusinessEventLogMeta.LOGGED_BY, databean.getLoggedBy());
log.error("Exception thrown during update of Transaction Dependency record" + e);
} finally {
if (innerUow != null) {
try {
innerUow.rollback();
} catch (Exception e) {
log.error("Unable to rollback inner UOW in updating Transaction Dependency");
}
}
}
}
use of org.jaffa.persistence.UOW 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.persistence.UOW in project jaffa-framework by jaffa-projects.
the class TaskFinderTx method find.
/**
* Searches for Task objects.
* @param taskType taskType of tasks that should be returned.
* @throws FrameworkException in case any internal error occurs.
* @throws ApplicationExceptions Indicates application error(s).
* @return The search results.
*/
public TaskFinderOutDto find(String taskType) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
if (log.isDebugEnabled())
log.debug("Retrieving all scheduled tasks");
uow = new UOW();
SchedulerHelper sh = SchedulerHelperFactory.instance();
TaskFinderOutDto output = new TaskFinderOutDto();
output.setSchedulerStatus(sh.getSchedulerStatus());
if (output.getSchedulerStatus() == SchedulerHelper.SchedulerStatusEnumeration.STOPPED) {
if (log.isDebugEnabled())
log.debug("The Scheduler has been shutdown. The Task list cannot be obtained");
} else {
Collection<TaskFinderOutRowDto> rows = new LinkedList<TaskFinderOutRowDto>();
String[] taskTypes = taskType != null ? taskType.split(",") : null;
if (taskTypes != null) {
for (String tempTaskType : taskTypes) {
populateTaskTypes(uow, tempTaskType, sh, rows);
}
} else {
populateTaskTypes(uow, taskType, sh, rows);
}
output.setRows((TaskFinderOutRowDto[]) rows.toArray(new TaskFinderOutRowDto[rows.size()]));
}
if (log.isDebugEnabled())
log.debug("Output: " + output);
return output;
} catch (Exception e) {
throw ExceptionHelper.throwAFR(e);
} finally {
if (uow != null)
uow.rollback();
}
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class UserFinderTx method find.
// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_find_1_be
/**
* Searches for User objects.
* @param input The criteria based on which the search will be performed.
* @throws ApplicationExceptions This will be thrown if the criteria contains invalid data.
* @throws FrameworkException Indicates some system error
* @return The search results.
*/
public UserFinderOutDto find(UserFinderInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
// Print Debug Information for the input
if (log.isDebugEnabled()) {
log.debug("Input: " + input);
}
// create the UOW
uow = new UOW();
// Build the Criteria Object
Criteria criteria = buildCriteria(input, uow);
// .//GEN-END:_find_1_be
// Add custom code before the query //GEN-FIRST:_find_1
// .//GEN-LAST:_find_1
// .//GEN-BEGIN:_find_2_be
// Execute The Query
Collection results = uow.query(criteria);
// .//GEN-END:_find_2_be
// Add custom code after the query //GEN-FIRST:_find_2
// .//GEN-LAST:_find_2
// .//GEN-BEGIN:_find_3_be
// Convert the domain objects into the outbound dto
UserFinderOutDto output = buildDto(uow, results, input);
// Print Debug Information for the output
if (log.isDebugEnabled()) {
log.debug("Output: " + output);
}
return output;
} finally {
if (uow != null)
uow.rollback();
}
}
use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.
the class ApplicationRulesUtilities method incorporateValuesFromPersistentStore.
private void incorporateValuesFromPersistentStore(String source, Map<String, Collection<String>> domainRulesCache, Collection<String> expandedRules, String[] domainInfo, String preRule, String postRule) {
Criteria myCriteria = new Criteria();
UOW myUOW = null;
try {
myCriteria.setTable(domainInfo[1]);
/*
* Added group by to avoid fetching everything. Performance optimization.
* It will find the unique field value based on the provided field on rule.
*/
myCriteria.addGroupBy(domainInfo[2], domainInfo[2]);
myUOW = new UOW();
Collection<String> domainFieldValues = new ArrayList<>();
Iterator<Persistent> myCollection = myUOW.query(myCriteria).iterator();
while (myCollection.hasNext()) {
Map row = (Map) myCollection.next();
String domainFieldValue = (String) row.get(domainInfo[2]);
domainFieldValues.add(domainFieldValue);
String expandedRule = preRule + domainFieldValue + postRule;
// Recursively call this method to handle rules with
// multiple internal properties.
Collection<String> furtherExpandedRules = elaborateDomainRules(expandedRule, domainRulesCache);
expandedRules.addAll(furtherExpandedRules);
}
// Mapping the domain rule name to its content in the cache
domainRulesCache.put(domainInfo[1], domainFieldValues);
} catch (Exception e) {
log.error("Unable to elaborate " + source, e);
} finally {
if (myUOW != null) {
try {
myUOW.rollback();
} catch (Exception e) {
log.error("Failed to rollback UOW:" + e);
}
}
}
}
Aggregations