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 String |
ACTION_ADD |
static String |
ACTION_DROP |
static String |
ACTION_GET |
static String |
ACTION_SET |
static 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 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 ResultSet |
executeQuery(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 int |
executeUpdate(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.
|
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 Object |
getPrimaryKey(ClassMapping mapping)
Return the primary key value for the sequence table for the given class.
|
String |
getPrimaryKeyColumn()
The name of the table's primary key column.
|
DBIdentifier |
getPrimaryKeyColumnIdentifier() |
protected long |
getSequence(ClassMapping mapping,
Connection conn)
Get the current sequence value.
|
protected long |
getSequence(ResultSet rs,
DBDictionary dict)
This method is to provide override for non-JDBC or JDBC-like
implementation of getting sequence from the result set.
|
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.
|
String |
getTable()
The sequence table name.
|
String |
getUniqueColumns() |
DBIdentifier |
getUniqueConstraintIdentifier() |
String |
getUniqueConstraintName() |
static void |
main(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 Object |
nextInternal(JDBCStore store,
ClassMapping mapping)
Return the next sequence object.
|
protected PreparedStatement |
prepareStatement(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
|
String |
resolveTableName(ClassMapping mapping,
Table table)
Deprecated.
|
static boolean |
run(JDBCConfiguration conf,
String[] args,
Options opts)
Run the tool.
|
static boolean |
run(JDBCConfiguration conf,
String[] args,
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(String primaryKeyColumn)
The name of the table's primary key column.
|
protected boolean |
setSequence(ClassMapping mapping,
TableJDBCSeq.Status stat,
int inc,
boolean updateStatSeq,
Connection conn)
Grabs the next handful of sequence numbers.
|
void |
setSequenceColumn(String sequenceColumn)
The name of the column that holds the sequence value.
|
void |
setTable(String name)
The sequence table name.
|
void |
setTableName(String name)
Deprecated.
Use
setTable(java.lang.String) . Retained for
backwards-compatibility with auto-configuration. |
void |
setUniqueColumns(String columnNames)
Sets the names of the columns on which a unique constraint is set.
|
void |
setUniqueConstraintName(DBIdentifier uniqueConstraintName) |
void |
setUniqueConstraintName(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 String ACTION_DROP
public static final String ACTION_ADD
public static final String ACTION_GET
public static final String ACTION_SET
public static final String DEFAULT_TABLE
public 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(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.@Deprecated public void setTableName(String name)
setTable(java.lang.String)
. Retained for
backwards-compatibility with auto-configuration.public String getSequenceColumn()
SEQUENCE_VALUE
.public void setSequenceColumn(String sequenceColumn)
SEQUENCE_VALUE
.public String getPrimaryKeyColumn()
ID
.public DBIdentifier getPrimaryKeyColumnIdentifier()
public void setPrimaryKeyColumn(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(String columnNames)
columnsNames
- are passed as a single String concatenated with
a '|' character. This method parses it back to array of Strings.public String getUniqueColumns()
@Deprecated 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 Object nextInternal(JDBCStore store, ClassMapping mapping) throws Exception
AbstractJDBCSeq
nextInternal
in class AbstractJDBCSeq
Exception
protected Object currentInternal(JDBCStore store, ClassMapping mapping) throws Exception
AbstractJDBCSeq
currentInternal
in class AbstractJDBCSeq
Exception
protected void allocateInternal(int count, JDBCStore store, ClassMapping mapping) throws SQLException
AbstractJDBCSeq
allocateInternal
in class AbstractJDBCSeq
SQLException
protected TableJDBCSeq.Status getStatus(ClassMapping mapping)
protected Column addPrimaryKeyColumn(Table table)
protected Object getPrimaryKey(ClassMapping mapping)
protected long getSequence(ClassMapping mapping, Connection conn) throws 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.SQLException
protected boolean setSequence(ClassMapping mapping, TableJDBCSeq.Status stat, int inc, boolean updateStatSeq, Connection conn) throws SQLException
SQLException
@Deprecated public 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 SQLException
SQLException
public void dropTable() throws SQLException
SQLException
public static void main(String[] args) throws Exception
JDBCConfiguration
. Optional.JDBCConfiguration
can be set by
using their names and supplying a value. For example:
-licenseKey adslfja83r3lkadf
Exception
public static boolean run(JDBCConfiguration conf, String[] args, Options opts) throws Exception
Exception
public static boolean run(JDBCConfiguration conf, String[] args, String action) throws Exception
Exception
protected PreparedStatement prepareStatement(Connection conn, SQLBuffer buf) throws SQLException
SQLException
protected int executeUpdate(JDBCConfiguration conf, Connection conn, PreparedStatement stmnt, SQLBuffer buf, int opcode) throws SQLException
SQLException
protected ResultSet executeQuery(JDBCConfiguration conf, Connection conn, PreparedStatement stmnt, SQLBuffer buf) throws SQLException
SQLException
protected long getSequence(ResultSet rs, DBDictionary dict) throws SQLException
SQLException
public void setUniqueConstraintName(String uniqueConstraintName)
public void setUniqueConstraintName(DBIdentifier uniqueConstraintName)
public String getUniqueConstraintName()
public DBIdentifier getUniqueConstraintIdentifier()
Copyright © 2006–2022 Apache Software Foundation. All rights reserved.