Search in sources :

Example 26 with UOW

use of org.jaffa.persistence.UOW 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 27 with UOW

use of org.jaffa.persistence.UOW 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 28 with UOW

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

the class CharFieldTest method testDelete.

/**
 * Deletes a new record.
 */
public void testDelete() {
    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();
        // Now ensure that the record got created
        uow = new UOW();
        object = PartAdditional.findByPK(uow, PART);
        assertNotNull("A PartAdditional object should have been created", object);
        assertEquals(PART, object.getPart());
        // Delete the bugger
        uow.delete(object);
        uow.commit();
        // Now ensure that the record got deleted
        uow = new UOW();
        object = PartAdditional.findByPK(uow, PART);
        assertNull("A PartAdditional object should have been deleted", object);
    } 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) UOW(org.jaffa.persistence.UOW)

Example 29 with UOW

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

the class CharFieldTest method testUpdate.

/**
 * Updates a record.
 */
public void testUpdate() {
    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();
        // Now ensure that the record got created
        uow = new UOW();
        object = PartAdditional.findByPK(uow, PART);
        assertNotNull("A PartAdditional object should have been created", object);
        assertEquals(PART, object.getPart());
        // Update the object
        object.setField1("NEW VALUE");
        object.setField2("");
        object.setField3("  ");
        uow.update(object);
        uow.commit();
        // Now ensure that the record got updated
        uow = new UOW();
        object = PartAdditional.findByPK(uow, PART);
        assertNotNull("A PartAdditional object should have been updated", object);
        assertEquals(PART, object.getPart());
        assertEquals("NEW VALUE", object.getField1());
        assertNull(object.getField2());
        assertNull(object.getField3());
    } 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) UOW(org.jaffa.persistence.UOW)

Example 30 with UOW

use of org.jaffa.persistence.UOW 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

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