Interface ChangeSetContext
- All Known Subinterfaces:
ChangeSetContextSPI
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 Summary
Modifier and TypeMethodDescriptionstatic ChangeSetContextGives access to the currently activeChangeSetContext.intgetId()static booleanisActive()booleanbooleanvoidMarks theChangeSetContextto be cancelled.voidMarks theChangeSetContextas transactional.voidregister(ChangeSetListener listener) Registers aChangeSetListeneron theChangeSetContext, to be notified once theChangeSetContextis closed successfully or cancelled.
-
Method Details
-
isActive
static boolean isActive()- Returns:
true, if aChangeSetContextis currently active
-
getCurrent
Gives access to the currently activeChangeSetContext. If noChangeSetContextis currently opened this method will returnnull- Returns:
- the currently active
ChangeSetContextornull.
-
getId
int getId()- Returns:
- a numeric identifier of the
ChangeSetContext, used for logging
-
markForCancel
void markForCancel()Marks theChangeSetContextto 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 theChangeSetContextas 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 theChangeSetContext. A transactional data source might mark theChangeSetContextas transactional, if it requires a transaction (e.g. when executing aCqnInsert,CqnUpdate,CqnDeleteorCqnSelectwith locks).ChangeSetContextthat 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 aCqnSelectwithout locks. In that case they are not required to be kept for the entireChangeSetContextscope.Once a
ChangeSetContextis marked as transactional it can't be unmarked again. If theChangeSetContexthas been marked as transactional already this method doesn't have any effects. -
isMarkedTransactional
boolean isMarkedTransactional()- Returns:
true, if thisChangeSetContextwas marked transactional (seemarkTransactional()).
-
register
Registers aChangeSetListeneron theChangeSetContext, to be notified once theChangeSetContextis closed successfully or cancelled.- Parameters:
listener- theChangeSetListener
-