use of org.jaffa.persistence.exceptions.UOWException 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.exceptions.UOWException in project jaffa-framework by jaffa-projects.
the class UserContextWrapper method readUserRoles.
/**
* Read the roles for the user from the database
*
* @param userId the user id.
* @return the roles for the user.
* @throws FrameworkException if any internal error occurs.
*/
protected String[] readUserRoles(String userId) throws FrameworkException {
UOW uow = null;
List<String> roleList = new ArrayList<String>();
try {
uow = new UOW();
Criteria c = new Criteria();
c.setTable(UserRoleMeta.getName());
c.addCriteria(UserRoleMeta.USER_NAME, userId);
Collection roles = uow.query(c);
for (Iterator it = roles.iterator(); it.hasNext(); ) {
UserRole role = (UserRole) it.next();
roleList.add(role.getRoleName());
}
} catch (UOWException e) {
// Log the error
log.error("Can't Get The Roles for User - " + userId, e);
} finally {
// Attempt to rollback any open transaction
try {
if (uow != null) {
uow.rollback();
}
} catch (UOWException e) {
log.error("Rollback", e);
}
}
return (String[]) roleList.toArray(new String[0]);
}
use of org.jaffa.persistence.exceptions.UOWException in project jaffa-framework by jaffa-projects.
the class UpdateInterceptor method invoke.
/**
*Performs the logic associated with updating Persistent objects in the database.
* This will update each object in the PersistentTransaction's UPDATE collection in the database, utilising the JdbcBridge.
* It will then pass on the control to the next Interceptor in the chain.
* @param pt The PersistentTransaction object, on which the Interceptor is to be executed.
* @throws UOWException if any error occurs.
* @return the output from the next Interceptor in the chain.
*/
public Object invoke(PersistentTransaction pt) throws UOWException {
Collection objects = pt.getUpdates();
if (objects != null) {
// updates the objects in the database
for (Iterator i = objects.iterator(); i.hasNext(); ) {
IPersistent object = (IPersistent) i.next();
try {
if (log.isDebugEnabled())
log.debug("Invoking JdbcBridge.executeUpdate() for the object " + object);
JdbcBridge.executeUpdate(object, pt.getDataSource());
pt.getDataSource().clearObjectCache();
} catch (Exception e) {
String str = "Error while updating the Persistent object in the database: " + object;
log.error(str, e);
throw new UpdateFailedException(null, e);
}
i.remove();
}
}
// pass control to the next interceptor in the chain
if (getNextInterceptor() != null) {
if (log.isDebugEnabled())
log.debug("Invoking the next Interceptor in the chain " + getNextInterceptor().getClass().getName());
return getNextInterceptor().invoke(pt);
} else {
if (log.isDebugEnabled())
log.debug("This is the end of the Interceptor chain");
return null;
}
}
use of org.jaffa.persistence.exceptions.UOWException in project jaffa-framework by jaffa-projects.
the class DeleteInterceptor method invoke.
/**
*Performs the logic associated with deleting Persistent objects from the database.
* This will delete each object in the PersistentTransaction's DELETE collection from the database, utilising the JdbcBridge.
* It will then pass on the control to the next Interceptor in the chain.
* @param pt The PersistentTransaction object, on which the Interceptor is to be executed.
* @throws UOWException if any error occurs.
* @return the output from the next Interceptor in the chain.
*/
public Object invoke(PersistentTransaction pt) throws UOWException {
Collection objects = pt.getDeletes();
if (objects != null) {
// deletes the objects from the database
for (Iterator i = objects.iterator(); i.hasNext(); ) {
IPersistent object = (IPersistent) i.next();
try {
if (log.isDebugEnabled())
log.debug("Invoking JdbcBridge.executeDelete() for the object " + object);
JdbcBridge.executeDelete(object, pt.getDataSource());
pt.getDataSource().clearObjectCache();
} catch (Exception e) {
String str = "Error while deleting the Persistent object from the database: " + object;
log.error(str, e);
throw new DeleteFailedException(null, e);
}
i.remove();
}
}
// pass control to the next interceptor in the chain
if (getNextInterceptor() != null) {
if (log.isDebugEnabled())
log.debug("Invoking the next Interceptor in the chain " + getNextInterceptor().getClass().getName());
return getNextInterceptor().invoke(pt);
} else {
if (log.isDebugEnabled())
log.debug("This is the end of the Interceptor chain");
return null;
}
}
use of org.jaffa.persistence.exceptions.UOWException in project jaffa-framework by jaffa-projects.
the class QueryInterceptor method invoke.
/**
*Performs the logic associated with querying the database. It will perform queries for each Criteria object in the PersistentTransaction's QUERY collection.
* Ideally there will be just one Criteria object in the collection.
* Control will be passed to the next interceptor in the chain, if any, else a Collection will be returned containing the Results of the last query.
* @param pt The PersistentTransaction object, on which the Interceptor is to be executed.
* @throws UOWException if any error occurs.
* @return the output from the next Interceptor in the chain, if any, else a Collection will be returned containing the Results of the last query. However, for a Criteria having a StoredProcedure, the output will be null.
*/
public Object invoke(PersistentTransaction pt) throws UOWException {
Object output = null;
if (pt.getQuery() != null) {
// check if the 1st entry in the criteria is a StoredPreocdure
Criteria criteria = pt.getQuery();
Object firstCriteriaElement = null;
Collection criteriaEntries = criteria.getCriteriaEntries();
if (criteriaEntries != null && criteriaEntries.size() > 0)
firstCriteriaElement = criteria.getCriteriaEntries().iterator().next();
if (firstCriteriaElement != null)
firstCriteriaElement = ((Criteria.CriteriaEntry) firstCriteriaElement).getValue();
if (firstCriteriaElement != null && firstCriteriaElement instanceof IStoredProcedure) {
try {
if (log.isDebugEnabled())
log.debug("Invoking JdbcBridge.executeStoredProcedure()");
JdbcBridge.executeStoredProcedure((IStoredProcedure) firstCriteriaElement, criteria, pt.getDataSource());
} catch (Exception e) {
String str = "Error in executing the StoredProcedure: " + firstCriteriaElement;
if (log.isDebugEnabled())
log.debug(str, e);
throw new QueryFailedException(null, e);
}
} else {
try {
if (log.isDebugEnabled())
log.debug("Invoking JdbcBridge.executeQuery()");
output = JdbcBridge.executeQuery(criteria, pt.getDataSource());
} catch (Exception e) {
String str = "Error in executing the query on : " + criteria.getTable();
if (log.isDebugEnabled())
log.debug(str, e);
throw new QueryFailedException(null, e);
}
}
pt.setQuery(null);
}
// pass control to the next interceptor in the chain
if (getNextInterceptor() != null) {
if (log.isDebugEnabled())
log.debug("Invoking the next Interceptor in the chain " + getNextInterceptor().getClass().getName());
return getNextInterceptor().invoke(pt);
} else {
if (log.isDebugEnabled())
log.debug("This is the end of the Interceptor chain");
return output;
}
}
Aggregations