Class MaxKeyGeneratorFactory
- java.lang.Object
-
- org.castor.cpa.persistence.sql.keygen.MaxKeyGeneratorFactory
-
- All Implemented Interfaces:
KeyGeneratorFactory
public final class MaxKeyGeneratorFactory extends java.lang.Object implements KeyGeneratorFactory
MAX key generator factory. The short name of this key generator is "MAX".
It uses the following alrorithm: the maximum value of the primary key is fetched and the correspondent record is locked until the end of transaction, generator returns (max + 1). The lock guarantees that key generators of concurrent transactions will not use this key value, so DuplicateKeyException is impossible. If the table is empty, generator returns 1, no lock is put, DuplicateKeyException is possible.- Version:
- $Revision: 8093 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
- Author:
- Oleg Nitz, Ralf Joachim
- See Also:
MaxKeyGenerator
-
-
Constructor Summary
Constructors Constructor Description MaxKeyGeneratorFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyGeneratorgetKeyGenerator(PersistenceFactory factory, java.util.Properties params, int sqlType)Produce the key generator.java.lang.StringgetKeyGeneratorName()Get the short name of the key generator.
-
-
-
Method Detail
-
getKeyGeneratorName
public java.lang.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:
getKeyGeneratorNamein interfaceKeyGeneratorFactory- Returns:
- Name of the
KeyGeneratorused to identify key generator (types).
-
getKeyGenerator
public KeyGenerator getKeyGenerator(PersistenceFactory factory, java.util.Properties params, int sqlType) throws MappingException
Produce the key generator.- Specified by:
getKeyGeneratorin interfaceKeyGeneratorFactory- 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
KeyGeneratorinstance. - Throws:
MappingException- If there's a problem resolving the mapping information.
-
-