Search in sources :

Example 66 with Criteria

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

the class UpdateTest method testUpdateCategoryOfInstrumentUsingProxy.

/**
 * Executes the following query:
 * update syci set description='UPDATED DESC', SUPPORT_EQUIP_B='F', CALCULATE_MTBF_B='T' WHERE CATEGORY_INSTRUMENT='Z-TESTCI-01'
 * It then ensures that the record was properly updated.
 */
public void testUpdateCategoryOfInstrumentUsingProxy() {
    try {
        Criteria c = new Criteria();
        c.setTable(ICategoryOfInstrument.class.getName());
        c.addCriteria(ICategoryOfInstrument.CATEGORY_INSTRUMENT, "Z-TESTCI-01");
        Iterator i = m_uow.query(c).iterator();
        ICategoryOfInstrument syci = (ICategoryOfInstrument) i.next();
        syci.setDescription("UPDATED DESC");
        syci.setSupportEquip(Boolean.FALSE);
        syci.setCalculateMtbf(Boolean.TRUE);
        m_uow.update(syci);
        m_uow.commit();
        // Now ensure that the record got updated
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(ICategoryOfInstrument.class.getName());
        c.addCriteria(ICategoryOfInstrument.CATEGORY_INSTRUMENT, "Z-TESTCI-01");
        i = m_uow.query(c).iterator();
        syci = (ICategoryOfInstrument) i.next();
        assertEquals("UPDATED DESC", syci.getDescription());
        assertEquals(Boolean.FALSE, syci.getSupportEquip());
        assertEquals(Boolean.TRUE, syci.getCalculateMtbf());
    } 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 67 with Criteria

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

the class UpdateTest method testCheckRollbackAfterUpdate.

/**
 * Executes the following query:
 * update syci set description='AFTER ROLLBACK' WHERE CATEGORY_INSTRUMENT='Z-TESTCI-01'
 * It then does a rollback. This is followed by a commit.
 * The test fails if the record is updated.
 */
public void testCheckRollbackAfterUpdate() {
    try {
        Criteria c = new Criteria();
        c.setTable(CategoryOfInstrumentMeta.getName());
        c.addCriteria(CategoryOfInstrumentMeta.CATEGORY_INSTRUMENT, "Z-TESTCI-01");
        Iterator i = m_uow.query(c).iterator();
        CategoryOfInstrument syci = (CategoryOfInstrument) i.next();
        String originalDescription = syci.getDescription();
        syci.updateDescription("AFTER ROLLBACK");
        m_uow.update(syci);
        m_uow.rollback();
        // Now ensure the record isn't updated
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(CategoryOfInstrumentMeta.getName());
        c.addCriteria(CategoryOfInstrumentMeta.CATEGORY_INSTRUMENT, "Z-TESTCI-01");
        i = m_uow.query(c).iterator();
        syci = (CategoryOfInstrument) i.next();
        assertEquals("Record has been updated even after a rollback", originalDescription, syci.getDescription());
    } 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 68 with Criteria

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

the class UpdateTest method testUpdateUsingQuote.

/**
 * Executes the following query:
 * update syci set description='JOHN'S DESC' WHERE CATEGORY_INSTRUMENT='Z-TESTCI-01'
 * It then ensures that the record was properly updated and resets the description to the old value.
 */
public void testUpdateUsingQuote() {
    try {
        String category = "Z-TESTCI-01";
        String newDesc = "DE'SC WI'TH Q'UOTES'";
        String oldDesc = null;
        Criteria c = new Criteria();
        c.setTable(CategoryOfInstrumentMeta.getName());
        c.addCriteria(CategoryOfInstrumentMeta.CATEGORY_INSTRUMENT, category);
        Iterator i = m_uow.query(c).iterator();
        CategoryOfInstrument syci = (CategoryOfInstrument) i.next();
        oldDesc = syci.getDescription();
        syci.updateDescription(newDesc);
        m_uow.update(syci);
        m_uow.commit();
        // Now ensure that the record got updated
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(CategoryOfInstrumentMeta.getName());
        c.addCriteria(CategoryOfInstrumentMeta.DESCRIPTION, newDesc);
        i = m_uow.query(c).iterator();
        syci = (CategoryOfInstrument) i.next();
        assertEquals(category, syci.getCategoryInstrument());
        assertEquals(newDesc, syci.getDescription());
        // Reset to the original value
        syci.updateDescription(oldDesc);
        m_uow.update(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 69 with Criteria

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

the class UpdateTest method testUpdateLongUsingProxy.

/**
 * Updates a CATZ using the query:
 * update catz set REMARKS = some 10,000 character string WHERE PART='Z-TESTPART-01'
 * It then ensures that the record was properly updated.
 */
public void testUpdateLongUsingProxy() {
    try {
        String longString = LONG_FIELD + '\n' + LONG_FIELD;
        Criteria c = new Criteria();
        c.setTable(IPartRemarks.class.getName());
        c.addCriteria(IPartRemarks.PART, "Z-TESTPART-01");
        Iterator i = m_uow.query(c).iterator();
        IPartRemarks catz = (IPartRemarks) i.next();
        catz.setRemarks(longString);
        m_uow.update(catz);
        m_uow.commit();
        // Now ensure that the record got updated
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(IPartRemarks.class.getName());
        c.addCriteria(IPartRemarks.PART, "Z-TESTPART-01");
        i = m_uow.query(c).iterator();
        catz = (IPartRemarks) i.next();
        assertEquals(longString, catz.getRemarks());
    } 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 70 with Criteria

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

the class UpdateTest method testUpdateDateTimeUsingProxy.

/**
 * Executes the following query:
 * update item set created_datetime=to_date('2003-10-10', 'yyyy-MM-dd') where item_id='Z-TESTITEM-01'
 * It then ensures that the record was properly updated and then resets it back to the original value
 */
public void testUpdateDateTimeUsingProxy() {
    try {
        Criteria c = new Criteria();
        c.setTable(IItem.class.getName());
        c.addCriteria(IItem.ITEM_ID, "Z-TESTITEM-01");
        Iterator i = m_uow.query(c).iterator();
        IItem item = (IItem) i.next();
        DateTime originalCreatedDatetime = item.getCreatedDatetime();
        DateTime newCreatedDatetime = new DateTime(2003, DateTime.OCTOBER, 10);
        item.setCreatedDatetime(newCreatedDatetime);
        m_uow.update(item);
        m_uow.commit();
        // Now ensure that the record got updated
        m_uow = new UOW();
        c = new Criteria();
        c.setTable(IItem.class.getName());
        c.addCriteria(IItem.ITEM_ID, "Z-TESTITEM-01");
        i = m_uow.query(c).iterator();
        item = (IItem) i.next();
        assertEquals(newCreatedDatetime, item.getCreatedDatetime());
        // Now reset to the original value
        item.setCreatedDatetime(originalCreatedDatetime);
        m_uow.update(item);
        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)

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