Package org.apache.torque.oid
Class AbstractIdGenerator
- java.lang.Object
-
- org.apache.torque.oid.AbstractIdGenerator
-
- All Implemented Interfaces:
IdGenerator
- Direct Known Subclasses:
AutoIncrementIdGenerator,SequenceIdGenerator
public abstract class AbstractIdGenerator extends Object implements IdGenerator
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 Modifier and Type Field Description protected AdapteradapterThe adapter that knows the correct sql syntaxprotected StringdatabaseNameThe internal name of the Database that this Generator is connected to.
-
Constructor Summary
Constructors Constructor Description AbstractIdGenerator(Adapter adapter, String databaseName)Creates an IdGenerator which will work with the specified database.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected <T> TgetId(Connection connection, Object keyInfo, RecordMapper<T> mapper)Returns the last ID used by this connection.BigDecimalgetIdAsBigDecimal(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.StringgetIdAsString(Connection connection, Object keyInfo)Returns the last ID used by this connection.StringgetIdSql(Object keyInfo)Returns the SQL to retrieve the next id.abstract booleanisConnectionRequired()A flag to determine whether a Connection is required to generate an id.abstract booleanisGetGeneratedKeysSupported()A flag to determine whether Statement#getGeneratedKeys() should be used.abstract booleanisPostInsert()A flag to determine the timing of the id generationabstract booleanisPriorToInsert()A flag to determine the timing of the id generation
-
-
-
Method Detail
-
getIdAsInt
public int getIdAsInt(Connection connection, Object keyInfo) throws TorqueException
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
public long getIdAsLong(Connection connection, Object keyInfo) throws TorqueException
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
public BigDecimal getIdAsBigDecimal(Connection connection, Object keyInfo) throws TorqueException
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
public String getIdAsString(Connection connection, Object keyInfo) throws TorqueException
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
public String getIdSql(Object keyInfo) throws TorqueException
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.
-
-