Interface SpiTransaction

All Superinterfaces:
AutoCloseable, Transaction
All Known Implementing Classes:
ExternalJdbcTransaction, JtaTransaction, ScopedTransaction, SpiTransactionProxy

public interface SpiTransaction extends Transaction
Extends Transaction with additional API required on server.

Provides support for batching and TransactionContext.

  • Method Details

    • label

      String label()
      Return the user defined label for the transaction.
    • isLogSql

      boolean isLogSql()
      Return true if generated SQL and Bind values should be logged to the transaction log.
    • isLogSummary

      boolean isLogSummary()
      Return true if summary level events should be logged to the transaction log.
    • logSql

      void logSql(String msg, Object... args)
      Log a message to the SQL logger.
    • logSummary

      void logSummary(String msg, Object... args)
      Log a summary message to the SUMMARY logger.
    • logTxn

      void logTxn(String msg, Object... args)
      Log a transaction message to the transaction logger.
    • registerDeferred

      void registerDeferred(PersistDeferredRelationship derived)
      Register a "Deferred Relationship" that requires an additional update later.
    • registerDeleteBean

      void registerDeleteBean(Class<?> type, Object id)
      Add a deleting bean to the registered list.

      This is to handle bi-directional relationships where both sides Cascade.

    • isRegisteredDeleteBean

      boolean isRegisteredDeleteBean(Class<?> type, Object id)
      Return true if this is a bean that has already been saved/deleted.
    • unregisterBeans

      void unregisterBeans()
      Unregister the persisted beans. Expected after persisting top level beans and hence including all beans that were cascade persisted.
    • isRegisteredBean

      boolean isRegisteredBean(Object bean)
      Return true if this is a bean that has already been persisted in the current recursive save request. The goal is to stop recursively saving the bean when cascade persist is on both sides of a relationship).

      This will register the bean if it is not already.

    • id

      String id()
      Returns a String used to identify the transaction. This id is used for Transaction logging.
    • startTime

      Instant startTime()
      Return the start timestamp for the transaction (JVM side).
    • isUpdateAllLoadedProperties

      Boolean isUpdateAllLoadedProperties()
      Return true if this transaction has updateAllLoadedProperties set. If null is returned the server default is used (set on DatabaseConfig).
    • getBatchSize

      int getBatchSize()
      Return the batchSize specifically set for this transaction or 0.

      Returning 0 implies to use the system wide default batch size.

      Specified by:
      getBatchSize in interface Transaction
    • getBatchGetGeneratedKeys

      Boolean getBatchGetGeneratedKeys()
      Return the getGeneratedKeys setting for this transaction.
    • depth

      default void depth(int diff)
      Modify the current 'depth' of the transaction.

      As we cascade save or delete we traverse the object graph tree. Going up to Assoc Ones the depth decreases and going down to Assoc Manys the depth increases.

      The depth is used for ordering batching statements. The lowest depth get executed first during save.

    • depthDecrement

      default void depthDecrement()
      Decrement the depth BUT only if depth is greater than 0. Return the amount that depth should be incremented by (0 or 1).
    • depthReset

      default void depthReset()
      Reset the depth back to 0 - done at the end of top level insert and update.
    • depth

      default int depth()
      Return the current depth.
    • isAutoPersistUpdates

      boolean isAutoPersistUpdates()
      Return true if dirty beans are automatically persisted.
    • isExplicit

      boolean isExplicit()
      Return true if this transaction was created explicitly via Ebean.beginTransaction().
    • event

      Get the object that holds the event details.

      This information is used maintain the table state, cache and text indexes. On commit the Table modifications this generates is broadcast around the cluster (if you have a cluster).

    • isPersistCascade

      boolean isPersistCascade()
      Whether persistCascade is on for save and delete.
    • isBatchThisRequest

      boolean isBatchThisRequest()
      Return true if this request should be batched. Conversely returns false if this request should be executed immediately.
    • batchControl

      BatchControl batchControl()
      Return the BatchControl used to batch up persist requests.
    • setBatchControl

      void setBatchControl(BatchControl control)
      Set the BatchControl used to batch up persist requests. There should only be one PersistQueue set per transaction.
    • persistenceContext

      SpiPersistenceContext persistenceContext()
      Return the persistence context associated with this transaction.

      You may wish to hold onto this and set it against another transaction later. This is along the lines of 'extended persistence context' behaviour.

    • setPersistenceContext

      void setPersistenceContext(SpiPersistenceContext context)
      Set the persistence context to this transaction.

      This could be considered similar to 'EJB3 Extended Persistence Context'. In that you can get the PersistenceContext from a transaction, hold onto it, and then set it back later to a second transaction. In general there is one PersistenceContext per Transaction. The getPersistenceContext() and setPersistenceContext() enable a developer to reuse a single PersistenceContext with multiple transactions.

    • internalConnection

      Connection internalConnection()
      Return the underlying Connection for internal use.

      If the connection is made from Transaction and the user code calls that method we can no longer trust the query only status of a Transaction.

    • isSaveAssocManyIntersection

      boolean isSaveAssocManyIntersection(String intersectionTable, String beanName)
      Return true if the manyToMany intersection should be persisted for this particular relationship direction.
    • checkBatchEscalationOnCascade

      boolean checkBatchEscalationOnCascade(PersistRequestBean<?> request)
      Return true if batch mode got escalated for this request (and associated cascades).
    • flushBatchOnCascade

      void flushBatchOnCascade()
      If batch mode was turned on for the request then flush the batch.
    • flushBatchOnRollback

      void flushBatchOnRollback()
      If batch was on then effectively clear the batch such that we can handle exceptions and continue.
    • translate

      jakarta.persistence.PersistenceException translate(String message, SQLException cause)
      Translate the SQLException.
    • markNotQueryOnly

      void markNotQueryOnly()
      Mark the transaction explicitly as not being query only.
    • checkBatchEscalationOnCollection

      void checkBatchEscalationOnCollection()
      Potentially escalate batch mode on saving or deleting a collection.
    • flushBatchOnCollection

      void flushBatchOnCollection()
      Flush batch if we escalated batch mode on saving or deleting a collection.
    • addBeanChange

      void addBeanChange(BeanChange beanChange)
      Add a bean change to the change log.
    • sendChangeLog

      void sendChangeLog(ChangeSet changeSet)
      Send the change set to be prepared and then logged.
    • setTenantId

      void setTenantId(Object tenantId)
      Set the current Tenant Id.
    • tenantId

      Object tenantId()
      Return the current Tenant Id.
    • profileOffset

      long profileOffset()
      Return the offset time from the start of the transaction.
    • profileEvent

      void profileEvent(SpiProfileTransactionEvent event)
      Check if the event should be added to a profiling transaction.
    • setProfileStream

      void setProfileStream(ProfileStream profileStream)
      Set the profileStream to catch and time all the events for this transaction.
    • profileStream

      ProfileStream profileStream()
      Return the stream that profiling events are written to.
    • setProfileLocation

      void setProfileLocation(ProfileLocation profileLocation)
      Set the profile location for this transaction.
    • profileLocation

      ProfileLocation profileLocation()
      Return the profile location for this transaction.
    • isNestedUseSavepoint

      boolean isNestedUseSavepoint()
      Return true when nested transactions should create Savepoints.
    • isSkipCacheExplicit

      boolean isSkipCacheExplicit()
      Return true if explicitly set to skip cache (ignores skipOnWrite).
    • preCommit

      void preCommit()
      Fire pre commit processing/listeners.
    • postCommit

      void postCommit()
      Fire post commit events and listeners.
    • postRollback

      void postRollback(Throwable cause)
      Fire post rollback events and listeners.
    • deactivateExternal

      void deactivateExternal()
      Set the transaction to be inactive via external transaction manager.
    • setAutoCommitOnFindIterate

      default void setAutoCommitOnFindIterate()
      Set autocommit to false for a findIterate query.

      This is done for specific platforms that need it, in order to make use cursors to stream a large or unbounded query result to the client.