use of org.jaffa.persistence.domainobjects.Item in project jaffa-framework by jaffa-projects.
the class Condition method newItemObject.
/**
* Creates a new Item object and initializes the related fields.
* This will uncache the related Item objects.
* @throws ValidationException if an invalid value is passed.
* @throws FrameworkException Indicates some system error
* @return the related Item object with the initialized related fields.
*/
public Item newItemObject() throws ValidationException, FrameworkException {
m_itemCollection = null;
Item item = new Item();
item.setCondition(getCondition());
// .//GEN-BEGIN:itemArray_3_be
return item;
}
use of org.jaffa.persistence.domainobjects.Item in project jaffa-framework by jaffa-projects.
the class Part method newItemObject.
/**
* Creates a new Item object and initializes the related fields.
* This will uncache the related Item objects.
* @throws ValidationException if an invalid value is passed.
* @throws FrameworkException Indicates some system error
* @return the related Item object with the initialized related fields.
*/
public Item newItemObject() throws ValidationException, FrameworkException {
m_itemCollection = null;
Item item = new Item();
item.setPart(getPart());
// .//GEN-BEGIN:itemArray_3_be
return item;
}
use of org.jaffa.persistence.domainobjects.Item in project jaffa-framework by jaffa-projects.
the class DomainXmlTest method writeAndReadDomainXml.
/**
* This method serializes a bunch of domain objects to XML.
* The XML is then deserialized back to domain objects.
*/
private void writeAndReadDomainXml(boolean escapeDomainXml) throws Exception {
UOW uow = null;
try {
// Retrieve a few objects and add them to the DomainXmlWriter
uow = new UOW();
DomainXmlWriter dxw = new DomainXmlWriter();
dxw.addObject(CategoryOfInstrument.findByPK(uow, "Z-TESTCI-01"));
dxw.addObject(Part.findByPK(uow, "Z-TESTPART-01"));
dxw.addObject(Part.findByPK(uow, "Z-TESTPART-02"));
dxw.addObject(Item.findByPK(uow, "Z-TESTITEM-01"));
dxw.addObject(Item.findByPK(uow, "Z-TESTITEM-03"));
// write XML
StringWriter w = new StringWriter();
dxw.write(w, escapeDomainXml);
// Now unmarhsal the XML into domain objects
Object obj = null;
String xml = w.toString();
System.out.println("*** Marshalled XML ***\n" + xml);
DomainXmlReader dxr = new DomainXmlReader(new StringReader(xml));
Iterator itr = dxr.iterator();
// Verify the deserialzed objects
obj = itr.next();
assertTrue("CategoryOfInstrument should have been generated", obj instanceof CategoryOfInstrument);
assertEquals("Z-TESTCI-01", ((CategoryOfInstrument) obj).getCategoryInstrument());
assertEquals("Z-TESTCIDESC-01", ((CategoryOfInstrument) obj).getDescription());
obj = itr.next();
assertTrue("Part should have been generated", obj instanceof Part);
assertEquals("Z-TESTPART-01", ((Part) obj).getPart());
assertEquals("Z-TESTNOUN-01", ((Part) obj).getNoun());
obj = itr.next();
assertTrue("Part should have been generated", obj instanceof Part);
assertEquals("Z-TESTPART-02", ((Part) obj).getPart());
assertEquals("Z-TESTNOUN-02", ((Part) obj).getNoun());
obj = itr.next();
assertTrue("Item should have been generated", obj instanceof Item);
assertEquals("Z-TESTITEM-01", ((Item) obj).getItemId());
obj = itr.next();
assertTrue("Item should have been generated", obj instanceof Item);
assertEquals("Z-TESTITEM-03", ((Item) obj).getItemId());
assertTrue("No more records should exist", !itr.hasNext());
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
if (uow != null)
uow.rollback();
}
}
use of org.jaffa.persistence.domainobjects.Item in project jaffa-framework by jaffa-projects.
the class PersistenceLoggingTest method testLogging.
public void testLogging() throws Exception {
UOW uow = null;
try {
// Specify the IPersistenceLoggingPlugin. This should ideally be mentioned in ApplicationRules.global
ContextManagerFactory.instance().setThreadContext(null);
ContextManagerFactory.instance().setProperty("jaffa.persistence.IPersistenceLoggingPlugin", "org.jaffa.persistence.blackboxtests.logging.DemoLogger");
// Create some Items
uow = new UOW();
for (int i = 0; i < ITEM_COUNT; i++) {
Item obj = new Item();
obj.setItemId("Z-TESTLOG-" + i);
obj.setKeyRef("KR" + i);
obj.setCreatedDatetime(new DateTime(2000, DateTime.JANUARY, 15, (i + 1), 30, 40, 0));
obj.setPrice(new Double(i * 10.5));
obj.setQty(new Long(i * 10));
uow.add(obj);
}
uow.commit();
// Delete the Items
uow = new UOW();
for (int i = 0; i < ITEM_COUNT; i++) {
Item obj = Item.findByPK(uow, "Z-TESTLOG-" + i);
assertNotNull("Item having id " + "Z-TESTLOG-" + i + " should have been retrieved", obj);
uow.delete(obj);
}
uow.commit();
// Unmarshal the serialized objects to java
uow = new UOW();
for (String s : DemoLogger.c_addedSerializedObjects) {
JAXBContext jc = JAXBContext.newInstance(new Class[] { Item.class });
Unmarshaller unmarshaller = jc.createUnmarshaller();
Object obj = unmarshaller.unmarshal(new StringReader(s));
uow.addSpecial(obj);
}
DemoLogger.c_addedSerializedObjects.clear();
uow.commit();
// Delete the Items
uow = new UOW();
for (int i = 0; i < ITEM_COUNT; i++) {
Item obj = Item.findByPK(uow, "Z-TESTLOG-" + i);
assertNotNull("Item having id " + "Z-TESTLOG-" + i + " should have been retrieved", obj);
assertEquals("KR" + i, obj.getKeyRef());
assertEquals(new DateTime(2000, DateTime.JANUARY, 15, (i + 1), 30, 40, 0), obj.getCreatedDatetime());
assertEquals(new Double(i * 10.5), obj.getPrice());
assertEquals(new Long(i * 10), obj.getQty());
uow.delete(obj);
}
uow.commit();
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
if (uow != null)
uow.rollback();
}
}
use of org.jaffa.persistence.domainobjects.Item in project jaffa-framework by jaffa-projects.
the class Condition 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) {
// Stop the deletion !!
throw new PreDeleteFailedException(null, new RelatedDomainObjectFoundException(AssetMeta.getLabelToken()));
}
Item[] itemArray = null;
try {
itemArray = getItemArray();
} catch (FrameworkException e) {
throw new PreDeleteFailedException(null, e);
}
if (itemArray != null && itemArray.length > 0) {
// Stop the deletion !!
throw new PreDeleteFailedException(null, new RelatedDomainObjectFoundException(ItemMeta.getLabelToken()));
}
}
Aggregations