001package io.ebean.config.dbplatform;
002
003import io.ebean.Transaction;
004
005/**
006 * Generates unique id's for objects. This occurs prior to the actual insert.
007 * <p>
008 * Note that many databases have sequences or auto increment features. These can
009 * be used rather than an IdGenerator and are different in that they occur
010 * during an insert. IdGenerator is used to generate an id <em>BEFORE</em> the
011 * actual insert.
012 * </p>
013 */
014public interface PlatformIdGenerator {
015
016  /**
017   * The name of the default UUID generator.
018   */
019  String AUTO_UUID = "auto.uuid";
020
021  /**
022   * Return the name of the IdGenerator. For sequences this is the sequence
023   * name.
024   */
025  String getName();
026
027  /**
028   * Return true if this is a DB sequence.
029   */
030  boolean isDbSequence();
031
032  /**
033   * return the next unique identity value.
034   * <p>
035   * Note the transaction passed in can be null.
036   * </p>
037   */
038  Object nextId(Transaction transaction);
039
040  /**
041   * Is called prior to inserting OneToMany's as an indication that a number of
042   * beans are likely to need id's shortly.
043   * <p>
044   * Can be used as a performance optimisation to prefetch a number of Id's.
045   * Especially when the allocateSize is very large.
046   * </p>
047   */
048  void preAllocateIds(int allocateSize);
049
050}