cal.setTime(date);
return cal;
}
public void testMutateCalendarDirties() {
CalendarFields c1 = new CalendarFields();
OpenJPAEntityManager pm;
pm = getPM();
startTx(pm);
pm.persist(c1);
int id = c1.getId();
endTx(pm);
endEm(pm);
pm = getPM();
c1 = pm.find(CalendarFields.class, id);
startTx(pm);
OpenJPAStateManager sm = getStateManager(c1, pm);
assertFalse(sm.getDirty().get(sm.getMetaData().
getField("gmt").getIndex()));
// test setting to same value doesn't dirty the field
/*
setTimeInMillis(c1.getGmtc1.getGmt().getTime().getTime());
c1.getGmt().setTime(c1.getGmt().getTime());
assertFalse(sm.getDirty().get(sm.getMetaData().
getField("gmt").getIndex()));
*/
// test changing time
setTimeInMillis(c1.getGmt(), 12345);
assertTrue(sm.getDirty().get(sm.getMetaData().
getField("gmt").getIndex()));
assertFalse(sm.getDirty().get(sm.getMetaData().
getField("newYork").getIndex()));
// test mutate via "add()" method
c1.getNewYork().add(Calendar.SECOND, -1);
assertTrue(sm.getDirty().get(sm.getMetaData().
getField("newYork").getIndex()));
assertFalse(sm.getDirty().get(sm.getMetaData().
getField("berlin").getIndex()));
// test mutate via "setTimeZone()" method
c1.getBerlin().setTimeZone(TimeZone.getTimeZone("GMT"));
assertTrue(sm.getDirty().get(sm.getMetaData().
getField("berlin").getIndex()));
// Calendar.set can only be subclassed in JDK 1.4+ (it is final in
// 1.3), so we only run this test in JDK 1.4+
if (JavaVersions.VERSION >= 4) {
assertFalse(sm.getDirty().get(sm.getMetaData().
getField("singapore").getIndex()));
// test mutate via "set()" method
c1.getSingapore().set(Calendar.YEAR, 1998);
assertTrue(sm.getDirty().get(sm.getMetaData().
getField("singapore").getIndex()));
}
assertFalse(sm.getDirty().get(sm.getMetaData().
getField("pacific").getIndex()));
// test mutate via "roll()" method
c1.getPacific().roll(Calendar.YEAR, 5);
assertTrue(sm.getDirty().get(sm.getMetaData().
getField("pacific").getIndex()));
endTx(pm);
endEm(pm);