Esempio n. 1
0
  /**
   * Actually gets the next id Gets the object of type ID from the database with the specific name.
   * Then increment the id value and returns. If object does not exist, creates t.
   *
   * @param idName
   * @return
   */
  @SuppressWarnings("unchecked")
  private long getNextId(String className) {
    ODB odb = getOdb();

    Objects objects =
        odb.getObjects(new CriteriaQuery(Sequence.class, Where.equal("className", className)));

    if (objects.isEmpty()) {
      Sequence sequence = new Sequence();
      sequence.setClassName(className);
      sequence.setId(1L);

      odb.store(sequence);

      return 1L;
    }

    Sequence sequence = (Sequence) objects.getFirst();

    sequence.increment();

    odb.store(sequence);

    return sequence.getId();
  }