Klasse IDBroker

java.lang.Object
org.apache.torque.oid.IDBroker
Alle implementierten Schnittstellen:
Runnable, IdGenerator

public class IDBroker extends Object implements Runnable, IdGenerator
This method of ID generation is used to ensure that code is more database independent. For example, MySQL has an auto-increment feature while Oracle uses sequences. It caches several ids to avoid needing a Connection for every request. This class uses the table ID_TABLE defined in conf/master/id-table-schema.xml. The columns in ID_TABLE are used as follows:
ID_TABLE_ID - The PK for this row (any unique int).
TABLE_NAME - The name of the table you want ids for.
NEXT_ID - The next id returned by IDBroker when it queries the database (not when it returns an id from memory).
QUANTITY - The number of ids that IDBroker will cache in memory.

Use this class like this:

 int id = dbMap.getIDBroker().getNextIdAsInt(null, "TABLE_NAME");
  - or -
 BigDecimal[] ids = ((IDBroker)dbMap.getIDBroker())
     .getNextIds("TABLE_NAME", numOfIdsToReturn);
 
NOTE: When the ID_TABLE must be updated we must ensure that IDBroker objects running in different JVMs do not overwrite each other. This is accomplished using using the transactional support occuring in some databases. Using this class with a database that does not support transactions should be limited to a single JVM.
Version:
$Id: IDBroker.java 1917245 2024-04-21 14:06:23Z tv $
Autor:
Frank Y. Kim, John D. McNally, Henning P. Schmiedehausen
  • Felddetails

  • Konstruktordetails

    • IDBroker

      public IDBroker(Database database)
      Constructs an IdBroker for the given Database.
      Parameter:
      database - the database where this IdBroker is running in.
  • Methodendetails