Package org.apache.openjpa.jdbc.kernel
Class AbstractJDBCSeq
java.lang.Object
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq
- Direct Known Subclasses:
NativeJDBCSeq
,TableJDBCSeq
Abstract sequence implementation. Handles obtaining the proper
connection to used based on whether the sequence is transactional and
whether a second datasource is configured.
- Author:
- Abe White
-
Field Summary
Fields inherited from interface org.apache.openjpa.kernel.Seq
TYPE_CONTIGUOUS, TYPE_DEFAULT, TYPE_NONTRANSACTIONAL, TYPE_TRANSACTIONAL
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addSchema
(ClassMapping mapping, SchemaGroup group) No-op.void
allocate
(int additional, StoreContext ctx, ClassMetaData meta) Allocate additional values efficiently.protected void
allocateInternal
(int additional, JDBCStore store, ClassMapping mapping) Allocate additional sequence values.void
close()
No-op.protected void
closeConnection
(Connection conn) Close the current connection.current
(StoreContext ctx, ClassMetaData meta) Return the current value of the sequence, or null if not available.protected Object
currentInternal
(JDBCStore store, ClassMapping mapping) Return the current sequence object.abstract JDBCConfiguration
Return theJDBCConfiguration
for this sequence.protected Connection
getConnection
(JDBCStore store) protected Connection
getConnection
(JDBCStore store, boolean forceNewConnection) Return the connection to use based on the type of sequence.next
(StoreContext ctx, ClassMetaData meta) Return the next value in the sequence.protected abstract Object
nextInternal
(JDBCStore store, ClassMapping mapping) Return the next sequence object.void
setType
(int type) Records the sequence type.protected boolean
Detect whether or not OpenJPA should suspend the transaction in a managed environment.
-
Field Details
-
type
protected int type -
current
-
-
Constructor Details
-
AbstractJDBCSeq
public AbstractJDBCSeq()
-
-
Method Details
-
setType
public void setType(int type) Records the sequence type. -
next
Description copied from interface:Seq
Return the next value in the sequence. -
current
Description copied from interface:Seq
Return the current value of the sequence, or null if not available. -
allocate
Description copied from interface:Seq
Allocate additional values efficiently. -
addSchema
No-op. -
close
public void close()No-op. -
nextInternal
Return the next sequence object.- Throws:
Exception
-
getConfiguration
Return theJDBCConfiguration
for this sequence. -
currentInternal
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.- Throws:
Exception
-
allocateInternal
protected void allocateInternal(int additional, JDBCStore store, ClassMapping mapping) throws Exception Allocate additional sequence values. Does nothing by default.- Throws:
Exception
-
getConnection
- Throws:
SQLException
- See Also:
-
getConnection
Return the connection to use based on the type of sequence. This connection will automatically be closed; do not close it.
- Parameters:
forceNewConnection
- iftrue
a new connection will be forced- Returns:
- If the sequence type is
TYPE_TRANSACTIONAL
orTYPE_CONTIGUOUS
the connection from theStoreManager
will be returned.Otherwise a new connection will be obtained using DataSource2 from the current configuration. In this case autocommit is set to false prior to returning the connection.
- Throws:
SQLException
-
closeConnection
Close the current connection. If the sequence isTYPE_TRANSACTIONAL
orTYPE_CONTIGUOUS
we will decrement the ref count. Otherwise the connection will be committed and then closed. -
suspendInJTA
protected boolean suspendInJTA()Detect whether or not OpenJPA should suspend the transaction in a managed environment.
-