org.exolab.castor.persist.spi
Interface KeyGenerator
- HighLowKeyGenerator, IdentityKeyGenerator, MaxKeyGenerator, SequenceKeyGenerator, UUIDKeyGenerator
public interface KeyGenerator
Interface for a key generator. The key generator is used for
producing identities for objects before they are created in the
database.
All the key generators belonging to the same database share the
same non-transactional connection to the database.
The key generator is configured from the mapping file using
Bean-like accessor methods.
$Revision: 1.1.1.1 $ $Date: 2003/03/03 07:08:51 $static byte | AFTER_INSERT - For the key generators of AFTER_INSERT style
generateKey(Connection,String,String,Properties)
is called after INSERT.
|
static byte | BEFORE_INSERT - For the key generators of BEFORE_INSERT style
generateKey(Connection,String,String,Properties)
is called before INSERT.
|
static byte | DURING_INSERT - For the key generators of DURING_INSERT style
generateKey(Connection,String,String,Properties)
is never called, all work is done by patchSQL(String,String) .
|
Object | generateKey(Connection conn, String tableName, String primKeyName, Properties props) - Generate a new key for the specified table.
|
byte | getStyle() - Style of the key generator: BEFORE_INSERT, DURING_INSERT or AFTER_INSERT.
|
boolean | isInSameConnection() - Is key generated in the same connection as INSERT?
For DURING_INSERT style this method is never called.
|
String | patchSQL(String insert, String primKeyName) - Gives a possibility to patch the Castor-generated SQL statement
for INSERT (indended mainly for DURING_INSERT style of key generators,
other key generators usually simply return the passed parameter).
|
AFTER_INSERT
public static final byte AFTER_INSERT
BEFORE_INSERT
public static final byte BEFORE_INSERT
DURING_INSERT
public static final byte DURING_INSERT
generateKey
public Object generateKey(Connection conn,
String tableName,
String primKeyName,
Properties props)
throws PersistenceException
Generate a new key for the specified table. This method is
called when a new object is about to be created. In some
environments the name of the owner of the object is known,
e.g. the principal in a J2EE server.
This method is never called for DURING_INSERT key generators.
conn
- An open connection within the given transactiontableName
- The table nameprimKeyName
- The primary key nameprops
- A temporary replacement for Principal object
getStyle
public byte getStyle()
Style of the key generator: BEFORE_INSERT, DURING_INSERT or AFTER_INSERT.
isInSameConnection
public boolean isInSameConnection()
Is key generated in the same connection as INSERT?
For DURING_INSERT style this method is never called.
patchSQL
public String patchSQL(String insert,
String primKeyName)
throws MappingException
Gives a possibility to patch the Castor-generated SQL statement
for INSERT (indended mainly for DURING_INSERT style of key generators,
other key generators usually simply return the passed parameter).
The original statement contains primary key column on the first place
for BEFORE_INSERT style and doesn't contain it for the other styles.
This method is called once for each class and must return String
with '?' that can be passed to CallableStatement (for DURING_INSERT
style) or to PreparedStatement (for the others).
Then for each record being created actual field values are substituted,
starting from the primary key value for BEFORE_INSERT style, of starting
from the first of other fields for the other styles.
The DURING_INSERT key generator must add one OUT parameter to the end
of the parameter list, which will return the generated identity.
For example, ReturningKeyGenerator for Oracle8i transforms
"INSERT INTO tbl (pk, fld1, ...,fldN) VALUES (?,?...,?)" to
"INSERT INTO tbl (pk, fld1, ...) VALUES (seq.nextval,?....,?)
RETURNING pk INTO ?".
DURING_INSERT key generator also may be implemented as a stored procedure.
insert
- Castor-generated INSERT statementprimKeyName
- The primary key name
Intalio Inc. (C) 1999-2003. All rights reserved http://www.intalio.com