use of org.jaffa.exceptions.DuplicateKeyException in project jaffa-framework by jaffa-projects.
the class FormUsageMaintenanceTx 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, FormUsageMaintenanceCreateInDto input) throws FrameworkException, ApplicationExceptions {
// .//GEN-BEGIN:_duplicateCheck_2_be
if (input.getFormName() == null)
return;
Criteria criteria = new Criteria();
criteria.setTable(FormUsageMeta.getName());
// .//GEN-END:_duplicateCheck_2_be
// Add custom criteria //GEN-FIRST:_duplicateCheck_2
// .//GEN-LAST:_duplicateCheck_2
// .//GEN-BEGIN:_duplicateCheck_3_be
criteria.addCriteria(FormUsageMeta.FORM_NAME, input.getFormName());
Collection col = uow.query(criteria);
// .//GEN-BEGIN:_duplicateCheck_4_be
if (col != null && !col.isEmpty()) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DuplicateKeyException(FormUsageMeta.getLabelToken()));
throw appExps;
}
}
use of org.jaffa.exceptions.DuplicateKeyException in project jaffa-framework by jaffa-projects.
the class PrinterDefinitionMaintenanceTx 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, PrinterDefinitionMaintenanceCreateInDto input) throws FrameworkException, ApplicationExceptions {
// .//GEN-BEGIN:_duplicateCheck_2_be
if (input.getPrinterId() == null)
return;
Criteria criteria = new Criteria();
criteria.setTable(PrinterDefinitionMeta.getName());
// .//GEN-END:_duplicateCheck_2_be
// Add custom criteria//GEN-FIRST:_duplicateCheck_2
// .//GEN-LAST:_duplicateCheck_2
// .//GEN-BEGIN:_duplicateCheck_3_be
criteria.addCriteria(PrinterDefinitionMeta.PRINTER_ID, input.getPrinterId());
Collection col = uow.query(criteria);
// .//GEN-BEGIN:_duplicateCheck_4_be
if (col != null && !col.isEmpty()) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DuplicateKeyException(PrinterDefinitionMeta.getLabelToken()));
throw appExps;
}
}
use of org.jaffa.exceptions.DuplicateKeyException in project jaffa-framework by jaffa-projects.
the class PrinterOutputTypeMaintenanceTx 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, PrinterOutputTypeMaintenanceCreateInDto input) throws FrameworkException, ApplicationExceptions {
// .//GEN-BEGIN:_duplicateCheck_2_be
if (input.getOutputType() == null)
return;
Criteria criteria = new Criteria();
criteria.setTable(PrinterOutputTypeMeta.getName());
// .//GEN-END:_duplicateCheck_2_be
// Add custom criteria //GEN-FIRST:_duplicateCheck_2
// .//GEN-LAST:_duplicateCheck_2
// .//GEN-BEGIN:_duplicateCheck_3_be
criteria.addCriteria(PrinterOutputTypeMeta.OUTPUT_TYPE, input.getOutputType());
Collection col = uow.query(criteria);
// .//GEN-BEGIN:_duplicateCheck_4_be
if (col != null && !col.isEmpty()) {
ApplicationExceptions appExps = new ApplicationExceptions();
appExps.add(new DuplicateKeyException(PrinterOutputTypeMeta.getLabelToken()));
throw appExps;
}
}
use of org.jaffa.exceptions.DuplicateKeyException in project jaffa-framework by jaffa-projects.
the class AddInterceptor method invoke.
/**
*Performs the logic associated with adding Persistent objects to the database.
* This will add each object in the PersistentTransaction's ADD collection to 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.getAdds();
if (objects != null) {
// add the objects to the database
for (Iterator i = objects.iterator(); i.hasNext(); ) {
IPersistent object = (IPersistent) i.next();
try {
if (log.isDebugEnabled())
log.debug("Invoking JdbcBridge.executeAdd() for the object " + object);
JdbcBridge.executeAdd(object, pt.getDataSource());
pt.getDataSource().clearObjectCache();
} catch (SQLIntegrityConstraintViolationException e) {
if (e.getErrorCode() == PRIMARY_KEY_ERROR_CODE) {
String str = "The primary-key is not unique: " + this;
log.error(str);
String labelToken = null;
try {
labelToken = PersistentHelper.getLabelToken(object.getClass().getName());
} catch (Exception ex) {
// don't do anything.. just return the domainClassName
}
if (labelToken == null)
labelToken = MessageHelper.tokenize(object.getClass().getName());
throw new PreAddFailedException(null, new DuplicateKeyException(labelToken));
} else {
String str = "Error while adding the Persistent object to the database: " + object;
log.error(str, e);
// was checked in pre-add previously
throw new PreAddFailedException(null, e);
}
} catch (Exception e) {
String str = "Error while adding the Persistent object to the database: " + object;
log.error(str, e);
throw new AddFailedException(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.exceptions.DuplicateKeyException in project jaffa-framework by jaffa-projects.
the class Persistent method verifyEntityDoesNotExist.
/**
* Check for existence prior to adding to the database.
*/
protected void verifyEntityDoesNotExist() throws PreAddFailedException {
if (log.isDebugEnabled())
log.debug("Invoking PersistentHelper.exists() to ensure unique-ness of the primary-key");
boolean keyExists = false;
try {
keyExists = PersistentHelper.exists(getUOW(), this);
} catch (NoSuchMethodException e) {
// In that case, we'll not perform the check, and leave it to the database to raise an error in case the key is a duplicate
if (log.isDebugEnabled())
log.debug("The exists check could not be performed since either the exists() method is missing or the meta class does not have the getKeyFields method: " + this.getClass());
} catch (Exception e) {
String str = "Exception thrown while checking the unique-ness of the primary-key: " + this;
log.error(str, e);
throw new PreAddFailedException(null, e);
}
if (keyExists) {
String str = "The primary-key is not unique: " + this;
log.error(str);
String labelToken = null;
try {
labelToken = PersistentHelper.getLabelToken(this.getClass().getName());
} catch (Exception e) {
// don't do anything.. just return the domainClassName
}
if (labelToken == null)
labelToken = MessageHelper.tokenize(this.getClass().getName());
throw new PreAddFailedException(null, new DuplicateKeyException(labelToken));
}
}
Aggregations