use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class BusinessEventLogViewerTx method addRelatedDtos.
// .//GEN-END:_buildDto_3_be
// .//GEN-BEGIN:_addRelatedDtos_1_be
private void addRelatedDtos(UOW uow, BusinessEventLogViewerOutDto output, BusinessEventLog businessEventLog) throws UOWException {
// .//GEN-BEGIN:_addRelatedDtos_Attachment_1_be
if (businessEventLog.getLogId() != null) {
Criteria criteria = new Criteria();
criteria.setTable(AttachmentMeta.getName());
criteria.addCriteria(AttachmentMeta.SERIALIZED_KEY, businessEventLog.getLogId());
criteria.addOrderBy("AttachmentId", Criteria.ORDER_BY_ASC);
// Create a new Criteria, and pass the correct serializedKey
try {
criteria = new Criteria();
criteria.setTable(AttachmentMeta.getName());
criteria.addCriteria(AttachmentMeta.SERIALIZED_KEY, PersistentHelper.generateSerializedKey(businessEventLog));
criteria.addOrderBy(AttachmentMeta.ATTACHMENT_ID, Criteria.ORDER_BY_ASC);
} catch (Exception e) {
String str = "Error in generating the serialized key";
log.error(str, e);
throw new RuntimeException(str, e);
}
// .//GEN-LAST:_addRelatedDtos_Attachment_1
// .//GEN-BEGIN:_addRelatedDtos_Attachment_2_be
Iterator itr = uow.query(criteria).iterator();
while (itr.hasNext()) {
Attachment attachment = (Attachment) itr.next();
AttachmentDto dto = new AttachmentDto();
// .//GEN-END:_addRelatedDtos_Attachment_2_be
// Add custom code before all the setters//GEN-FIRST:_addRelatedDtos_Attachment_2
// .//GEN-LAST:_addRelatedDtos_Attachment_2
// .//GEN-BEGIN:_addRelatedDtos_Attachment_AttachmentId_1_be
dto.setAttachmentId(attachment.getAttachmentId());
// .//GEN-END:_addRelatedDtos_Attachment_AttachmentId_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_SerializedKey_1_be
dto.setSerializedKey(attachment.getSerializedKey());
// .//GEN-END:_addRelatedDtos_Attachment_SerializedKey_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_OriginalFileName_1_be
dto.setOriginalFileName(attachment.getOriginalFileName());
// .//GEN-END:_addRelatedDtos_Attachment_OriginalFileName_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_AttachmentType_1_be
dto.setAttachmentType(attachment.getAttachmentType());
// .//GEN-END:_addRelatedDtos_Attachment_AttachmentType_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_ContentType_1_be
dto.setContentType(attachment.getContentType());
// .//GEN-END:_addRelatedDtos_Attachment_ContentType_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_Description_1_be
dto.setDescription(attachment.getDescription());
// .//GEN-END:_addRelatedDtos_Attachment_Description_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_Remarks_1_be
dto.setRemarks(attachment.getRemarks());
// .//GEN-END:_addRelatedDtos_Attachment_Remarks_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_SupercededBy_1_be
dto.setSupercededBy(attachment.getSupercededBy());
// .//GEN-END:_addRelatedDtos_Attachment_SupercededBy_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_CreatedOn_1_be
dto.setCreatedOn(attachment.getCreatedOn());
// .//GEN-END:_addRelatedDtos_Attachment_CreatedOn_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_CreatedBy_1_be
dto.setCreatedBy(attachment.getCreatedBy());
// .//GEN-END:_addRelatedDtos_Attachment_CreatedBy_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_LastChangedOn_1_be
dto.setLastChangedOn(attachment.getLastChangedOn());
// .//GEN-END:_addRelatedDtos_Attachment_LastChangedOn_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_LastChangedBy_1_be
dto.setLastChangedBy(attachment.getLastChangedBy());
// .//GEN-END:_addRelatedDtos_Attachment_LastChangedBy_1_be
// .//GEN-BEGIN:_addRelatedDtos_Attachment_Data_1_be
dto.setData(attachment.getData());
// .//GEN-END:_addRelatedDtos_Attachment_Data_1_be
// Add custom code to pass values to the dto//GEN-FIRST:_addRelatedDtos_Attachment_3
// .//GEN-LAST:_addRelatedDtos_Attachment_3
// .//GEN-BEGIN:_addRelatedDtos_Attachment_3_be
output.addAttachment(dto);
}
}
// .//GEN-END:_addRelatedDtos_Attachment_3_be
// .//GEN-BEGIN:_addRelatedDtos_2_be
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class BusinessEventLogFinderTx method buildCriteria.
// .//GEN-END:_find_3_be
// .//GEN-BEGIN:_buildCriteria_1_be
private Criteria buildCriteria(BusinessEventLogFinderInDto input, UOW uow) {
Criteria criteria = new Criteria();
criteria.setTable(BusinessEventLogMeta.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.getLogId(), BusinessEventLogMeta.LOG_ID, criteria);
FinderTx.addCriteria(input.getCorrelationType(), BusinessEventLogMeta.CORRELATION_TYPE, criteria);
FinderTx.addCriteria(input.getCorrelationKey1(), BusinessEventLogMeta.CORRELATION_KEY1, criteria);
FinderTx.addCriteria(input.getCorrelationKey2(), BusinessEventLogMeta.CORRELATION_KEY2, criteria);
FinderTx.addCriteria(input.getCorrelationKey3(), BusinessEventLogMeta.CORRELATION_KEY3, criteria);
FinderTx.addCriteria(input.getScheduledTaskId(), BusinessEventLogMeta.SCHEDULED_TASK_ID, criteria);
FinderTx.addCriteria(input.getMessageId(), BusinessEventLogMeta.MESSAGE_ID, criteria);
FinderTx.addCriteria(input.getLoggedOn(), BusinessEventLogMeta.LOGGED_ON, criteria);
FinderTx.addCriteria(input.getLoggedBy(), BusinessEventLogMeta.LOGGED_BY, criteria);
FinderTx.addCriteria(input.getProcessName(), BusinessEventLogMeta.PROCESS_NAME, criteria);
FinderTx.addCriteria(input.getSubProcessName(), BusinessEventLogMeta.SUB_PROCESS_NAME, criteria);
FinderTx.addCriteria(input.getMessageType(), BusinessEventLogMeta.MESSAGE_TYPE, criteria);
FinderTx.addCriteria(input.getMessageText(), BusinessEventLogMeta.MESSAGE_TEXT, criteria);
FinderTx.addCriteria(input.getSourceClass(), BusinessEventLogMeta.SOURCE_CLASS, criteria);
FinderTx.addCriteria(input.getSourceMethod(), BusinessEventLogMeta.SOURCE_METHOD, criteria);
FinderTx.addCriteria(input.getSourceLine(), BusinessEventLogMeta.SOURCE_LINE, criteria);
FinderTx.addCriteria(input.getStackTrace(), BusinessEventLogMeta.STACK_TRACE, 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 ForeignKeyFieldValidator method validate.
/**
* The RulesEngine will invoke this method to perform the field validation.
* @throws ValidationException if any validation rule fails.
* @throws FrameworkException if any framework error occurs.
*/
public void validate() throws ValidationException, FrameworkException {
if (getValue() != null) {
UOW uow = getUow();
boolean localUow = (uow == null);
try {
if (localUow)
uow = new UOW();
Criteria c = new Criteria();
c.setTable(getDomainClass());
c.addCriteria(getProperty(), getValue());
Collection col = uow.query(c);
if (col.size() == 0) {
String str = "ForeignKey validation failed for the value '" + getValue() + "' against the domainClass/field - " + getDomainClass() + '/' + getProperty();
log.error(str);
throw new InvalidForeignKeyException(getLabelToken(), new Object[] { getLabelToken(getDomainClass()), getLabelToken(getDomainClass(), getProperty()) });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class GenericForeignKeyFieldValidator method validate.
/**
* The RulesEngine will invoke this method to perform the field validation.
* @throws ValidationException if any validation rule fails.
* @throws FrameworkException if any framework error occurs.
*/
public void validate() throws ValidationException, FrameworkException {
if (getValue() != null) {
UOW uow = getUow();
boolean localUow = (uow == null);
try {
if (localUow)
uow = new UOW();
Criteria c = new Criteria();
c.setTable(getDomainClassName());
c.addCriteria(getFieldNameForTable(), getTableName());
c.addCriteria(getFieldNameForField(), getFieldName());
c.addCriteria(getFieldNameForValue(), getValue().toString());
Collection col = uow.query(c);
if (col.size() == 0) {
// Invalid value. Display the list of valid values in the error message
StringBuffer validValues = new StringBuffer();
c = new Criteria();
c.setTable(getDomainClassName());
c.addCriteria(getFieldNameForTable(), getTableName());
c.addCriteria(getFieldNameForField(), getFieldName());
c.addOrderBy(getFieldNameForValue(), Criteria.ORDER_BY_ASC);
for (Iterator i = uow.query(c).iterator(); i.hasNext(); ) {
try {
Object value = BeanHelper.getField(i.next(), getFieldNameForValue());
if (validValues.length() > 0)
validValues.append(',');
validValues.append(value);
} catch (Exception e) {
// do nothing
}
}
String str = "Generic ForeignKey validation failed for the value '" + getValue() + "' against the table/field - " + getTableName() + '/' + getFieldName() + ". Valid values are " + validValues.toString();
log.error(str);
throw new InvalidGenericForeignKeyException(getLabelToken(), new Object[] { getTableName(), getFieldName(), validValues.toString() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
}
use of org.jaffa.persistence.Criteria in project jaffa-framework by jaffa-projects.
the class AddTest method testAddDateTime.
/**
* Inserts a record into ITEM using the query:
* insert into ITEM(ITEM_ID, CREATED_DATETIME) values('Z-TESTITEM-04', to_date('2003-09-10 20:30:40', 'yyyy-MM-dd hh24:mi:ss')).
* It then checks if the record was added. Finally the record is deleted
*/
public void testAddDateTime() {
try {
String itemId = "Z-TESTITEM-04";
DateTime datetime = new DateTime(2003, DateTime.SEPTEMBER, 10, 20, 30, 40, 0);
Item obj = (Item) m_uow.newPersistentInstance(Item.class);
obj.updateItemId(itemId);
obj.updateCreatedDatetime(datetime);
m_uow.add(obj);
m_uow.commit();
// Now retrieve the added record & check if it was correctly added
m_uow = new UOW();
Criteria c = new Criteria();
c.setTable(ItemMeta.getName());
c.addCriteria(ItemMeta.ITEM_ID, itemId);
Iterator i = m_uow.query(c).iterator();
Item item = (Item) i.next();
assertEquals(itemId, item.getItemId());
assertEquals(datetime, item.getCreatedDatetime());
// Now delete the bugger
m_uow.delete(item);
m_uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations