Class AbstractJDBCSeq

java.lang.Object
org.apache.openjpa.jdbc.kernel.AbstractJDBCSeq
All Implemented Interfaces:
JDBCSeq, Seq, Closeable
Direct Known Subclasses:
NativeJDBCSeq, TableJDBCSeq

public abstract class AbstractJDBCSeq extends Object implements JDBCSeq
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 Details

    • type

      protected int type
    • current

      protected Object current
  • Constructor Details

    • AbstractJDBCSeq

      public AbstractJDBCSeq()
  • Method Details

    • setType

      public void setType(int type)
      Records the sequence type.
      Specified by:
      setType in interface Seq
    • next

      public Object next(StoreContext ctx, ClassMetaData meta)
      Description copied from interface: Seq
      Return the next value in the sequence.
      Specified by:
      next in interface Seq
      Parameters:
      ctx - the current context
      meta - if this is a datastore identity sequence, the persistent class the identity value is for; else null
    • current

      public Object current(StoreContext ctx, ClassMetaData meta)
      Description copied from interface: Seq
      Return the current value of the sequence, or null if not available.
      Specified by:
      current in interface Seq
      Parameters:
      ctx - the current context
      meta - if this is a datastore identity sequence, the persistent class the identity value is for; else null
    • allocate

      public void allocate(int additional, StoreContext ctx, ClassMetaData meta)
      Description copied from interface: Seq
      Allocate additional values efficiently.
      Specified by:
      allocate in interface Seq
      ctx - the current context
      meta - if this is a datastore identity sequence, the persistent class the identity value is for; else null
    • addSchema

      public void addSchema(ClassMapping mapping, SchemaGroup group)
      No-op.
      Specified by:
      addSchema in interface JDBCSeq
    • close

      public void close()
      No-op.
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Seq
    • nextInternal

      protected abstract Object nextInternal(JDBCStore store, ClassMapping mapping) throws Exception
      Return the next sequence object.
      Throws:
      Exception
    • getConfiguration

      public abstract JDBCConfiguration getConfiguration()
      Return the JDBCConfiguration for this sequence.
    • currentInternal

      protected Object currentInternal(JDBCStore store, ClassMapping mapping) throws Exception
      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

      protected Connection getConnection(JDBCStore store) throws SQLException
      Throws:
      SQLException
      See Also:
    • getConnection

      protected Connection getConnection(JDBCStore store, boolean forceNewConnection) throws SQLException

      Return the connection to use based on the type of sequence. This connection will automatically be closed; do not close it.

      Parameters:
      forceNewConnection - if true a new connection will be forced
      Returns:
      If the sequence type is TYPE_TRANSACTIONAL or TYPE_CONTIGUOUS the connection from the StoreManager 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

      protected void closeConnection(Connection conn)
      Close the current connection. If the sequence is TYPE_TRANSACTIONAL or TYPE_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.