Package org.apache.openjpa.jdbc.kernel
Class TableJDBCSeq
java.lang.Object
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq
org.apache.openjpa.jdbc.kernel.TableJDBCSeq
- All Implemented Interfaces:
JDBCSeq,Seq,Configurable,Closeable
- Direct Known Subclasses:
ClassTableJDBCSeq,ValueTableJDBCSeq
JDBCSeq implementation that uses a database table
for sequence number generation. This base implementation uses a single
row for a global sequence number.- Author:
- Abe White
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classAllocateSequenceRunnable is a runnable wrapper that will inserts the initial sequence value into the database.protected classCurentSequenceRunnable is a runnable wrapper which obtains the current sequence value from the database.protected static classHelper struct to hold status information. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq
current, typeFields inherited from interface org.apache.openjpa.kernel.Seq
TYPE_CONTIGUOUS, TYPE_DEFAULT, TYPE_NONTRANSACTIONAL, TYPE_TRANSACTIONAL -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ColumnaddPrimaryKeyColumn(Table table) Add the primary key column to the given table and return it.voidaddSchema(ClassMapping mapping, SchemaGroup group) No-op.protected voidallocateInternal(int count, JDBCStore store, ClassMapping mapping) Allocate additional sequence values.protected ObjectcurrentInternal(JDBCStore store, ClassMapping mapping) Return the current sequence object.voidDrops the sequence table in the DB.voidInvoked upon completion of bean property configuration for this object.protected ResultSetexecuteQuery(JDBCConfiguration conf, Connection conn, PreparedStatement stmnt, SQLBuffer buf) This method is to provide override for non-JDBC or JDBC-like implementation of executing query.protected intexecuteUpdate(JDBCConfiguration conf, Connection conn, PreparedStatement stmnt, SQLBuffer buf, int opcode) This method is to provide override for non-JDBC or JDBC-like implementation of executing update.intReturn the number of sequences to allocate for each update of the sequence table.Return theJDBCConfigurationfor this sequence.intReturn the number as the initial number for the GeneratedValue.TABLE strategy to start with.protected ObjectgetPrimaryKey(ClassMapping mapping) Return the primary key value for the sequence table for the given class.The name of the table's primary key column.protected longgetSequence(ResultSet rs, DBDictionary dict) This method is to provide override for non-JDBC or JDBC-like implementation of getting sequence from the result set.protected longgetSequence(ClassMapping mapping, Connection conn) Get the current sequence value.The name of the column that holds the sequence value.protected TableJDBCSeq.StatusgetStatus(ClassMapping mapping) Return the appropriate status object for the given class, or null if cannot handle the given class.getTable()The sequence table name.static voidUsage: java org.apache.openjpa.jdbc.schema.TableJDBCSequence [option]* -action/-a <add | drop | get | set> [value] Where the following options are recognized.protected ObjectnextInternal(JDBCStore store, ClassMapping mapping) Return the next sequence object.protected PreparedStatementprepareStatement(Connection conn, SQLBuffer buf) This method is to provide override for non-JDBC or JDBC-like implementation of preparing statement.voidCreates the sequence table in the DB.resolveTableIdentifier(ClassMapping mapping, Table table) Resolve a fully qualified table nameresolveTableName(ClassMapping mapping, Table table) Deprecated.static booleanrun(JDBCConfiguration conf, String[] args, String action) Run the tool.static booleanrun(JDBCConfiguration conf, String[] args, Options opts) Run the tool.voidsetAllocate(int alloc) Return the number of sequences to allocate for each update of the sequence table.voidInvoked prior to setting bean properties.voidsetIncrement(int inc) Deprecated.voidsetInitialValue(int intValue) Set the initial number in the table for the GeneratedValue.TABLE strategy to use as initial number.voidsetPrimaryKeyColumn(String primaryKeyColumn) The name of the table's primary key column.protected booleansetSequence(ClassMapping mapping, TableJDBCSeq.Status stat, int inc, boolean updateStatSeq, Connection conn) Grabs the next handful of sequence numbers.voidsetSequenceColumn(String sequenceColumn) The name of the column that holds the sequence value.voidThe sequence table name.voidsetTableName(String name) Deprecated.voidsetUniqueColumns(String columnNames) Sets the names of the columns on which a unique constraint is set.voidsetUniqueConstraintName(String uniqueConstraintName) voidsetUniqueConstraintName(DBIdentifier uniqueConstraintName) voidInvoked before bean property configuration is begun on this object.Methods inherited from class org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq
allocate, close, closeConnection, current, getConnection, getConnection, next, setType, suspendInJTA
-
Field Details
-
ACTION_DROP
- See Also:
-
ACTION_ADD
- See Also:
-
ACTION_GET
- See Also:
-
ACTION_SET
- See Also:
-
DEFAULT_TABLE
- See Also:
-
-
Constructor Details
-
TableJDBCSeq
public TableJDBCSeq()
-
-
Method Details
-
getTable
The sequence table name. Defaults toOPENJPA_SEQUENCE_TABLE. By default, the table will be placed in the first schema listed in youropenjpa.jdbc.Schemasproperty, or in the default schema if the property is not given. If you specify a table name in the form<schema>.<table>, then the given schema will be used. -
setTable
The sequence table name. Defaults toOPENJPA_SEQUENCE_TABLE. By default, the table will be placed in the first schema listed in youropenjpa.jdbc.Schemasproperty, or in the default schema if the property is not given. If you specify a table name in the form<schema>.<table>, then the given schema will be used. -
setTableName
Deprecated.UsesetTable(java.lang.String). Retained for backwards-compatibility with auto-configuration. -
getSequenceColumn
The name of the column that holds the sequence value. Defaults toSEQUENCE_VALUE. -
setSequenceColumn
The name of the column that holds the sequence value. Defaults toSEQUENCE_VALUE. -
getPrimaryKeyColumn
The name of the table's primary key column. Defaults toID. -
getPrimaryKeyColumnIdentifier
-
setPrimaryKeyColumn
The name of the table's primary key column. Defaults toID. -
getAllocate
public int getAllocate()Return the number of sequences to allocate for each update of the sequence table. Sequence numbers will be grabbed in blocks of this value to reduce the number of transactions that must be performed on the sequence table. -
setAllocate
public void setAllocate(int alloc) Return the number of sequences to allocate for each update of the sequence table. Sequence numbers will be grabbed in blocks of this value to reduce the number of transactions that must be performed on the sequence table. -
getInitialValue
public int getInitialValue()Return the number as the initial number for the GeneratedValue.TABLE strategy to start with.- Returns:
- an initial number
-
setInitialValue
public void setInitialValue(int intValue) Set the initial number in the table for the GeneratedValue.TABLE strategy to use as initial number.- Parameters:
intValue- . The initial number
-
setUniqueColumns
Sets the names of the columns on which a unique constraint is set.- Parameters:
columnsNames- are passed as a single String concatenated with a '|' character. This method parses it back to array of Strings.
-
getUniqueColumns
-
setIncrement
Deprecated.UsesetAllocate(int). Retained for backwards compatibility of auto-configuration. -
getConfiguration
Description copied from class:AbstractJDBCSeqReturn theJDBCConfigurationfor this sequence.- Specified by:
getConfigurationin classAbstractJDBCSeq
-
setConfiguration
Description copied from interface:ConfigurableInvoked prior to setting bean properties.- Specified by:
setConfigurationin interfaceConfigurable
-
startConfiguration
public void startConfiguration()Description copied from interface:ConfigurableInvoked before bean property configuration is begun on this object.- Specified by:
startConfigurationin interfaceConfigurable
-
endConfiguration
public void endConfiguration()Description copied from interface:ConfigurableInvoked upon completion of bean property configuration for this object.- Specified by:
endConfigurationin interfaceConfigurable
-
addSchema
Description copied from class:AbstractJDBCSeqNo-op.- Specified by:
addSchemain interfaceJDBCSeq- Overrides:
addSchemain classAbstractJDBCSeq
-
nextInternal
Description copied from class:AbstractJDBCSeqReturn the next sequence object.- Specified by:
nextInternalin classAbstractJDBCSeq- Throws:
Exception
-
currentInternal
Description copied from class:AbstractJDBCSeqReturn the current sequence object. By default returns the last sequence value used, or null if no sequence values have been requested yet. Default implementation is not threadsafe.- Overrides:
currentInternalin classAbstractJDBCSeq- Throws:
Exception
-
allocateInternal
protected void allocateInternal(int count, JDBCStore store, ClassMapping mapping) throws SQLException Description copied from class:AbstractJDBCSeqAllocate additional sequence values. Does nothing by default.- Overrides:
allocateInternalin classAbstractJDBCSeq- Throws:
SQLException
-
getStatus
Return the appropriate status object for the given class, or null if cannot handle the given class. The mapping may be null. -
addPrimaryKeyColumn
Add the primary key column to the given table and return it. -
getPrimaryKey
Return the primary key value for the sequence table for the given class. -
getSequence
Get the current sequence value.- Parameters:
mapping- ClassMapping of the entity whose sequence value will be obtained.conn- Connection used issue SQL statements.- Returns:
- The current sequence value, or
SEQUENCE_NOT_FOUNDif the sequence could not be found. - Throws:
SQLException
-
setSequence
protected boolean setSequence(ClassMapping mapping, TableJDBCSeq.Status stat, int inc, boolean updateStatSeq, Connection conn) throws SQLException Grabs the next handful of sequence numbers.- Returns:
- true if the sequence was updated, false if no sequence row existed for this mapping
- Throws:
SQLException
-
resolveTableName
Deprecated.Resolve a fully qualified table name- Parameters:
class- mapping to get the schema name
-
resolveTableIdentifier
Resolve a fully qualified table name- Parameters:
class- mapping to get the schema name
-
refreshTable
Creates the sequence table in the DB.- Throws:
SQLException
-
dropTable
Drops the sequence table in the DB.- Throws:
SQLException
-
main
Usage: java org.apache.openjpa.jdbc.schema.TableJDBCSequence [option]* -action/-a <add | drop | get | set> [value] Where the following options are recognized.- -properties/-p <properties file or resource>: The
path or resource name of a OpenJPA properties file containing
information such as the license key and connection data as
outlined in
JDBCConfiguration. Optional. - -<property name> <property value>: All bean
properties of the OpenJPA
JDBCConfigurationcan be set by using their names and supplying a value. For example:-licenseKey adslfja83r3lkadf
- add: Create the sequence table.
- drop: Drop the sequence table.
- get: Print the current sequence value.
- set: Set the sequence value.
- Throws:
Exception
- -properties/-p <properties file or resource>: The
path or resource name of a OpenJPA properties file containing
information such as the license key and connection data as
outlined in
-
run
Run the tool. Returns false if invalid options were given.- Throws:
Exception
-
run
Run the tool. Return false if an invalid option was given.- Throws:
Exception
-
prepareStatement
This method is to provide override for non-JDBC or JDBC-like implementation of preparing statement.- Throws:
SQLException
-
executeUpdate
protected int executeUpdate(JDBCConfiguration conf, Connection conn, PreparedStatement stmnt, SQLBuffer buf, int opcode) throws SQLException This method is to provide override for non-JDBC or JDBC-like implementation of executing update.- Throws:
SQLException
-
executeQuery
protected ResultSet executeQuery(JDBCConfiguration conf, Connection conn, PreparedStatement stmnt, SQLBuffer buf) throws SQLException This method is to provide override for non-JDBC or JDBC-like implementation of executing query.- Throws:
SQLException
-
getSequence
This method is to provide override for non-JDBC or JDBC-like implementation of getting sequence from the result set.- Throws:
SQLException
-
setUniqueConstraintName
-
setUniqueConstraintName
-
getUniqueConstraintName
-
getUniqueConstraintIdentifier
-
setAllocate(int).