コード例 #1
0
 /**
  * Saves the given field trip to the database.
  *
  * @param trip the field trip
  */
 public static void save(FieldTrip trip) {
   EntityManager em = HomeschoolTracker.getFactory().createEntityManager();
   em.getTransaction().begin();
   em.merge(trip);
   em.getTransaction().commit();
   em.close();
 }
コード例 #2
0
  /**
   * Retrieves field trip details for a given {@link Day}.
   *
   * @param selectedDay the day
   * @return the field trip
   */
  public static FieldTrip get(Date selectedDay) {
    EntityManager em = HomeschoolTracker.getFactory().createEntityManager();
    Query q = em.createQuery("SELECT t FROM FieldTrip t JOIN t._when w WHERE w._date = :when");
    q.setParameter("when", selectedDay);

    FieldTrip result = null;
    if (q.getResultList().size() > 0) {
      result = (FieldTrip) q.getSingleResult();
    }

    em.close();
    return result;
  }