Class SequenceKeyGeneratorFactory

java.lang.Object
org.castor.cpa.persistence.sql.keygen.SequenceKeyGeneratorFactory
All Implemented Interfaces:
KeyGeneratorFactory

public final class SequenceKeyGeneratorFactory extends Object implements KeyGeneratorFactory
SEQUENCE key generator factory. The short name of this key generator is "SEQUENCE".
It uses Oracle/PostrgeSQL SEQUENCEs. There are two optional parameters for this key generator:
  • 1) name is "sequence" and the default value is "{0}_seq";
  • 2) name is "returning", values: "true"/"false", default is "false".
The latter parameter should be used only with Oracle8i, "true" value turns on more efficient RETURNING syntax. It is possible to use naming patterns like this to obtain SEQUENCE name by table name. This gives the possibility to use one global key generator declaration rather than one per table.
Version:
$Revision: 8317 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
Author:
Oleg Nitz, Ralf Joachim
  • Constructor Details

    • SequenceKeyGeneratorFactory

      public SequenceKeyGeneratorFactory()
  • Method Details

    • getKeyGeneratorName

      public String getKeyGeneratorName()
      Get the short name of the key generator. It is used to reference key generators in a mapping configuration file. If several key generators of the same type are used for the same database, then they are referenced by aliases.
      Specified by:
      getKeyGeneratorName in interface KeyGeneratorFactory
      Returns:
      Name of the KeyGenerator used to identify key generator (types).
    • getKeyGenerator

      public KeyGenerator getKeyGenerator(PersistenceFactory factory, Properties params, int sqlType) throws MappingException
      Produce the key generator.
      Specified by:
      getKeyGenerator in interface KeyGeneratorFactory
      Parameters:
      factory - Helper object for obtaining database-specific QuerySyntax.
      params - Parameters for key generator.
      sqlType - The SQL type of the primary key, the generated identities must have the corresponding Java type, e.g. java.sql.Types.INTEGER corresponds to java.lang.Integer, java.sql.Types.NUMERIC corresponds to java.lang.BigDecimal.
      Returns:
      A KeyGenerator instance.
      Throws:
      MappingException - If there's a problem resolving the mapping information.