use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class ItemFinderTx method find.
// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_find_1_be
/**
* Searches for Item 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 ItemFinderOutDto find(ItemFinderInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
// Print Debug Information for the input
if (log.isDebugEnabled()) {
log.debug("Input: " + (input != null ? input.toString() : null));
}
// 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
ItemFinderOutDto output = buildDto(uow, results, input);
// Print Debug Information for the output
if (log.isDebugEnabled()) {
log.debug("Output: " + (output != null ? output.toString() : null));
}
return output;
} finally {
if (uow != null)
uow.rollback();
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class ItemFinderTx method buildCriteria.
// .//GEN-END:_find_3_be
// .//GEN-BEGIN:_buildCriteria_1_be
private Criteria buildCriteria(ItemFinderInDto input, UOW uow) {
Criteria criteria = new Criteria();
criteria.setTable(ItemMeta.getName());
// .//GEN-END:_buildCriteria_1_be
// Add custom criteria //GEN-FIRST:_buildCriteria_1
// .//GEN-LAST:_buildCriteria_1
// .//GEN-BEGIN:_buildCriteria_2_be
FinderTx.addCriteria(input.getSegregationCode(), ItemMeta.SC, criteria);
FinderTx.addCriteria(input.getPartNo(), ItemMeta.PART, criteria);
FinderTx.addCriteria(input.getSerial(), ItemMeta.SERIAL, criteria);
FinderTx.addCriteria(input.getQty(), ItemMeta.QTY, criteria);
// append an orderBy clause to the criteria
OrderByField[] orderByFields = input.getOrderByFields();
if (orderByFields != null) {
for (int i = 0; i < orderByFields.length; i++) {
OrderByField orderByField = orderByFields[i];
int sort = Criteria.ORDER_BY_ASC;
if (orderByField.getSortAscending() != null && !orderByField.getSortAscending().booleanValue())
sort = Criteria.ORDER_BY_DESC;
criteria.addOrderBy(orderByField.getFieldName(), sort);
}
}
// .//GEN-BEGIN:_buildCriteria_3_be
return criteria;
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class UserTimeEntryLookupTx method find.
// .//GEN-END:_destroy_2_be
// .//GEN-BEGIN:_find_1_be
/**
* Searches for UserTimeEntry 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 UserTimeEntryLookupOutDto find(UserTimeEntryLookupInDto input) throws FrameworkException, ApplicationExceptions {
UOW uow = null;
try {
// Print Debug Information for the input
if (log.isDebugEnabled()) {
log.debug("Input: " + (input != null ? input.toString() : null));
}
// 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
UserTimeEntryLookupOutDto output = buildDto(uow, results, input);
// Print Debug Information for the output
if (log.isDebugEnabled()) {
log.debug("Output: " + (output != null ? output.toString() : null));
}
return output;
} finally {
if (uow != null)
uow.rollback();
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class UserTimeEntryMaintenanceTx method load.
// .//GEN-END:_preprocessDelete_2_be
// .//GEN-BEGIN:_loadDelete_1_be
/**
* Retrieve the domain object.
*/
private UserTimeEntry load(UOW uow, UserTimeEntryMaintenanceDeleteInDto input) throws FrameworkException, ApplicationExceptions {
UserTimeEntry domain = null;
Criteria criteria = new Criteria();
criteria.setTable(UserTimeEntryMeta.getName());
// .//GEN-END:_loadDelete_1_be
// Add custom criteria //GEN-FIRST:_loadDelete_1
// .//GEN-LAST:_loadDelete_1
// .//GEN-BEGIN:_loadDelete_2_be
criteria.addCriteria(UserTimeEntryMeta.USER_NAME, input.getUserName());
criteria.addCriteria(UserTimeEntryMeta.PROJECT_CODE, input.getProjectCode());
criteria.addCriteria(UserTimeEntryMeta.TASK, input.getTask());
criteria.addCriteria(UserTimeEntryMeta.PERIOD_START, input.getPeriodStart());
criteria.addCriteria(UserTimeEntryMeta.PERIOD_END, input.getPeriodEnd());
criteria.setLocking(Criteria.LOCKING_PARANOID);
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext())
domain = (UserTimeEntry) itr.next();
// .//GEN-BEGIN:_loadDelete_3_be
if (domain == null) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DomainObjectNotFoundException(UserTimeEntryMeta.getLabelToken()));
throw appExps;
}
return domain;
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class UserTimeEntryMaintenanceTx method duplicateCheck.
// .//GEN-END:_preprocessCreate_2_be
// .//GEN-BEGIN:_duplicateCheck_1_be
/**
* Ensure that a duplicate record is not created.
*/
private void duplicateCheck(UOW uow, UserTimeEntryMaintenanceCreateInDto input) throws FrameworkException, ApplicationExceptions {
// .//GEN-BEGIN:_duplicateCheck_2_be
if (input.getUserName() == null || input.getProjectCode() == null || input.getTask() == null || input.getPeriodStart() == null || input.getPeriodEnd() == null)
return;
Criteria criteria = new Criteria();
criteria.setTable(UserTimeEntryMeta.getName());
// .//GEN-END:_duplicateCheck_2_be
// Add custom criteria //GEN-FIRST:_duplicateCheck_2
// .//GEN-LAST:_duplicateCheck_2
// .//GEN-BEGIN:_duplicateCheck_3_be
criteria.addCriteria(UserTimeEntryMeta.USER_NAME, input.getUserName());
criteria.addCriteria(UserTimeEntryMeta.PROJECT_CODE, input.getProjectCode());
criteria.addCriteria(UserTimeEntryMeta.TASK, input.getTask());
criteria.addCriteria(UserTimeEntryMeta.PERIOD_START, input.getPeriodStart());
criteria.addCriteria(UserTimeEntryMeta.PERIOD_END, input.getPeriodEnd());
Collection col = uow.query(criteria);
// .//GEN-BEGIN:_duplicateCheck_4_be
if (col != null && !col.isEmpty()) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DuplicateKeyException(UserTimeEntryMeta.getLabelToken()));
throw appExps;
}
}
Aggregations