use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class FormTemplate method findFormDefinitionObject.
/**
* Finds the related FormDefinition object.
* If checkExistenceOnly is false, then the related object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the related object, as oppposed to fetching all the values for that object.
*/
private void findFormDefinitionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_formDefinitionObject == null && getFormId() != null) {
Criteria criteria = new Criteria();
criteria.setTable(FormDefinitionMeta.getName());
criteria.addCriteria(FormDefinitionMeta.FORM_ID, getFormId());
if (checkExistenceOnly)
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Number count = null;
if (uow == null || !uow.isActive()) {
uow = new UOW();
localUow = true;
}
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
if (checkExistenceOnly)
count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
else
m_formDefinitionObject = (FormDefinition) itr.next();
}
if (m_formDefinitionObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(FormTemplateMeta.META_FORM_ID.getLabelToken(), new Object[] { FormDefinitionMeta.getLabelToken(), FormDefinitionMeta.META_FORM_ID.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class FormUsage method findFormGroupObject.
/**
* Finds the related foreign FormGroup object.
* If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
*/
private void findFormGroupObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_formGroupObject == null && getFormName() != null) {
Criteria criteria = new Criteria();
criteria.setTable(FormGroupMeta.getName());
criteria.addCriteria(FormGroupMeta.FORM_NAME, getFormName());
if (checkExistenceOnly)
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Number count = null;
if (uow == null || !uow.isActive()) {
uow = new UOW();
localUow = true;
}
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
if (checkExistenceOnly)
count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
else
m_formGroupObject = (FormGroup) itr.next();
}
if (m_formGroupObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(FormUsageMeta.META_FORM_NAME.getLabelToken(), new Object[] { FormGroupMeta.getLabelToken(), FormGroupMeta.META_FORM_NAME.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class SOAEventParam method findSOAEventObject.
/**
* Finds the related foreign SOAEvent object.
* If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
*/
private void findSOAEventObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
UOW uow = getUOW();
boolean localUow = false;
try {
if (m_sOAEventObject == null && getEventId() != null) {
Criteria criteria = new Criteria();
criteria.setTable(SOAEventMeta.getName());
criteria.addCriteria(SOAEventMeta.EVENT_ID, getEventId());
if (checkExistenceOnly)
criteria.addFunction(Criteria.FUNCTION_COUNT, null, Criteria.ID_FUNCTION_COUNT);
Number count = null;
if (uow == null || !uow.isActive()) {
uow = new UOW();
localUow = true;
}
Iterator itr = uow.query(criteria).iterator();
if (itr.hasNext()) {
if (checkExistenceOnly)
count = (Number) ((Map) itr.next()).get(Criteria.ID_FUNCTION_COUNT);
else
m_sOAEventObject = (SOAEvent) itr.next();
}
if (m_sOAEventObject == null && (count == null || count.intValue() <= 0))
throw new InvalidForeignKeyException(SOAEventParamMeta.META_EVENT_ID.getLabelToken(), new Object[] { SOAEventMeta.getLabelToken(), SOAEventMeta.META_EVENT_ID.getLabelToken() });
}
} finally {
if (localUow && uow != null)
uow.rollback();
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class ExtensionTest method testCompositeForeignKey.
public void testCompositeForeignKey() {
try {
Extension1 obj = createExtension1();
try {
obj.setField10("KEY1");
obj.setField5(4L);
obj.validate();
} catch (Exception e) {
InvalidForeignKeyException appExp = (InvalidForeignKeyException) ExceptionHelper.extractException(e, InvalidForeignKeyException.class);
if (appExp != null) {
Object[] arguments = appExp.getArguments();
assertNotNull("The InvalidForeignKeyException should have arguments", arguments);
assertTrue("The InvalidForeignKeyException should have arguments", arguments.length > 0);
assertEquals("The InvalidForeignKeyException should have been created for field10,field5", "field10,field5", arguments[0]);
} else {
throw e;
}
}
// The following is a valid foreign-key and should work
obj.setField10("KEY1");
obj.setField5(3L);
obj.validate();
} catch (Exception e) {
e.printStackTrace(System.err);
fail();
}
}
use of org.jaffa.datatypes.exceptions.InvalidForeignKeyException in project jaffa-framework by jaffa-projects.
the class TransactionDependency method findDependsOnTransactionObject.
/**
* Finds the related foreign Transaction object.
* If checkExistenceOnly is false, then the foreign object will be fetched and assigned to the corresponding member variable of this class.
* If checkExistenceOnly is true, then a mere existence check is performed for the foreign object, as oppposed to fetching all the values for that object.
*/
private void findDependsOnTransactionObject(boolean checkExistenceOnly) throws ValidationException, FrameworkException {
// TODO this is generated code...
if (m_dependsOnTransactionObject == null && getDependsOnId() != null) {
Transaction transaction = getTransactionDAO().getTransaction(getDependsOnId());
Number count = null;
if (checkExistenceOnly) {
if (transaction != null) {
count = 1;
}
} else {
m_dependsOnTransactionObject = transaction;
}
if ((m_dependsOnTransactionObject == null) && ((count == null) || (count.intValue() <= 0))) {
throw new InvalidForeignKeyException(TransactionDependencyMeta.META_DEPENDS_ON_ID.getLabelToken(), new Object[] { TransactionMeta.getLabelToken(), TransactionMeta.META_ID.getLabelToken() });
}
}
}
Aggregations