public void testOffsetDateTime()
{
EierlegendeWollmilchSau ews;
- Long id;
TimeConversions.setZoneOffsetStrategy(new FixedZoneOffsetStrategy(defaultOffset));
ews = new EierlegendeWollmilchSau();
ews.odt = odt;
- id = persist(ews);
- ews = retrieve(id);
+ persist(ews);
+ ews = retrieve(EierlegendeWollmilchSau.class, ews.id);
assertEquals(odt, ews.odt);
TimeConversions.setZoneOffsetStrategy(new FixedZoneOffsetStrategy(otherOffset));
ews = new EierlegendeWollmilchSau();
ews.odt = odt;
- id = persist(ews);
- ews = retrieve(id);
+ persist(ews);
+ ews = retrieve(EierlegendeWollmilchSau.class, ews.id);
assertEquals(odt.toInstant(), ews.odt.toInstant());
}
public void testZonedDateTime()
{
EierlegendeWollmilchSau ews;
- Long id;
TimeConversions.setZoneIdStrategy(new FixedZoneIdStrategy(defaultZone));
ews = new EierlegendeWollmilchSau();
ews.zdt = zdt;
- id = persist(ews);
- ews = retrieve(id);
+ persist(ews);
+ ews = retrieve(EierlegendeWollmilchSau.class, ews.id);
assertEquals(zdt, ews.zdt);
TimeConversions.setZoneIdStrategy(new FixedZoneIdStrategy(otherZone));
ews = new EierlegendeWollmilchSau();
ews.zdt = zdt;
- id = persist(ews);
- ews = retrieve(id);
+ persist(ews);
+ ews = retrieve(EierlegendeWollmilchSau.class, ews.id);
assertEquals(zdt.toInstant(), ews.zdt.toInstant());
}
- private Long persist(EierlegendeWollmilchSau ews)
+ private void persist(Object entity)
{
EntityTransaction tx = em.getTransaction();
tx.begin();
- em.persist(ews);
- log.info("persisting {}", ews);
+ em.persist(entity);
+ log.info("persisting {}", entity);
tx.commit();
em.clear();
- return ews.id;
}
- private EierlegendeWollmilchSau retrieve(Long id)
+ private <T> T retrieve(Class<T> entityClass, Object id)
{
- EierlegendeWollmilchSau ews;
EntityTransaction tx = em.getTransaction();
tx.begin();
- ews = em.find(EierlegendeWollmilchSau.class, id);
- tx.rollback();
- log.info("retrieved {}", ews);
- return ews;
+ try
+ {
+ log.info("retrieving {} of class {}", id, entityClass);
+ return em.find(entityClass, id);
+ }
+ finally
+ {
+ tx.rollback();
+ }
}
}