Beispiel #1
0
  /**
   * Get a table penalties.
   *
   * @param table
   * @return the table's penalties, never null.
   */
  @SuppressWarnings("unchecked")
  public static List<Penalty> getByTable(Table table) throws FatalException {

    Session s = HibernateUtil.getSession();
    Query q = s.createQuery("select p from Table as t inner join t.penalty as p where t = :table");
    q.setParameter("table", table);

    return (List<Penalty>) q.list();
  }
Beispiel #2
0
  /**
   * Add/update a table's penalty.
   *
   * @param table
   * @param penalties
   */
  public static void addOrUpdateAll(Table table) throws FatalException {

    // delete penalties for which values are all null
    List<Penalty> tablePenalties = table.getPenalties();
    for (Iterator<Penalty> iterator = tablePenalties.iterator(); iterator.hasNext(); ) {
      Penalty penalty = (Penalty) iterator.next();
      if (penalty != null
          && penalty.getPenaltyPlayer1() == null
          && penalty.getPenaltyPlayer2() == null
          && penalty.getPenaltyPlayer3() == null
          && penalty.getPenaltyPlayer4() == null) {
        iterator.remove();
      }
    }

    HibernateUtil.save(table);
  }
Beispiel #3
0
  /**
   * Remove a table's penalty.
   *
   * @param table
   * @param penalty
   * @throws FatalException
   */
  public static void deleteAll(Table table) throws FatalException {
    List<Penalty> tablePenalties = table.getPenalties();
    tablePenalties.clear();

    HibernateUtil.save(table);
  }