Search in sources :

Example 1 with Item

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;
}
Also used : Item(org.jaffa.persistence.domainobjects.Item)

Example 2 with 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;
}
Also used : Item(org.jaffa.persistence.domainobjects.Item)

Example 3 with 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();
    }
}
Also used : Item(org.jaffa.persistence.domainobjects.Item) CategoryOfInstrument(org.jaffa.persistence.domainobjects.CategoryOfInstrument) StringWriter(java.io.StringWriter) Part(org.jaffa.persistence.domainobjects.Part) StringReader(java.io.StringReader) Iterator(java.util.Iterator) UOW(org.jaffa.persistence.UOW)

Example 4 with Item

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();
    }
}
Also used : Item(org.jaffa.persistence.domainobjects.Item) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) UOW(org.jaffa.persistence.UOW) Unmarshaller(javax.xml.bind.Unmarshaller) DateTime(org.jaffa.datatypes.DateTime)

Example 5 with Item

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()));
    }
}
Also used : Item(org.jaffa.persistence.domainobjects.Item) FrameworkException(org.jaffa.exceptions.FrameworkException) Asset(org.jaffa.persistence.domainobjects.Asset) RelatedDomainObjectFoundException(org.jaffa.exceptions.RelatedDomainObjectFoundException)

Aggregations

Item (org.jaffa.persistence.domainobjects.Item)6 StringReader (java.io.StringReader)2 FrameworkException (org.jaffa.exceptions.FrameworkException)2 RelatedDomainObjectFoundException (org.jaffa.exceptions.RelatedDomainObjectFoundException)2 UOW (org.jaffa.persistence.UOW)2 Asset (org.jaffa.persistence.domainobjects.Asset)2 StringWriter (java.io.StringWriter)1 Iterator (java.util.Iterator)1 JAXBContext (javax.xml.bind.JAXBContext)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 DateTime (org.jaffa.datatypes.DateTime)1 InvalidForeignKeyException (org.jaffa.datatypes.exceptions.InvalidForeignKeyException)1 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)1 CategoryOfInstrument (org.jaffa.persistence.domainobjects.CategoryOfInstrument)1 Part (org.jaffa.persistence.domainobjects.Part)1 PartAdditional (org.jaffa.persistence.domainobjects.PartAdditional)1 PartPicture (org.jaffa.persistence.domainobjects.PartPicture)1 PartRemarks (org.jaffa.persistence.domainobjects.PartRemarks)1 PartRemarksPicture (org.jaffa.persistence.domainobjects.PartRemarksPicture)1