Search in sources :

Example 31 with UOW

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

the class CharFieldTest method testNotNullQuery.

/**
 * Tests the sql:
 * Select * from zz_jut_part_additional where field1 is not null and field1 != ' '
 * This should return 1 record
 */
public void testNotNullQuery() {
    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 field2 is not null. Should get 1 record
        uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(PartAdditionalMeta.getName());
        c.addCriteria(PartAdditionalMeta.FIELD2, Criteria.RELATIONAL_IS_NOT_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 field1 is not null. Nothing should be retrieved
        uow = new UOW();
        c = new Criteria();
        c.setTable(PartAdditionalMeta.getName());
        c.addCriteria(PartAdditionalMeta.FIELD1, Criteria.RELATIONAL_IS_NOT_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);
    }
}
Also used : PartAdditional(org.jaffa.persistence.domainobjects.PartAdditional) Collection(java.util.Collection) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 32 with UOW

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

the class DeleteTest method testCheckRollbackAfterDelete.

/**
 * Deletes a record from SYCD using the following query:
 * delete from sycd WHERE condition='Z-TESTSYCD-03'
 * It then does a rollback. This is followed by a commit.
 * The test fails if the record is deleted.
 */
public void testCheckRollbackAfterDelete() {
    try {
        Criteria c = new Criteria();
        c.setTable(ConditionMeta.getName());
        c.addCriteria(ConditionMeta.CONDITION, "Z-TESTSYCD-03");
        Iterator i = m_uow.query(c).iterator();
        Condition sycd = (Condition) i.next();
        m_uow.delete(sycd);
        m_uow.rollback();
        // Now ensure the record isn't deleted
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(ConditionMeta.getName());
        c.addCriteria(ConditionMeta.CONDITION, "Z-TESTSYCD-03");
        i = m_uow.query(c).iterator();
        if (!i.hasNext())
            fail("Record has been deleted even after a rollback");
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Iterator(java.util.Iterator) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 33 with UOW

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

the class DeleteTest method testCheckRollbackAfterDeleteUsingProxy.

/**
 * Deletes a record from SYCD using the following query:
 * delete from sycd WHERE condition='Z-TESTSYCD-03'
 * It then does a rollback. This is followed by a commit.
 * The test fails if the record is deleted.
 */
public void testCheckRollbackAfterDeleteUsingProxy() {
    try {
        Criteria c = new Criteria();
        c.setTable(ICondition.class.getName());
        c.addCriteria(ICondition.CONDITION, "Z-TESTSYCD-03");
        Iterator i = m_uow.query(c).iterator();
        ICondition sycd = (ICondition) i.next();
        m_uow.delete(sycd);
        m_uow.rollback();
        // Now ensure the record isn't deleted
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(ICondition.class.getName());
        c.addCriteria(ICondition.CONDITION, "Z-TESTSYCD-03");
        i = m_uow.query(c).iterator();
        if (!i.hasNext())
            fail("Record has been deleted even after a rollback");
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Iterator(java.util.Iterator) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 34 with UOW

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

the class DeleteTest method testDeleteCondition.

/**
 * Executes the following query:
 * delete from sycd WHERE condition='Z-TESTSYCD-02'
 * It then ensures that the record was got deleted.
 */
public void testDeleteCondition() {
    try {
        Criteria c = new Criteria();
        c.setTable(ConditionMeta.getName());
        c.addCriteria(ConditionMeta.CONDITION, "Z-TESTSYCD-02");
        Iterator i = m_uow.query(c).iterator();
        Condition sycd = (Condition) i.next();
        String description = sycd.getDescription();
        m_uow.delete(sycd);
        m_uow.commit();
        // Now ensure that the record got deleted
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(ConditionMeta.getName());
        c.addCriteria(ConditionMeta.CONDITION, "Z-TESTSYCD-02");
        i = m_uow.query(c).iterator();
        if (i.hasNext())
            fail();
        // Finally, recreate the record
        m_uow = new UOW();
        sycd = (Condition) m_uow.newPersistentInstance(Condition.class);
        sycd.setCondition("Z-TESTSYCD-02");
        sycd.setDescription(description);
        m_uow.add(sycd);
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Iterator(java.util.Iterator) AtomicCriteria(org.jaffa.persistence.AtomicCriteria) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW)

Example 35 with UOW

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

the class LobTest method testUpdateClob.

/**
 * Creates ZZ_TEST_PART_REMARKS_PICTURE records having clob and blob elements.
 * It then retrieves and updates the rows. Finally it checks if the data has been updated.
 */
public void testUpdateClob() {
    try {
        // create 3 records
        PartRemarksPicture partRemarksPicture = null;
        partRemarksPicture = (PartRemarksPicture) m_uow.newPersistentInstance(PartRemarksPicture.class);
        partRemarksPicture.updatePart("Z-TESTPART-01");
        partRemarksPicture.updateRemarks(CLOB_FIELD + "01");
        partRemarksPicture.updatePicture((BLOB_FIELD + "01").getBytes());
        m_uow.add(partRemarksPicture);
        partRemarksPicture = (PartRemarksPicture) m_uow.newPersistentInstance(PartRemarksPicture.class);
        partRemarksPicture.updatePart("Z-TESTPART-02");
        partRemarksPicture.updateRemarks(CLOB_FIELD + "02");
        partRemarksPicture.updatePicture((BLOB_FIELD + "02").getBytes());
        m_uow.add(partRemarksPicture);
        partRemarksPicture = (PartRemarksPicture) m_uow.newPersistentInstance(PartRemarksPicture.class);
        partRemarksPicture.updatePart("Z-TESTPART-03");
        partRemarksPicture.updateRemarks(CLOB_FIELD + "03");
        partRemarksPicture.updatePicture((BLOB_FIELD + "03").getBytes());
        m_uow.add(partRemarksPicture);
        m_uow.commit();
        // now check if they have been added
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(PartRemarksPictureMeta.getName());
        c.addCriteria(PartRemarksPictureMeta.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z-");
        c.addOrderBy(PartRemarksPictureMeta.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());
        PartRemarksPicture[] partRemarksPictures = (PartRemarksPicture[]) col.toArray(new PartRemarksPicture[0]);
        assertEquals("Z-TESTPART-01", partRemarksPictures[0].getPart());
        assertEquals(CLOB_FIELD + "01", partRemarksPictures[0].getRemarks());
        assertTrue(Arrays.equals((BLOB_FIELD + "01").getBytes(), partRemarksPictures[0].getPicture()));
        assertEquals("Z-TESTPART-02", partRemarksPictures[1].getPart());
        assertEquals(CLOB_FIELD + "02", partRemarksPictures[1].getRemarks());
        assertTrue(Arrays.equals((BLOB_FIELD + "02").getBytes(), partRemarksPictures[1].getPicture()));
        assertEquals("Z-TESTPART-03", partRemarksPictures[2].getPart());
        assertEquals(CLOB_FIELD + "03", partRemarksPictures[2].getRemarks());
        assertTrue(Arrays.equals((BLOB_FIELD + "03").getBytes(), partRemarksPictures[2].getPicture()));
        // now update the records
        partRemarksPictures[0].updateRemarks(null);
        partRemarksPictures[1].updateRemarks("Z-UPDATEDREMARKS-022");
        m_uow.update(partRemarksPictures[0]);
        m_uow.update(partRemarksPictures[1]);
        m_uow.commit();
        // now check if the updates were successful
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(PartRemarksPictureMeta.getName());
        c.addCriteria(PartRemarksPictureMeta.PART, Criteria.RELATIONAL_BEGINS_WITH, "Z-");
        c.addOrderBy(PartRemarksPictureMeta.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());
        partRemarksPictures = (PartRemarksPicture[]) col.toArray(new PartRemarksPicture[0]);
        assertNull(partRemarksPictures[0].getRemarks());
        assertEquals("Z-UPDATEDREMARKS-022", partRemarksPictures[1].getRemarks());
        assertEquals(CLOB_FIELD + "03", partRemarksPictures[2].getRemarks());
        // now delete the records
        m_uow.delete(partRemarksPictures[0]);
        m_uow.delete(partRemarksPictures[1]);
        m_uow.delete(partRemarksPictures[2]);
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Criteria(org.jaffa.persistence.Criteria) 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