use of org.jaffa.persistence.domainobjects.PartAdditional in project jaffa-framework by jaffa-projects.
the class CharFieldTest method testNullQuery.
/**
* Tests the sql:
* Select * from zz_jut_part_additional where field1 is null or field1 = ' '
* This should return 1 record
*/
public void testNullQuery() {
UOW uow = null;
try {
uow = new UOW();
// Create a new object
PartAdditional object = (PartAdditional) uow.newPersistentInstance(PartAdditional.class);
object.setPart(PART);
// enter at least a blank string, since the field is mandatory
object.setField1(" ");
object.setField2("A VALUE");
uow.add(object);
uow.commit();
// Retrieve records where field1 is null. Should get 1 record
uow = new UOW();
Criteria c = new Criteria();
c.setTable(PartAdditionalMeta.getName());
c.addCriteria(PartAdditionalMeta.FIELD1, Criteria.RELATIONAL_IS_NULL);
Collection col = uow.query(c);
assertEquals("One record should have been retrieved", 1, col.size());
object = (PartAdditional) col.iterator().next();
assertEquals(PART, object.getPart());
assertNull(object.getField1());
assertEquals("A VALUE", object.getField2());
assertNull(object.getField3());
// Retrieve records where field2 is null. Nothing should be retrieved
uow = new UOW();
c = new Criteria();
c.setTable(PartAdditionalMeta.getName());
c.addCriteria(PartAdditionalMeta.FIELD2, Criteria.RELATIONAL_IS_NULL);
col = uow.query(c);
assertEquals("No record should have been retrieved", 0, col.size());
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
try {
if (uow != null)
uow.rollback();
} catch (Exception e) {
// do nothing
}
cleanupData(PART);
}
}
use of org.jaffa.persistence.domainobjects.PartAdditional in project jaffa-framework by jaffa-projects.
the class CharFieldTest method testEndsWithQuery.
/**
* Tests the sql:
* Select * from zz_jut_part_additional where trim(part) like '%01'
* This should return 1 record
*/
public void testEndsWithQuery() {
UOW uow = null;
try {
uow = new UOW();
// Create a new object
PartAdditional object = (PartAdditional) uow.newPersistentInstance(PartAdditional.class);
object.setPart(PART);
// enter at least a blank string, since the field is mandatory
object.setField1(" ");
uow.add(object);
uow.commit();
// Perform a query using the EndsWith clause
uow = new UOW();
Criteria c = new Criteria();
c.setTable(PartAdditionalMeta.getName());
c.addCriteria(PartAdditionalMeta.PART, Criteria.RELATIONAL_ENDS_WITH, "01");
Collection col = uow.query(c);
assertEquals("One record should have been retrieved", 1, col.size());
object = (PartAdditional) col.iterator().next();
assertEquals(PART, object.getPart());
assertNull(object.getField1());
assertNull(object.getField2());
assertNull(object.getField3());
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
try {
if (uow != null)
uow.rollback();
} catch (Exception e) {
// do nothing
}
cleanupData(PART);
}
}
use of org.jaffa.persistence.domainobjects.PartAdditional in project jaffa-framework by jaffa-projects.
the class CharFieldTest method testAdd.
/**
* Inserts a new record.
*/
public void testAdd() {
UOW uow = null;
try {
uow = new UOW();
// Create a new object
PartAdditional object = (PartAdditional) uow.newPersistentInstance(PartAdditional.class);
object.setPart(PART);
// enter at least a blank string, since the field is mandatory
object.setField1(" ");
uow.add(object);
uow.commit();
// Now ensure that the record got created
uow = new UOW();
object = PartAdditional.findByPK(uow, PART);
assertNotNull("A PartAdditional object should have been created", object);
assertEquals(PART, object.getPart());
assertNull(object.getField1());
assertNull(object.getField2());
assertNull(object.getField3());
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
try {
if (uow != null)
uow.rollback();
} catch (Exception e) {
// do nothing
}
cleanupData(PART);
}
}
use of org.jaffa.persistence.domainobjects.PartAdditional in project jaffa-framework by jaffa-projects.
the class Part method performPreDeleteReferentialIntegrity.
// .//GEN-END:performForeignKeyValidations_1_be
// .//GEN-BEGIN:performPreDeleteReferentialIntegrity_1_be
/**
* This method is triggered by the UOW, before adding this object to the Delete-Store.
* This will raise an exception if any associated/aggregated objects exist.
* This will cascade delete all composite objects.
* @throws PreDeleteFailedException if any error occurs during the process.
*/
public void performPreDeleteReferentialIntegrity() throws PreDeleteFailedException {
Asset[] assetArray = null;
try {
assetArray = getAssetArray();
} catch (FrameworkException e) {
throw new PreDeleteFailedException(null, e);
}
if (assetArray != null && assetArray.length > 0) {
try {
// Perform cascade deletes
for (int i = 0; i < assetArray.length; i++) getUOW().delete(assetArray[i]);
} catch (Exception e) {
throw new PreDeleteFailedException(null, e);
}
}
Item[] itemArray = null;
try {
itemArray = getItemArray();
} catch (FrameworkException e) {
throw new PreDeleteFailedException(null, e);
}
if (itemArray != null && itemArray.length > 0) {
try {
// Perform cascade deletes
for (int i = 0; i < itemArray.length; i++) getUOW().delete(itemArray[i]);
} catch (Exception e) {
throw new PreDeleteFailedException(null, e);
}
}
PartRemarks partRemarksObject = null;
try {
partRemarksObject = getPartRemarksObject();
} catch (FrameworkException e) {
throw new PreDeleteFailedException(null, e);
}
if (partRemarksObject != null) {
// Stop the deletion !!
throw new PreDeleteFailedException(null, new RelatedDomainObjectFoundException(PartRemarksMeta.getLabelToken()));
}
PartPicture partPictureObject = null;
try {
partPictureObject = getPartPictureObject();
} catch (FrameworkException e) {
throw new PreDeleteFailedException(null, e);
}
if (partPictureObject != null) {
try {
// Perform cascade delete
getUOW().delete(partPictureObject);
} catch (Exception e) {
throw new PreDeleteFailedException(null, e);
}
}
PartRemarksPicture partRemarksPictureObject = null;
try {
partRemarksPictureObject = getPartRemarksPictureObject();
} catch (FrameworkException e) {
throw new PreDeleteFailedException(null, e);
}
if (partRemarksPictureObject != null) {
try {
// Perform cascade delete
getUOW().delete(partRemarksPictureObject);
} catch (Exception e) {
throw new PreDeleteFailedException(null, e);
}
}
PartAdditional partAdditionalObject = null;
try {
partAdditionalObject = getPartAdditionalObject();
} catch (FrameworkException e) {
throw new PreDeleteFailedException(null, e);
}
if (partAdditionalObject != null) {
try {
// Perform cascade delete
getUOW().delete(partAdditionalObject);
} catch (Exception e) {
throw new PreDeleteFailedException(null, e);
}
}
}
Aggregations