Search in sources :

Example 51 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class FunctionTest method testObtainCurrentDateTime.

/**
 * Tests the current DateTime from the server
 */
public void testObtainCurrentDateTime() {
    try {
        Criteria c = new Criteria();
        c.addFunction(Criteria.FUNCTION_CURRENT_DATE_TIME, null, "cdt");
        DateTime localValue = new DateTime();
        Map m = (Map) m_uow.query(c).iterator().next();
        DateTime dbValue = (DateTime) m.get("cdt");
        assertEquals("Year on the database server does not match the current value", localValue.year(), dbValue.year());
        assertEquals("Month on the database server does not match the current value", localValue.month(), dbValue.month());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : Criteria(org.jaffa.persistence.Criteria) Map(java.util.Map) DateTime(org.jaffa.datatypes.DateTime)

Example 52 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class HitlistTest method testHitlist.

/**
 * This creates 123 Item records. It then retrieves them. After reading each record, the size of the Collection will be checked.
 * The size will increment in steps of hitlist size (which is assumed to be 10). The size will be negative, until all the records have been fetched.
 */
public void testHitlist() {
    try {
        int rows = 123;
        int hitlistSize = 10;
        String itemIdPrefix = "ZZ-HIT-LIST-";
        DateTime createdDateTime = new DateTime();
        // create items
        for (int i = 1; i <= rows; i++) {
            Item item = (Item) m_uow.newPersistentInstance(Item.class);
            item.updateItemId(itemIdPrefix + i);
            item.updateQty(new Long(i));
            item.updateCreatedDatetime(createdDateTime);
            m_uow.add(item);
        }
        m_uow.commit();
        // now retrieve the items
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setLocking(Criteria.LOCKING_PARANOID);
        c.setTable(ItemMeta.getName());
        c.addCriteria(ItemMeta.ITEM_ID, Criteria.RELATIONAL_BEGINS_WITH, itemIdPrefix);
        c.addOrderBy(ItemMeta.QTY, Criteria.ORDER_BY_ASC);
        Collection items = m_uow.query(c);
        assertEquals(-hitlistSize, items.size());
        int i = 0;
        for (Iterator itr = items.iterator(); itr.hasNext(); ) {
            ++i;
            Item item = (Item) itr.next();
            assertEquals(itemIdPrefix + i, item.getItemId());
            assertEquals(new Long(i), item.getQty());
            assertEquals(createdDateTime.toString(), item.getCreatedDatetime().toString());
            // hitlist checks
            if (i == rows) {
                assertEquals(rows, items.size());
            } else if (i % hitlistSize == 0) {
                assertEquals(-i, items.size());
            } else {
                int expectedSize = i - (i % hitlistSize) + hitlistSize;
                if (expectedSize >= rows)
                    assertEquals(rows, items.size());
                else
                    assertEquals(-expectedSize, items.size());
            }
        }
        // one final check.. to ensure that all the records were retrieved
        assertEquals(rows, items.size());
        // now delete the records
        for (Iterator itr = items.iterator(); itr.hasNext(); ) m_uow.delete((IPersistent) itr.next());
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : IPersistent(org.jaffa.persistence.IPersistent) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW) DateTime(org.jaffa.datatypes.DateTime)

Example 53 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class HitlistTest method testHitlistUsingProxy.

/**
 * This creates 123 Item records. It then retrieves them. After reading each record, the size of the Collection will be checked.
 * The size will increment in steps of hitlist size (which is assumed to be 10). The size will be negative, until all the records have been fetched.
 */
public void testHitlistUsingProxy() {
    try {
        int rows = 123;
        int hitlistSize = 10;
        String itemIdPrefix = "ZZ-HIT-LIST-";
        DateTime createdDateTime = new DateTime();
        // create items
        for (int i = 1; i <= rows; i++) {
            IItem item = (IItem) m_uow.newPersistentInstance(IItem.class);
            item.setItemId(itemIdPrefix + i);
            item.setQty(new Long(i));
            item.setCreatedDatetime(createdDateTime);
            m_uow.add(item);
        }
        m_uow.commit();
        // now retrieve the items
        m_uow = new UOW();
        Criteria c = new Criteria();
        c.setLocking(Criteria.LOCKING_PARANOID);
        c.setTable(IItem.class.getName());
        c.addCriteria(IItem.ITEM_ID, Criteria.RELATIONAL_BEGINS_WITH, itemIdPrefix);
        c.addOrderBy(IItem.QTY, Criteria.ORDER_BY_ASC);
        Collection items = m_uow.query(c);
        assertEquals(-hitlistSize, items.size());
        int i = 0;
        for (Iterator itr = items.iterator(); itr.hasNext(); ) {
            ++i;
            IItem item = (IItem) itr.next();
            assertEquals(itemIdPrefix + i, item.getItemId());
            assertEquals(new Long(i), item.getQty());
            assertEquals(createdDateTime.toString(), item.getCreatedDatetime().toString());
            // hitlist checks
            if (i == rows) {
                assertEquals(rows, items.size());
            } else if (i % hitlistSize == 0) {
                assertEquals(-i, items.size());
            } else {
                int expectedSize = i - (i % hitlistSize) + hitlistSize;
                if (expectedSize >= rows)
                    assertEquals(rows, items.size());
                else
                    assertEquals(-expectedSize, items.size());
            }
        }
        // one final check.. to ensure that all the records were retrieved
        assertEquals(rows, items.size());
        // now delete the records
        for (Iterator itr = items.iterator(); itr.hasNext(); ) m_uow.delete((IPersistent) itr.next());
        m_uow.commit();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : IPersistent(org.jaffa.persistence.IPersistent) Criteria(org.jaffa.persistence.Criteria) UOW(org.jaffa.persistence.UOW) DateTime(org.jaffa.datatypes.DateTime)

Example 54 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class QueryTest method testBasicQuery.

/**
 * Tests the sql:
 * Select * from item where item_id like 'Z-TEST%'
 * and condition like '%TESTSYCD%'
 * and part = 'Z-TESTPART-01�
 * and sc is not null
 * and qty > 1 and qty < 3
 * and key_ref like '%TEST-KEY-REF'
 * order by item_id
 * This should return 3 item records
 */
public void testBasicQuery() {
    try {
        Criteria c = new Criteria();
        c.setTable(ItemMeta.getName());
        c.addCriteria(ItemMeta.ITEM_ID, Criteria.RELATIONAL_BEGINS_WITH, "Z-TEST");
        c.addCriteria(ItemMeta.CONDITION, Criteria.RELATIONAL_LIKE, "TESTSYCD");
        c.addCriteria(ItemMeta.PART, "Z-TESTPART-01");
        c.addCriteria(ItemMeta.SC, Criteria.RELATIONAL_IS_NOT_NULL);
        c.addCriteria(ItemMeta.QTY, Criteria.RELATIONAL_GREATER_THAN, new Long(1));
        c.addCriteria(ItemMeta.QTY, Criteria.RELATIONAL_SMALLER_THAN, new Long(3));
        c.addCriteria(ItemMeta.KEY_REF, Criteria.RELATIONAL_ENDS_WITH, "TEST-KEY-REF");
        c.addOrderBy(ItemMeta.ITEM_ID, Criteria.ORDER_BY_ASC);
        // The following criteria points to an undefined mapping, and should be ignored and not cause any exception
        c.addCriteria("UnmappedField", "ZZZZ");
        Iterator i = m_uow.query(c).iterator();
        Item item = null;
        item = ((Item) i.next());
        assertEquals("Z-TESTITEM-01", item.getItemId());
        assertEquals("SOME SC", item.getSc());
        assertEquals("Z-TESTPART-01", item.getPart());
        assertEquals("Z-TESTPRIME-01", item.getPrime());
        assertEquals("Z-TESTSYCD-01", item.getCondition());
        assertEquals(2, item.getQty().intValue());
        assertEquals(new DateTime(2003, DateTime.SEPTEMBER, 10, 20, 30, 40, 0), item.getCreatedDatetime());
        item = ((Item) i.next());
        assertEquals("Z-TESTITEM-02", item.getItemId());
        assertEquals("SOME SC", item.getSc());
        assertEquals("Z-TESTPART-01", item.getPart());
        assertEquals("Z-TESTPRIME-01", item.getPrime());
        assertEquals("Z-TESTSYCD-01", item.getCondition());
        assertEquals(2, item.getQty().intValue());
        assertEquals(new DateTime(2003, DateTime.SEPTEMBER, 10), item.getCreatedDatetime());
        item = ((Item) i.next());
        assertEquals("Z-TESTITEM-03", item.getItemId());
        assertEquals("SOME SC", item.getSc());
        assertEquals("Z-TESTPART-01", item.getPart());
        assertEquals("Z-TESTPRIME-01", item.getPrime());
        assertEquals("Z-TESTSYCD-01", item.getCondition());
        assertEquals(2, item.getQty().intValue());
        assertNull(item.getCreatedDatetime());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DateTime(org.jaffa.datatypes.DateTime)

Example 55 with DateTime

use of org.jaffa.datatypes.DateTime in project jaffa-framework by jaffa-projects.

the class QueryTest method testDateTimeQueryUsingProxy.

/**
 * Tests the sql:
 * Select * from item Where
 * created_datetime = to_date('2003-09-10 20:30:40', 'yyyy-MM-dd hh24:mi:ss')
 * or created_datetime = to_date('2003-09-10', 'yyyy-MM-dd')
 * or created_datetime is null
 * order by item_id
 * This should return 3 item records
 */
public void testDateTimeQueryUsingProxy() {
    try {
        Criteria c = new Criteria();
        c.addCriteria(IItem.CREATED_DATETIME, new DateTime(2003, DateTime.SEPTEMBER, 10, 20, 30, 40, 0));
        c.addOrCriteria(IItem.CREATED_DATETIME, new DateTime(2003, DateTime.SEPTEMBER, 10));
        c.addOrCriteria(IItem.CREATED_DATETIME, Criteria.RELATIONAL_IS_NULL);
        c.setTable(IItem.class.getName());
        c.addOrderBy(IItem.ITEM_ID, Criteria.ORDER_BY_ASC);
        Iterator i = m_uow.query(c).iterator();
        IItem item = (IItem) i.next();
        assertEquals("Z-TESTITEM-01", item.getItemId());
        assertEquals(new DateTime(2003, DateTime.SEPTEMBER, 10, 20, 30, 40, 0), item.getCreatedDatetime());
        item = ((IItem) i.next());
        assertEquals("Z-TESTITEM-02", item.getItemId());
        assertEquals(new DateTime(2003, DateTime.SEPTEMBER, 10), item.getCreatedDatetime());
        item = ((IItem) i.next());
        assertNull(item.getCreatedDatetime());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DateTime(org.jaffa.datatypes.DateTime)

Aggregations

DateTime (org.jaffa.datatypes.DateTime)74 Criteria (org.jaffa.persistence.Criteria)16 UOW (org.jaffa.persistence.UOW)11 AtomicCriteria (org.jaffa.persistence.AtomicCriteria)9 PreparedStatement (java.sql.PreparedStatement)8 ValidationException (org.jaffa.datatypes.ValidationException)8 ApplicationExceptions (org.jaffa.exceptions.ApplicationExceptions)8 Iterator (java.util.Iterator)7 Map (java.util.Map)5 Date (java.util.Date)4 FrameworkException (org.jaffa.exceptions.FrameworkException)4 LinkedHashMap (java.util.LinkedHashMap)3 JMSException (javax.jms.JMSException)3 MarshallException (org.directwebremoting.extend.MarshallException)3 CheckBoxModel (org.jaffa.presentation.portlet.widgets.model.CheckBoxModel)3 DateTimeModel (org.jaffa.presentation.portlet.widgets.model.DateTimeModel)3 DropDownModel (org.jaffa.presentation.portlet.widgets.model.DropDownModel)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Enumeration (java.util.Enumeration)2 LinkedList (java.util.LinkedList)2