Package com.google.appengine.datanucleus.test.jpa

Examples of com.google.appengine.datanucleus.test.jpa.TemporalHolder


    int day_of_month = 15;
    int hour_of_day = 5;
    int minute = 10;
    int second = 45;

    TemporalHolder holder = new TemporalHolder(1);
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.YEAR, year);
    cal.set(Calendar.MONTH, month);
    cal.set(Calendar.DAY_OF_MONTH, day_of_month);
    cal.set(Calendar.HOUR_OF_DAY, hour_of_day);
    cal.set(Calendar.MINUTE, minute);
    cal.set(Calendar.SECOND, second);
    cal.set(Calendar.MILLISECOND, 0);
    holder.setDateField(cal.getTime());
    holder.setTimestampField(cal.getTime());
    holder.setTimeField(cal.getTime());

    beginTxn();
    em.persist(holder);
    commitTxn();
    em.clear(); // Clean L1 cache to enforce load from datastore

    // Retrieve and check fields
    beginTxn();
    Query q = em.createQuery("SELECT h FROM TemporalHolder h WHERE id = 1");
    TemporalHolder h = (TemporalHolder)q.getSingleResult();
    Date dateField = h.getDateField();
    Assert.assertEquals("Year of Date incorrect", year, dateField.getYear()+1900);
    Assert.assertEquals("Month of Date incorrect", month, dateField.getMonth());
    Assert.assertEquals("Day of Date incorrect", day_of_month, dateField.getDate());
    Date timeField = h.getTimeField();
    Assert.assertEquals("Hour of Time incorrect", hour_of_day, timeField.getHours());
    Assert.assertEquals("Minute of Time incorrect", minute, timeField.getMinutes());
    Assert.assertEquals("Second of Time incorrect", second, timeField.getSeconds());
    Date timestampField = h.getTimestampField();
    Assert.assertEquals("Year of Timestamp incorrect", year, timestampField.getYear()+1900);
    Assert.assertEquals("Month of Timestamp incorrect", month, timestampField.getMonth());
    Assert.assertEquals("Day of Timestamp incorrect", day_of_month, timestampField.getDate());
    Assert.assertEquals("Hour of Timestamp incorrect", hour_of_day, timestampField.getHours());
    Assert.assertEquals("Minute of Timestamp incorrect", minute, timestampField.getMinutes());
View Full Code Here

TOP

Related Classes of com.google.appengine.datanucleus.test.jpa.TemporalHolder

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.