Interface ChangeSetContext

All Known Subinterfaces:
ChangeSetContextSPI

public interface ChangeSetContext
A ChangeSetContext defines the transactional boundaries around one or multiple Service.emit(com.sap.cds.services.EventContext) calls. It can be used by Handler or other participants to ensure that changes, which were done as part of a ChangeSetContext are canceled (rolled back).
In addition, it provides the ability to perform actions at the end of a ChangeSet by registering a ChangeSetListener
  • Method Details

    • isActive

      static boolean isActive()
      Returns:
      true, if a ChangeSetContext is currently active
    • getCurrent

      static ChangeSetContext getCurrent()
      Gives access to the currently active ChangeSetContext. If no ChangeSetContext is currently opened this method will return null
      Returns:
      the currently active ChangeSetContext or null.
    • getId

      int getId()
      Returns:
      a numeric identifier of the ChangeSetContext, used for logging
    • markForCancel

      void markForCancel()
      Marks the ChangeSetContext to be cancelled. When the ChangeSet is finished, transactions will be rolled back.
    • isMarkedForCancel

      boolean isMarkedForCancel()
      Returns:
      true, if markForCancel() was called at least once, false otherwise
    • markTransactional

      void markTransactional()
      Marks the ChangeSetContext as transactional.

      Transactional ChangeSetContexts ensure to allocate transactions and corresponding resources (e.g. SQL connections), upon first interaction with a transactional data sources. Those resources are released only after closing the ChangeSetContext. A transactional data source might mark the ChangeSetContext as transactional, if it requires a transaction (e.g. when executing a CqnInsert, CqnUpdate, CqnDelete or CqnSelect with locks).

      ChangeSetContext that are not marked transactional allow transactional data sources to free resources earlier, e.g. after each interaction. For example in case of JDBC data sources, SQL connections can be returned to the connection pool after executing a CqnSelect without locks. In that case they are not required to be kept for the entire ChangeSetContext scope.

      Once a ChangeSetContext is marked as transactional it can't be unmarked again. If the ChangeSetContext has been marked as transactional already this method doesn't have any effects.

    • isMarkedTransactional

      boolean isMarkedTransactional()
      Returns:
      true, if this ChangeSetContext was marked transactional (see markTransactional()).
    • register

      void register(ChangeSetListener listener)
      Registers a ChangeSetListener on the ChangeSetContext, to be notified once the ChangeSetContext is closed successfully or cancelled.
      Parameters:
      listener - the ChangeSetListener