Search in sources :

Example 41 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class RawTest method testUpdateRawAndLongRaw.

/**
 * Creates ZZ_TEST_PART_PICTURE records having raw and longraw elements.
 * It then retrieves and updates the rows. Finally it checks if the data has been updated.
 */
public void testUpdateRawAndLongRaw() {
    try {
        // create 3 records
        PartPicture partPicture = null;
        partPicture = (PartPicture) m_uow.newPersistentInstance(PartPicture.class);
        partPicture.updatePart("Z-TESTPART-01");
        partPicture.updateSmallPicture("Z-TESTSMALLPICTURE-01".getBytes());
        partPicture.updatePicture((LONG_FIELD + "01").getBytes());
        m_uow.add(partPicture);
        partPicture = (PartPicture) m_uow.newPersistentInstance(PartPicture.class);
        partPicture.updatePart("Z-TESTPART-02");
        partPicture.updateSmallPicture("Z-TESTSMALLPICTURE-02".getBytes());
        partPicture.updatePicture((LONG_FIELD + "02").getBytes());
        m_uow.add(partPicture);
        partPicture = (PartPicture) m_uow.newPersistentInstance(PartPicture.class);
        partPicture.updatePart("Z-TESTPART-03");
        partPicture.updateSmallPicture("Z-TESTSMALLPICTURE-03".getBytes());
        partPicture.updatePicture((LONG_FIELD + "03").getBytes());
        m_uow.add(partPicture);
        m_uow.commit();
        // now check if they have been added
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(PartPictureMeta.getName());
        c.addCriteria(PartPictureMeta.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z");
        c.addOrderBy(PartPictureMeta.PART, Criteria.ORDER_BY_ASC);
        Collection col = m_uow.query(c);
        // fetch in all the records
        for (Iterator i = col.iterator(); i.hasNext(); ) i.next();
        assertEquals(3, col.size());
        PartPicture[] partPictures = (PartPicture[]) col.toArray(new PartPicture[0]);
        assertEquals("Z-TESTPART-01", partPictures[0].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-01".getBytes(), partPictures[0].getSmallPicture()));
        assertTrue(Arrays.equals((LONG_FIELD + "01").getBytes(), partPictures[0].getPicture()));
        assertEquals("Z-TESTPART-02", partPictures[1].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-02".getBytes(), partPictures[1].getSmallPicture()));
        assertTrue(Arrays.equals((LONG_FIELD + "02").getBytes(), partPictures[1].getPicture()));
        assertEquals("Z-TESTPART-03", partPictures[2].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-03".getBytes(), partPictures[2].getSmallPicture()));
        assertTrue(Arrays.equals((LONG_FIELD + "03").getBytes(), partPictures[2].getPicture()));
        // now update the records
        partPictures[0].updateSmallPicture(null);
        partPictures[0].updatePicture(null);
        partPictures[1].updateSmallPicture("Z-TESTSMALLPICTURE-022".getBytes());
        partPictures[1].updatePicture("Z-TESTPICTURE-022".getBytes());
        m_uow.update(partPictures[0]);
        m_uow.update(partPictures[1]);
        m_uow.commit();
        // now check if the updates were successful
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(PartPictureMeta.getName());
        c.addCriteria(PartPictureMeta.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z");
        c.addOrderBy(PartPictureMeta.PART, Criteria.ORDER_BY_ASC);
        col = m_uow.query(c);
        // fetch in all the records
        for (Iterator i = col.iterator(); i.hasNext(); ) i.next();
        assertEquals(3, col.size());
        partPictures = (PartPicture[]) col.toArray(new PartPicture[0]);
        assertEquals("Z-TESTPART-01", partPictures[0].getPart());
        assertNull(partPictures[0].getSmallPicture());
        assertNull(partPictures[0].getPicture());
        assertEquals("Z-TESTPART-02", partPictures[1].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-022".getBytes(), partPictures[1].getSmallPicture()));
        assertTrue(Arrays.equals("Z-TESTPICTURE-022".getBytes(), partPictures[1].getPicture()));
        assertEquals("Z-TESTPART-03", partPictures[2].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-03".getBytes(), partPictures[2].getSmallPicture()));
        assertTrue(Arrays.equals((LONG_FIELD + "03").getBytes(), partPictures[2].getPicture()));
        // now delete the records
        m_uow.delete(partPictures[0]);
        m_uow.delete(partPictures[1]);
        m_uow.delete(partPictures[2]);
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 42 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class RawTest method testUpdateRawAndLongRawUsingProxy.

/**
 * Creates ZZ_TEST_PART_PICTURE records having raw and longraw elements.
 * It then retrieves and updates the rows. Finally it checks if the data has been updated.
 */
public void testUpdateRawAndLongRawUsingProxy() {
    try {
        // create 3 records
        IPartPicture partPicture = null;
        partPicture = (IPartPicture) m_uow.newPersistentInstance(IPartPicture.class);
        partPicture.setPart("Z-TESTPART-01");
        partPicture.setSmallPicture("Z-TESTSMALLPICTURE-01".getBytes());
        partPicture.setPicture((LONG_FIELD + "01").getBytes());
        m_uow.add(partPicture);
        partPicture = (IPartPicture) m_uow.newPersistentInstance(IPartPicture.class);
        partPicture.setPart("Z-TESTPART-02");
        partPicture.setSmallPicture("Z-TESTSMALLPICTURE-02".getBytes());
        partPicture.setPicture((LONG_FIELD + "02").getBytes());
        m_uow.add(partPicture);
        partPicture = (IPartPicture) m_uow.newPersistentInstance(IPartPicture.class);
        partPicture.setPart("Z-TESTPART-03");
        partPicture.setSmallPicture("Z-TESTSMALLPICTURE-03".getBytes());
        partPicture.setPicture((LONG_FIELD + "03").getBytes());
        m_uow.add(partPicture);
        m_uow.commit();
        // now check if they have been added
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(IPartPicture.class.getName());
        c.addCriteria(IPartPicture.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z");
        c.addOrderBy(IPartPicture.PART, Criteria.ORDER_BY_ASC);
        Collection col = m_uow.query(c);
        // fetch in all the records
        for (Iterator i = col.iterator(); i.hasNext(); ) i.next();
        assertEquals(3, col.size());
        IPartPicture[] partPictures = (IPartPicture[]) col.toArray(new IPartPicture[0]);
        assertEquals("Z-TESTPART-01", partPictures[0].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-01".getBytes(), partPictures[0].getSmallPicture()));
        assertTrue(Arrays.equals((LONG_FIELD + "01").getBytes(), partPictures[0].getPicture()));
        assertEquals("Z-TESTPART-02", partPictures[1].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-02".getBytes(), partPictures[1].getSmallPicture()));
        assertTrue(Arrays.equals((LONG_FIELD + "02").getBytes(), partPictures[1].getPicture()));
        assertEquals("Z-TESTPART-03", partPictures[2].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-03".getBytes(), partPictures[2].getSmallPicture()));
        assertTrue(Arrays.equals((LONG_FIELD + "03").getBytes(), partPictures[2].getPicture()));
        // now update the records
        partPictures[0].setSmallPicture(null);
        partPictures[0].setPicture(null);
        partPictures[1].setSmallPicture("Z-TESTSMALLPICTURE-022".getBytes());
        partPictures[1].setPicture("Z-TESTPICTURE-022".getBytes());
        m_uow.update(partPictures[0]);
        m_uow.update(partPictures[1]);
        m_uow.commit();
        // now check if the updates were successful
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(IPartPicture.class.getName());
        c.addCriteria(IPartPicture.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z");
        c.addOrderBy(IPartPicture.PART, Criteria.ORDER_BY_ASC);
        col = m_uow.query(c);
        // fetch in all the records
        for (Iterator i = col.iterator(); i.hasNext(); ) i.next();
        assertEquals(3, col.size());
        partPictures = (IPartPicture[]) col.toArray(new IPartPicture[0]);
        assertEquals("Z-TESTPART-01", partPictures[0].getPart());
        assertNull(partPictures[0].getSmallPicture());
        assertNull(partPictures[0].getPicture());
        assertEquals("Z-TESTPART-02", partPictures[1].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-022".getBytes(), partPictures[1].getSmallPicture()));
        assertTrue(Arrays.equals("Z-TESTPICTURE-022".getBytes(), partPictures[1].getPicture()));
        assertEquals("Z-TESTPART-03", partPictures[2].getPart());
        assertTrue(Arrays.equals("Z-TESTSMALLPICTURE-03".getBytes(), partPictures[2].getSmallPicture()));
        assertTrue(Arrays.equals((LONG_FIELD + "03").getBytes(), partPictures[2].getPicture()));
        // now delete the records
        m_uow.delete(partPictures[0]);
        m_uow.delete(partPictures[1]);
        m_uow.delete(partPictures[2]);
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 43 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class SpecialAddUpdateDeleteTest method createItem.

/**
 * Inserts a record into Item using add() and addSpecial() methods.
 * The receivedItemId field, which is set in the preAdd() method of Item, should get stamped during the add() invocation only.
 */
private void createItem(boolean useSpecial) {
    try {
        String itemId = "Z-TESTITEM-04";
        if (m_uow == null || !m_uow.isActive())
            m_uow = new UOW();
        // Create an item using the add() or addSpecial() methods
        Item obj = (Item) m_uow.newPersistentInstance(Item.class);
        obj.setItemId(itemId);
        if (!useSpecial)
            m_uow.add(obj);
        else
            m_uow.addSpecial(obj);
        m_uow.commit();
        // Now retrieve the added record & check if the receivedItemId got stamped for the add() case only
        m_uow = new UOW();
        obj = Item.findByPK(m_uow, itemId);
        if (!useSpecial)
            assertEquals("ADD" + itemId, obj.getReceivedItemId());
        else
            assertNull("The preAdd trigger should not have been fired in the special case", obj.getReceivedItemId());
        // Now delete the object
        m_uow.delete(obj);
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : UOW(org.jaffa.persistence.UOW)

Example 44 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class SpecialAddUpdateDeleteTest method updateItem.

/**
 * Creates an Item record and updates it using the update() and updateSpecial() methods.
 * The receivedItemId field, which is set in the preUpdate() method of Item, should get stamped during the update() invocation only.
 */
private void updateItem(boolean useSpecial) {
    try {
        String itemId = "Z-TESTITEM-04";
        if (m_uow == null || !m_uow.isActive())
            m_uow = new UOW();
        // Create an item
        Item obj = (Item) m_uow.newPersistentInstance(Item.class);
        obj.setItemId(itemId);
        m_uow.add(obj);
        m_uow.commit();
        // update the item using update() or updateSpecial() methods
        m_uow = new UOW();
        if (!useSpecial) {
            // retrieve the item, and update it
            obj = Item.findByPK(m_uow, itemId);
            obj.setReceivedItemId(null);
            m_uow.update(obj);
        } else {
            // the updateSpecial should work well on both retrieved or 'new' objects
            obj = (Item) m_uow.newPersistentInstance(Item.class);
            obj.setItemId(itemId);
            obj.setReceivedItemId(null);
            m_uow.updateSpecial(obj);
        }
        m_uow.commit();
        // Now retrieve the updated record & check if the receivedItemId got stamped for the update() case only
        m_uow = new UOW();
        obj = Item.findByPK(m_uow, itemId);
        if (!useSpecial)
            assertEquals("UPD" + itemId, obj.getReceivedItemId());
        else
            assertNull("The preUpdate trigger should not have been fired in the special case", obj.getReceivedItemId());
        // Now delete the object
        m_uow.delete(obj);
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : UOW(org.jaffa.persistence.UOW)

Example 45 with UOW

use of org.jaffa.persistence.UOW in project jaffa-framework by jaffa-projects.

the class SpecialAddUpdateDeleteTest method deleteItem.

/**
 * Creates an Item record and deletes it using the delete() and deleteSpecial() methods.
 * The receivedItemId field, which is set in the preDelete() method of Item, should get stamped during the delete() invocation only.
 */
private void deleteItem(boolean useSpecial) {
    try {
        String itemId = "Z-TESTITEM-04";
        if (m_uow == null || !m_uow.isActive())
            m_uow = new UOW();
        // Create an item
        Item obj = (Item) m_uow.newPersistentInstance(Item.class);
        obj.setItemId(itemId);
        m_uow.add(obj);
        m_uow.commit();
        // delete the item using delete() or deleteSpecial() methods
        m_uow = new UOW();
        if (!useSpecial) {
            // retrieve the item, and delete it
            obj = Item.findByPK(m_uow, itemId);
            obj.setReceivedItemId(null);
            m_uow.delete(obj);
        } else {
            // the deleteSpecial should work well on both retrieved or 'new' objects
            obj = (Item) m_uow.newPersistentInstance(Item.class);
            obj.setItemId(itemId);
            obj.setReceivedItemId(null);
            m_uow.deleteSpecial(obj);
        }
        m_uow.commit();
        // Check if the receivedItemId got stamped for the update() case only
        if (!useSpecial)
            assertEquals("DEL" + itemId, obj.getReceivedItemId());
        else
            assertNull("The preDelete trigger should not have been fired in the special case", obj.getReceivedItemId());
        // Ensure that the object has been deleted
        m_uow = new UOW();
        obj = Item.findByPK(m_uow, itemId);
        assertNull("The item record should have been deleted", obj);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : UOW(org.jaffa.persistence.UOW)

Aggregations

UOW (org.jaffa.persistence.UOW)259 Criteria (org.jaffa.persistence.Criteria)138 FrameworkException (org.jaffa.exceptions.FrameworkException)99 ApplicationException (org.jaffa.exceptions.ApplicationException)88 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)87 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)82 Iterator (java.util.Iterator)47 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)33 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)33 ArrayList (java.util.ArrayList)19 Transaction (org.jaffa.transaction.domain.Transaction)19 Map (java.util.Map)16 LinkedHashMap (java.util.LinkedHashMap)13 HashMap (java.util.HashMap)12 DateTime (org.jaffa.datatypes.DateTime)11 FormTemplate (org.jaffa.modules.printing.domain.FormTemplate)10 IPersistent (org.jaffa.persistence.IPersistent)10 Method (java.lang.reflect.Method)9 Collection (java.util.Collection)8 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)8