org.apache.openjpa.jdbc.kernel
Class TableJDBCSeq

java.lang.Object
  extended by org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq
      extended by org.apache.openjpa.jdbc.kernel.TableJDBCSeq
All Implemented Interfaces:
JDBCSeq, Seq, Configurable, Closeable
Direct Known Subclasses:
ClassTableJDBCSeq, ValueTableJDBCSeq

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.

Author:
Abe White

Nested Class Summary
protected static class TableJDBCSeq.Status
          Helper struct to hold status information.
 
Field Summary
static String ACTION_ADD
           
static String ACTION_DROP
           
static String ACTION_GET
           
static String ACTION_SET
           
 
Fields inherited from class org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq
current, type
 
Fields inherited from interface org.apache.openjpa.kernel.Seq
TYPE_CONTIGUOUS, TYPE_DEFAULT, TYPE_NONTRANSACTIONAL, TYPE_TRANSACTIONAL
 
Constructor Summary
TableJDBCSeq()
           
 
Method Summary
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.
 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.
protected  long getSequence(ClassMapping mapping, Connection conn)
          Return the current sequence value, or -1 if unattainable.
 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.
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.
 void refreshTable()
          Creates the sequence table in the DB.
 String resolveTableName(ClassMapping mapping, Table table)
          Resolve a fully qualified table name
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 startConfiguration()
          Invoked before bean property configuration is begun on this object.
 
Methods inherited from class org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq
allocate, close, closeConnection, current, getConnection, next, setType, suspendInJTA
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTION_DROP

public static final String ACTION_DROP
See Also:
Constant Field Values

ACTION_ADD

public static final String ACTION_ADD
See Also:
Constant Field Values

ACTION_GET

public static final String ACTION_GET
See Also:
Constant Field Values

ACTION_SET

public static final String ACTION_SET
See Also:
Constant Field Values
Constructor Detail

TableJDBCSeq

public TableJDBCSeq()
Method Detail

getTable

public String getTable()
The sequence table name. Defaults to 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.


setTable

public void setTable(String name)
The sequence table name. Defaults to 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.


setTableName

public void setTableName(String name)
Deprecated. Use setTable(java.lang.String). Retained for backwards-compatibility with auto-configuration.


getSequenceColumn

public String getSequenceColumn()
The name of the column that holds the sequence value. Defaults to SEQUENCE_VALUE.


setSequenceColumn

public void setSequenceColumn(String sequenceColumn)
The name of the column that holds the sequence value. Defaults to SEQUENCE_VALUE.


getPrimaryKeyColumn

public String getPrimaryKeyColumn()
The name of the table's primary key column. Defaults to ID.


setPrimaryKeyColumn

public void setPrimaryKeyColumn(String primaryKeyColumn)
The name of the table's primary key column. Defaults to ID.


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

setIncrement

public void setIncrement(int inc)
Deprecated. Use setAllocate(int). Retained for backwards compatibility of auto-configuration.


getConfiguration

public JDBCConfiguration getConfiguration()
Description copied from class: AbstractJDBCSeq
Return the JDBCConfiguration for this sequence.

Specified by:
getConfiguration in class AbstractJDBCSeq

setConfiguration

public void setConfiguration(Configuration conf)
Description copied from interface: Configurable
Invoked prior to setting bean properties.

Specified by:
setConfiguration in interface Configurable

startConfiguration

public void startConfiguration()
Description copied from interface: Configurable
Invoked before bean property configuration is begun on this object.

Specified by:
startConfiguration in interface Configurable

endConfiguration

public void endConfiguration()
Description copied from interface: Configurable
Invoked upon completion of bean property configuration for this object.

Specified by:
endConfiguration in interface Configurable

addSchema

public void addSchema(ClassMapping mapping,
                      SchemaGroup group)
Description copied from class: AbstractJDBCSeq
No-op.

Specified by:
addSchema in interface JDBCSeq
Overrides:
addSchema in class AbstractJDBCSeq

nextInternal

protected Object nextInternal(JDBCStore store,
                              ClassMapping mapping)
                       throws Exception
Description copied from class: AbstractJDBCSeq
Return the next sequence object.

Specified by:
nextInternal in class AbstractJDBCSeq
Throws:
Exception

currentInternal

protected Object currentInternal(JDBCStore store,
                                 ClassMapping mapping)
                          throws Exception
Description copied from class: AbstractJDBCSeq
Return 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:
currentInternal in class AbstractJDBCSeq
Throws:
Exception

allocateInternal

protected void allocateInternal(int count,
                                JDBCStore store,
                                ClassMapping mapping)
                         throws SQLException
Description copied from class: AbstractJDBCSeq
Allocate additional sequence values. Does nothing by default.

Overrides:
allocateInternal in class AbstractJDBCSeq
Throws:
SQLException

getStatus

protected TableJDBCSeq.Status getStatus(ClassMapping mapping)
Return the appropriate status object for the given class, or null if cannot handle the given class. The mapping may be null.


addPrimaryKeyColumn

protected Column addPrimaryKeyColumn(Table table)
Add the primary key column to the given table and return it.


getPrimaryKey

protected Object getPrimaryKey(ClassMapping mapping)
Return the primary key value for the sequence table for the given class.


getSequence

protected long getSequence(ClassMapping mapping,
                           Connection conn)
                    throws SQLException
Return the current sequence value, or -1 if unattainable.

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

public String resolveTableName(ClassMapping mapping,
                               Table table)
Resolve a fully qualified table name

Parameters:
class - mapping to get the schema name

refreshTable

public void refreshTable()
                  throws SQLException
Creates the sequence table in the DB.

Throws:
SQLException

dropTable

public void dropTable()
               throws SQLException
Drops the sequence table in the DB.

Throws:
SQLException

main

public static void main(String[] args)
                 throws Exception
Usage: java org.apache.openjpa.jdbc.schema.TableJDBCSequence [option]* -action/-a <add | drop | get | set> [value] Where the following options are recognized. The various actions are as follows.

Throws:
Exception

run

public static boolean run(JDBCConfiguration conf,
                          String[] args,
                          Options opts)
                   throws Exception
Run the tool. Returns false if invalid options were given.

Throws:
Exception

run

public static boolean run(JDBCConfiguration conf,
                          String[] args,
                          String action)
                   throws Exception
Run the tool. Return false if an invalid option was given.

Throws:
Exception


Copyright © 2006-2010 Apache Software Foundation. All Rights Reserved.