Package org.apache.art

Examples of org.apache.art.DateTestEntity


        ObjectContext context = createDataContext();
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);

        DateTestEntity o1 = context.newObject(DateTestEntity.class);
        cal.set(year - 3, 1, 1);
        o1.setDateColumn(cal.getTime());

        DateTestEntity o2 = context.newObject(DateTestEntity.class);
        cal.set(year + 3, 1, 1);
        o2.setDateColumn(cal.getTime());

        context.commitChanges();

        EJBQLQuery query = new EJBQLQuery(
                "SELECT d FROM DateTestEntity d WHERE d.dateColumn > CURRENT_DATE");
View Full Code Here


        ObjectContext context = createDataContext();
        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);

        DateTestEntity o1 = context.newObject(DateTestEntity.class);
        cal.set(year, 1, 1, 0, 0, 0);
        o1.setTimeColumn(cal.getTime());

        DateTestEntity o2 = context.newObject(DateTestEntity.class);
        cal.set(year, 1, 1, 23, 59, 59);
        o2.setTimeColumn(cal.getTime());

        context.commitChanges();

        EJBQLQuery query = new EJBQLQuery(
                "SELECT d FROM DateTestEntity d WHERE d.timeColumn < CURRENT_TIME");
View Full Code Here

        Calendar cal = Calendar.getInstance();
        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH);
        int date = cal.get(Calendar.DATE);

        DateTestEntity o1 = context.newObject(DateTestEntity.class);
        cal.set(year, month, date, 0, 0, 0);
        o1.setTimestampColumn(cal.getTime());

        DateTestEntity o2 = context.newObject(DateTestEntity.class);
        cal.set(year, month, date, 23, 59, 59);
        o2.setTimestampColumn(cal.getTime());

        context.commitChanges();

        EJBQLQuery query = new EJBQLQuery(
                "SELECT d FROM DateTestEntity d WHERE d.timestampColumn < CURRENT_TIMESTAMP");
View Full Code Here

        test.setCalendarField(null);
        context.commitChanges();
    }

    public void testDate() throws Exception {
        DateTestEntity test = (DateTestEntity) context.newObject("DateTestEntity");

        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(2002, 1, 1);
        Date nowDate = cal.getTime();
        test.setDateColumn(nowDate);
        context.commitChanges();

        SelectQuery q = new SelectQuery(DateTestEntity.class);
        DateTestEntity testRead = (DateTestEntity) context.performQuery(q).get(0);
        assertNotNull(testRead.getDateColumn());
        assertEquals(nowDate, testRead.getDateColumn());
    }
View Full Code Here

        assertNotNull(testRead.getDateColumn());
        assertEquals(nowDate, testRead.getDateColumn());
    }

    public void testTime() throws Exception {
        DateTestEntity test = (DateTestEntity) context.newObject("DateTestEntity");

        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(1970, 0, 1, 1, 20, 30);
        Date nowTime = cal.getTime();
        test.setTimeColumn(nowTime);
        context.commitChanges();

        SelectQuery q = new SelectQuery(DateTestEntity.class);
        DateTestEntity testRead = (DateTestEntity) context.performQuery(q).get(0);
        assertNotNull(testRead.getTimeColumn());

        // OpenBase fails to store seconds for the time
        // FrontBase returns time with 1 hour offset (I guess "TIME WITH TIMEZONE" may
        // need to be used as a default FB type?)
        // so this test is approximate...

        long delta = nowTime.getTime() - testRead.getTimeColumn().getTime();
        assertTrue("" + delta, Math.abs(delta) <= 1000 * 60 * 60);
    }
View Full Code Here

        long delta = nowTime.getTime() - testRead.getTimeColumn().getTime();
        assertTrue("" + delta, Math.abs(delta) <= 1000 * 60 * 60);
    }

    public void testTimestamp() throws Exception {
        DateTestEntity test = (DateTestEntity) context.newObject("DateTestEntity");

        Calendar cal = Calendar.getInstance();
        cal.clear();
        cal.set(2003, 1, 1, 1, 20, 30);

        // most databases fail millisecond accuracy
        // cal.set(Calendar.MILLISECOND, 55);

        Date now = cal.getTime();
        test.setTimestampColumn(now);
        context.commitChanges();

        SelectQuery q = new SelectQuery(DateTestEntity.class);
        DateTestEntity testRead = (DateTestEntity) context.performQuery(q).get(0);
        assertNotNull(testRead.getTimestampColumn());
        assertEquals(now, testRead.getTimestampColumn());
    }
View Full Code Here

TOP

Related Classes of org.apache.art.DateTestEntity

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.