Package org.apache.torque.oid
Class AbstractIdGenerator
java.lang.Object
org.apache.torque.oid.AbstractIdGenerator
- All Implemented Interfaces:
IdGenerator
- Direct Known Subclasses:
AutoIncrementIdGenerator,SequenceIdGenerator
This class serves as a common base class for the sequence-based and the
autoincrement-based id generators
- Version:
- $Id: AbstractIdGenerator.java 1850965 2019-01-10 17:21:29Z painter $
- Author:
- Thomas Vandahl
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionAbstractIdGenerator(Adapter adapter, String databaseName) Creates an IdGenerator which will work with the specified database. -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> TgetId(Connection connection, Object keyInfo, RecordMapper<T> mapper) Returns the last ID used by this connection.getIdAsBigDecimal(Connection connection, Object keyInfo) Returns the last ID used by this connection.intgetIdAsInt(Connection connection, Object keyInfo) Returns the last ID used by this connection.longgetIdAsLong(Connection connection, Object keyInfo) Returns the last ID used by this connection.getIdAsString(Connection connection, Object keyInfo) Returns the last ID used by this connection.Returns the SQL to retrieve the next id.abstract booleanA flag to determine whether a Connection is required to generate an id.abstract booleanA flag to determine whether Statement#getGeneratedKeys() should be used.abstract booleanA flag to determine the timing of the id generationabstract booleanA flag to determine the timing of the id generation
-
Field Details
-
adapter
The adapter that knows the correct sql syntax -
databaseName
The internal name of the Database that this Generator is connected to.
-
-
Constructor Details
-
AbstractIdGenerator
Creates an IdGenerator which will work with the specified database.- Parameters:
adapter- the adapter that knows the correct sql syntax.databaseName- The name of the databaseName to find the correct schema.
-
-
Method Details
-
getIdAsInt
Returns the last ID used by this connection.- Specified by:
getIdAsIntin interfaceIdGenerator- Parameters:
connection- The database connection to read the new id, not null.keyInfo- the name of the table for which the id is retrieved.- Returns:
- An int with the new id.
- Throws:
TorqueException- if a database error occurs.
-
getIdAsLong
Returns the last ID used by this connection.- Specified by:
getIdAsLongin interfaceIdGenerator- Parameters:
connection- The database connection to read the new id, not null.keyInfo- the name of the table for which the id is retrieved.- Returns:
- A long with the new id.
- Throws:
TorqueException- if a database error occurs.
-
getIdAsBigDecimal
Returns the last ID used by this connection.- Specified by:
getIdAsBigDecimalin interfaceIdGenerator- Parameters:
connection- The database connection to read the new id, not null.keyInfo- the name of the table for which the id is retrieved.- Returns:
- A BigDecimal with the new id.
- Throws:
TorqueException- if a database error occurs.
-
getIdAsString
Returns the last ID used by this connection.- Specified by:
getIdAsStringin interfaceIdGenerator- Parameters:
connection- The database connection to read the new id, not null.keyInfo- the name of the table for which the id is retrieved.- Returns:
- A String with the new id.
- Throws:
TorqueException- if a database error occurs.
-
isPriorToInsert
public abstract boolean isPriorToInsert()A flag to determine the timing of the id generation- Specified by:
isPriorToInsertin interfaceIdGenerator- Returns:
- a
booleanvalue
-
isPostInsert
public abstract boolean isPostInsert()A flag to determine the timing of the id generation- Specified by:
isPostInsertin interfaceIdGenerator- Returns:
- a
booleanvalue
-
isConnectionRequired
public abstract boolean isConnectionRequired()A flag to determine whether a Connection is required to generate an id.- Specified by:
isConnectionRequiredin interfaceIdGenerator- Returns:
- a
booleanvalue
-
isGetGeneratedKeysSupported
public abstract boolean isGetGeneratedKeysSupported()A flag to determine whether Statement#getGeneratedKeys() should be used.- Specified by:
isGetGeneratedKeysSupportedin interfaceIdGenerator- Returns:
- a
booleanvalue
-
getId
protected <T> T getId(Connection connection, Object keyInfo, RecordMapper<T> mapper) throws TorqueException Returns the last ID used by this connection.- Type Parameters:
T- the id object class- Parameters:
connection- A Connection.keyInfo- an Object that contains additional info.mapper- The RecordMapper that maps from a ResultSet to the appropriate java object.- Returns:
- The generated id.
- Throws:
TorqueException- if a database error occurs.
-
getIdSql
Returns the SQL to retrieve the next id.- Parameters:
keyInfo- an Object that contains additional info.- Returns:
- the SQL to retrieve the next id.
- Throws:
TorqueException- if a database error occurs.
-