Search in sources :

Example 36 with Criteria

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

the class AddTest method testCheckRollbackAfterAdd.

/**
 * Inserts a record into SYCI using the query:
 * insert into SYCI(CATEGORY_INSTRUMENT, DESCRIPTION) values('Z-TESTCI-03', 'Z-TESTCIDESC-03').
 * It then does a rollback. This is followed by a commit. The test fails if the record is added.
 */
public void testCheckRollbackAfterAdd() {
    try {
        CategoryOfInstrument obj = (CategoryOfInstrument) m_uow.newPersistentInstance(CategoryOfInstrument.class);
        obj.updateCategoryInstrument("Z-TESTCI-03");
        obj.updateDescription("Z-TESTCIDESC-03");
        m_uow.add(obj);
        m_uow.rollback();
        // Now ensure the record isn't added
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(CategoryOfInstrumentMeta.getName());
        c.addCriteria(CategoryOfInstrumentMeta.CATEGORY_INSTRUMENT, "Z-TESTCI-03");
        Iterator i = m_uow.query(c).iterator();
        if (i.hasNext()) {
            // delete the record & fail the test
            CategoryOfInstrument syci = (CategoryOfInstrument) i.next();
            m_uow.delete(syci);
            m_uow.commit();
            fail("Record has been added 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 37 with Criteria

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

the class AddTest method testCreateCategoryOfInstrumentUsingProxy.

/**
 * Inserts a record into SYCI using the query:
 * insert into SYCI(CATEGORY_INSTRUMENT, DESCRIPTION) values('Z-TESTCI-02', 'Z-TESTCIDESC-02').
 * It then checks if the record was added. Finally the record is deleted
 */
public void testCreateCategoryOfInstrumentUsingProxy() {
    try {
        ICategoryOfInstrument obj = (ICategoryOfInstrument) m_uow.newPersistentInstance(ICategoryOfInstrument.class);
        obj.setCategoryInstrument("Z-TESTCI-02");
        obj.setDescription("Z-TESTCIDESC-02");
        obj.setSupportEquip(Boolean.FALSE);
        m_uow.add(obj);
        m_uow.commit();
        // Now retrieve the added record & check if it was correctly added
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(ICategoryOfInstrument.class.getName());
        c.addCriteria(ICategoryOfInstrument.CATEGORY_INSTRUMENT, "Z-TESTCI-02");
        Iterator i = m_uow.query(c).iterator();
        ICategoryOfInstrument syci = (ICategoryOfInstrument) i.next();
        assertEquals("Z-TESTCI-02", syci.getCategoryInstrument());
        assertEquals("Z-TESTCIDESC-02", syci.getDescription());
        assertEquals(Boolean.FALSE, syci.getSupportEquip());
        assertNull(syci.getCalculateMtbf());
        // Now delete the bugger
        m_uow.delete(syci);
        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 38 with Criteria

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

the class AddTest method testAddWithAutoKey.

/**
 * Inserts a record into ASSET, which has a database generated key
 * It then checks if the record was added. Finally the record is deleted
 */
public void testAddWithAutoKey() {
    try {
        String assetId = "Z-TESTASSET-01";
        DateTime datetime = new DateTime(2003, DateTime.SEPTEMBER, 10, 20, 30, 40, 0);
        Asset obj = (Asset) m_uow.newPersistentInstance(Asset.class);
        obj.updateAssetId(assetId);
        obj.updateCreatedDatetime(datetime);
        m_uow.add(obj);
        m_uow.commit();
        // Now retrieve the added record & check if it was correctly added
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(AssetMeta.getName());
        c.addCriteria(AssetMeta.ASSET_ID, assetId);
        Iterator i = m_uow.query(c).iterator();
        Asset asset = (Asset) i.next();
        assertNotNull(asset.getAssetTk());
        assertEquals(assetId, asset.getAssetId());
        assertEquals(datetime, asset.getCreatedDatetime());
        // Now delete the bugger
        m_uow.delete(asset);
        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) DateTime(org.jaffa.datatypes.DateTime)

Example 39 with Criteria

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

the class AddTest method testCreateCategoryOfInstrument.

/**
 * Inserts a record into SYCI using the query:
 * insert into SYCI(CATEGORY_INSTRUMENT, DESCRIPTION) values('Z-TESTCI-02', 'Z-TESTCIDESC-02').
 * It then checks if the record was added. Finally the record is deleted
 */
public void testCreateCategoryOfInstrument() {
    try {
        CategoryOfInstrument obj = (CategoryOfInstrument) m_uow.newPersistentInstance(CategoryOfInstrument.class);
        obj.updateCategoryInstrument("Z-TESTCI-02");
        obj.updateDescription("Z-TESTCIDESC-02");
        obj.updateSupportEquip(Boolean.FALSE);
        m_uow.add(obj);
        m_uow.commit();
        // Now retrieve the added record & check if it was correctly added
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setTable(CategoryOfInstrumentMeta.getName());
        c.addCriteria(CategoryOfInstrumentMeta.CATEGORY_INSTRUMENT, "Z-TESTCI-02");
        Iterator i = m_uow.query(c).iterator();
        CategoryOfInstrument syci = (CategoryOfInstrument) i.next();
        assertEquals("Z-TESTCI-02", syci.getCategoryInstrument());
        assertEquals("Z-TESTCIDESC-02", syci.getDescription());
        assertEquals(Boolean.FALSE, syci.getSupportEquip());
        assertNull(syci.getCalculateMtbf());
        // Now delete the bugger
        m_uow.delete(syci);
        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 40 with Criteria

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

the class CharFieldTest method testJoinQueryBetweenCharAndVarchar.

/**
 * Tests the sql:
 * Select * from zz_jut_part_additional Where exists
 * (select 1 from zz_jut_part Where zz_jut_part.part = trim(zz_jut_part_additional.part))
 * This should return 1 record
 */
public void testJoinQueryBetweenCharAndVarchar() {
    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 join between PartAdditional and Part
        uow = new UOW();
        Criteria c1 = new Criteria();
        c1.setTable(PartMeta.getName());
        c1.addInnerCriteria(PartMeta.PART, PartAdditionalMeta.PART);
        Criteria c2 = new Criteria();
        c2.setTable(PartAdditionalMeta.getName());
        c2.addAggregate(c1);
        Collection col = uow.query(c2);
        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());
        // Now lets do a join between PartAdditional and Part, and a non-existent record
        c1 = new Criteria();
        c1.setTable(PartMeta.getName());
        c1.addInnerCriteria(PartMeta.PART, PartAdditionalMeta.PART);
        c2 = new Criteria();
        c2.setTable(PartAdditionalMeta.getName());
        c2.addAggregate(c1);
        c2.addCriteria(PartAdditionalMeta.PART, "NON-EXISTENT-PART");
        col = uow.query(c2);
        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)

Aggregations

Criteria (org.jaffa.persistence.Criteria)300 UOW (org.jaffa.persistence.UOW)136 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)124 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)66 Iterator (java.util.Iterator)53 DomainObjectNotFoundException (org.jaffa.exceptions.DomainObjectNotFoundException)39 TransactionCriteria (org.jaffa.transaction.apis.data.TransactionCriteria)32 TransactionFieldCriteria (org.jaffa.transaction.apis.data.TransactionFieldCriteria)32 OrderByField (org.jaffa.components.finder.OrderByField)28 Map (java.util.Map)23 ArrayList (java.util.ArrayList)17 DateTime (org.jaffa.datatypes.DateTime)16 FrameworkException (org.jaffa.exceptions.FrameworkException)14 ApplicationException (org.jaffa.exceptions.ApplicationException)13 DuplicateKeyException (org.jaffa.exceptions.DuplicateKeyException)13 Transaction (org.jaffa.transaction.domain.Transaction)13 Collection (java.util.Collection)12 LinkedHashMap (java.util.LinkedHashMap)11 IPersistent (org.jaffa.persistence.IPersistent)11 HashMap (java.util.HashMap)9