org.apache.openjpa.jdbc.kernel
public class TableJDBCSeq extends AbstractJDBCSeq implements Configurable
JDBCSeq
implementation that uses a database table
for sequence number generation. This base implementation uses a single
row for a global sequence number.Modifier and Type | Class and Description |
---|---|
protected class |
TableJDBCSeq.AllocateSequenceRunnable
AllocateSequenceRunnable is a runnable wrapper that will inserts the
initial sequence value into the database.
|
protected class |
TableJDBCSeq.CurrentSequenceRunnable
CurentSequenceRunnable is a runnable wrapper which obtains the current
sequence value from the database.
|
protected static class |
TableJDBCSeq.Status
Helper struct to hold status information.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
ACTION_ADD |
static java.lang.String |
ACTION_DROP |
static java.lang.String |
ACTION_GET |
static java.lang.String |
ACTION_SET |
static java.lang.String |
DEFAULT_TABLE |
current, type
TYPE_CONTIGUOUS, TYPE_DEFAULT, TYPE_NONTRANSACTIONAL, TYPE_TRANSACTIONAL
Constructor and Description |
---|
TableJDBCSeq() |
Modifier and Type | Method and Description |
---|---|
protected Column |
addPrimaryKeyColumn(Table table)
Add the primary key column to the given table and return it.
|
void |
addSchema(ClassMapping mapping,
SchemaGroup group)
No-op.
|
protected void |
allocateInternal(int count,
JDBCStore store,
ClassMapping mapping)
Allocate additional sequence values.
|
protected java.lang.Object |
currentInternal(JDBCStore store,
ClassMapping mapping)
Return the current sequence object.
|
void |
dropTable()
Drops the sequence table in the DB.
|
void |
endConfiguration()
Invoked upon completion of bean property configuration for this object.
|
protected java.sql.ResultSet |
executeQuery(JDBCConfiguration conf,
java.sql.Connection conn,
java.sql.PreparedStatement stmnt,
SQLBuffer buf)
This method is to provide override for non-JDBC or JDBC-like
implementation of executing query.
|
protected int |
executeUpdate(JDBCConfiguration conf,
java.sql.Connection conn,
java.sql.PreparedStatement stmnt,
SQLBuffer buf,
int opcode)
This method is to provide override for non-JDBC or JDBC-like
implementation of executing update.
|
int |
getAllocate()
Return the number of sequences to allocate for each update of the
sequence table.
|
JDBCConfiguration |
getConfiguration()
Return the
JDBCConfiguration for this sequence. |
int |
getInitialValue()
Return the number as the initial number for the
GeneratedValue.TABLE strategy to start with.
|
protected java.lang.Object |
getPrimaryKey(ClassMapping mapping)
Return the primary key value for the sequence table for the given class.
|
java.lang.String |
getPrimaryKeyColumn()
The name of the table's primary key column.
|
DBIdentifier |
getPrimaryKeyColumnIdentifier() |
protected long |
getSequence(ClassMapping mapping,
java.sql.Connection conn)
Get the current sequence value.
|
protected long |
getSequence(java.sql.ResultSet rs,
DBDictionary dict)
This method is to provide override for non-JDBC or JDBC-like
implementation of getting sequence from the result set.
|
java.lang.String |
getSequenceColumn()
The name of the column that holds the sequence value.
|
protected TableJDBCSeq.Status |
getStatus(ClassMapping mapping)
Return the appropriate status object for the given class, or null
if cannot handle the given class.
|
java.lang.String |
getTable()
The sequence table name.
|
java.lang.String |
getUniqueColumns() |
DBIdentifier |
getUniqueConstraintIdentifier() |
java.lang.String |
getUniqueConstraintName() |
static void |
main(java.lang.String[] args)
Usage: java org.apache.openjpa.jdbc.schema.TableJDBCSequence [option]*
-action/-a <add | drop | get | set> [value]
Where the following options are recognized.
|
protected java.lang.Object |
nextInternal(JDBCStore store,
ClassMapping mapping)
Return the next sequence object.
|
protected java.sql.PreparedStatement |
prepareStatement(java.sql.Connection conn,
SQLBuffer buf)
This method is to provide override for non-JDBC or JDBC-like
implementation of preparing statement.
|
void |
refreshTable()
Creates the sequence table in the DB.
|
DBIdentifier |
resolveTableIdentifier(ClassMapping mapping,
Table table)
Resolve a fully qualified table name
|
java.lang.String |
resolveTableName(ClassMapping mapping,
Table table)
Deprecated.
|
static boolean |
run(JDBCConfiguration conf,
java.lang.String[] args,
Options opts)
Run the tool.
|
static boolean |
run(JDBCConfiguration conf,
java.lang.String[] args,
java.lang.String action)
Run the tool.
|
void |
setAllocate(int alloc)
Return the number of sequences to allocate for each update of the
sequence table.
|
void |
setConfiguration(Configuration conf)
Invoked prior to setting bean properties.
|
void |
setIncrement(int inc)
Deprecated.
Use
setAllocate(int) . Retained for backwards
compatibility of auto-configuration. |
void |
setInitialValue(int intValue)
Set the initial number in the table for the GeneratedValue.TABLE
strategy to use as initial number.
|
void |
setPrimaryKeyColumn(java.lang.String primaryKeyColumn)
The name of the table's primary key column.
|
protected boolean |
setSequence(ClassMapping mapping,
TableJDBCSeq.Status stat,
int inc,
boolean updateStatSeq,
java.sql.Connection conn)
Grabs the next handful of sequence numbers.
|
void |
setSequenceColumn(java.lang.String sequenceColumn)
The name of the column that holds the sequence value.
|
void |
setTable(java.lang.String name)
The sequence table name.
|
void |
setTableName(java.lang.String name)
Deprecated.
Use
setTable(java.lang.String) . Retained for
backwards-compatibility with auto-configuration. |
void |
setUniqueColumns(java.lang.String columnNames)
Sets the names of the columns on which a unique constraint is set.
|
void |
setUniqueConstraintName(DBIdentifier uniqueConstraintName) |
void |
setUniqueConstraintName(java.lang.String uniqueConstraintName) |
void |
startConfiguration()
Invoked before bean property configuration is begun on this object.
|
allocate, close, closeConnection, current, getConnection, next, setType, suspendInJTA
public static final java.lang.String ACTION_DROP
public static final java.lang.String ACTION_ADD
public static final java.lang.String ACTION_GET
public static final java.lang.String ACTION_SET
public static final java.lang.String DEFAULT_TABLE
public java.lang.String getTable()
OPENJPA_SEQUENCE_TABLE
.
By default, the table will be placed in the first schema listed in your
openjpa.jdbc.Schemas
property, 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.public void setTable(java.lang.String name)
OPENJPA_SEQUENCE_TABLE
.
By default, the table will be placed in the first schema listed in your
openjpa.jdbc.Schemas
property, 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.public void setTableName(java.lang.String name)
setTable(java.lang.String)
. Retained for
backwards-compatibility with auto-configuration.public java.lang.String getSequenceColumn()
SEQUENCE_VALUE
.public void setSequenceColumn(java.lang.String sequenceColumn)
SEQUENCE_VALUE
.public java.lang.String getPrimaryKeyColumn()
ID
.public DBIdentifier getPrimaryKeyColumnIdentifier()
public void setPrimaryKeyColumn(java.lang.String primaryKeyColumn)
ID
.public int getAllocate()
public void setAllocate(int alloc)
public int getInitialValue()
public void setInitialValue(int intValue)
intValue.
- The initial numberpublic void setUniqueColumns(java.lang.String columnNames)
columnsNames
- are passed as a single String concatenated with
a '|' character. This method parses it back to array of Strings.public java.lang.String getUniqueColumns()
public void setIncrement(int inc)
setAllocate(int)
. Retained for backwards
compatibility of auto-configuration.public JDBCConfiguration getConfiguration()
AbstractJDBCSeq
JDBCConfiguration
for this sequence.getConfiguration
in class AbstractJDBCSeq
public void setConfiguration(Configuration conf)
Configurable
setConfiguration
in interface Configurable
public void startConfiguration()
Configurable
startConfiguration
in interface Configurable
public void endConfiguration()
Configurable
endConfiguration
in interface Configurable
public void addSchema(ClassMapping mapping, SchemaGroup group)
AbstractJDBCSeq
addSchema
in interface JDBCSeq
addSchema
in class AbstractJDBCSeq
protected java.lang.Object nextInternal(JDBCStore store, ClassMapping mapping) throws java.lang.Exception
AbstractJDBCSeq
nextInternal
in class AbstractJDBCSeq
java.lang.Exception
protected java.lang.Object currentInternal(JDBCStore store, ClassMapping mapping) throws java.lang.Exception
AbstractJDBCSeq
currentInternal
in class AbstractJDBCSeq
java.lang.Exception
protected void allocateInternal(int count, JDBCStore store, ClassMapping mapping) throws java.sql.SQLException
AbstractJDBCSeq
allocateInternal
in class AbstractJDBCSeq
java.sql.SQLException
protected TableJDBCSeq.Status getStatus(ClassMapping mapping)
protected Column addPrimaryKeyColumn(Table table)
protected java.lang.Object getPrimaryKey(ClassMapping mapping)
protected long getSequence(ClassMapping mapping, java.sql.Connection conn) throws java.sql.SQLException
mapping
- ClassMapping of the entity whose sequence value will be
obtained.conn
- Connection used issue SQL statements.SEQUENCE_NOT_FOUND
if the sequence could not be found.java.sql.SQLException
protected boolean setSequence(ClassMapping mapping, TableJDBCSeq.Status stat, int inc, boolean updateStatSeq, java.sql.Connection conn) throws java.sql.SQLException
java.sql.SQLException
public java.lang.String resolveTableName(ClassMapping mapping, Table table)
class
- mapping to get the schema namepublic DBIdentifier resolveTableIdentifier(ClassMapping mapping, Table table)
class
- mapping to get the schema namepublic void refreshTable() throws java.sql.SQLException
java.sql.SQLException
public void dropTable() throws java.sql.SQLException
java.sql.SQLException
public static void main(java.lang.String[] args) throws java.lang.Exception
JDBCConfiguration
. Optional.JDBCConfiguration
can be set by
using their names and supplying a value. For example:
-licenseKey adslfja83r3lkadf
java.lang.Exception
public static boolean run(JDBCConfiguration conf, java.lang.String[] args, Options opts) throws java.lang.Exception
java.lang.Exception
public static boolean run(JDBCConfiguration conf, java.lang.String[] args, java.lang.String action) throws java.lang.Exception
java.lang.Exception
protected java.sql.PreparedStatement prepareStatement(java.sql.Connection conn, SQLBuffer buf) throws java.sql.SQLException
java.sql.SQLException
protected int executeUpdate(JDBCConfiguration conf, java.sql.Connection conn, java.sql.PreparedStatement stmnt, SQLBuffer buf, int opcode) throws java.sql.SQLException
java.sql.SQLException
protected java.sql.ResultSet executeQuery(JDBCConfiguration conf, java.sql.Connection conn, java.sql.PreparedStatement stmnt, SQLBuffer buf) throws java.sql.SQLException
java.sql.SQLException
protected long getSequence(java.sql.ResultSet rs, DBDictionary dict) throws java.sql.SQLException
java.sql.SQLException
public void setUniqueConstraintName(java.lang.String uniqueConstraintName)
public void setUniqueConstraintName(DBIdentifier uniqueConstraintName)
public java.lang.String getUniqueConstraintName()
public DBIdentifier getUniqueConstraintIdentifier()