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 Adapter
adapter
The adapter that knows the correct sql syntaxprotected String
databaseName
The 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> T
getId(Connection connection, Object keyInfo, RecordMapper<T> mapper)
Returns the last ID used by this connection.BigDecimal
getIdAsBigDecimal(Connection connection, Object keyInfo)
Returns the last ID used by this connection.int
getIdAsInt(Connection connection, Object keyInfo)
Returns the last ID used by this connection.long
getIdAsLong(Connection connection, Object keyInfo)
Returns the last ID used by this connection.String
getIdAsString(Connection connection, Object keyInfo)
Returns the last ID used by this connection.String
getIdSql(Object keyInfo)
Returns the SQL to retrieve the next id.abstract boolean
isConnectionRequired()
A flag to determine whether a Connection is required to generate an id.abstract boolean
isGetGeneratedKeysSupported()
A flag to determine whether Statement#getGeneratedKeys() should be used.abstract boolean
isPostInsert()
A flag to determine the timing of the id generationabstract boolean
isPriorToInsert()
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:
getIdAsInt
in 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:
getIdAsLong
in 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:
getIdAsBigDecimal
in 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:
getIdAsString
in 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:
isPriorToInsert
in interfaceIdGenerator
- Returns:
- a
boolean
value
-
isPostInsert
public abstract boolean isPostInsert()
A flag to determine the timing of the id generation- Specified by:
isPostInsert
in interfaceIdGenerator
- Returns:
- a
boolean
value
-
isConnectionRequired
public abstract boolean isConnectionRequired()
A flag to determine whether a Connection is required to generate an id.- Specified by:
isConnectionRequired
in interfaceIdGenerator
- Returns:
- a
boolean
value
-
isGetGeneratedKeysSupported
public abstract boolean isGetGeneratedKeysSupported()
A flag to determine whether Statement#getGeneratedKeys() should be used.- Specified by:
isGetGeneratedKeysSupported
in interfaceIdGenerator
- Returns:
- a
boolean
value
-
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.
-
-