Interface DataConn
DataHub.
Implementations encapsulate connection state and operations for external resources such as relational databases, NoSQL stores, or web services. During a transaction, connections progress through pre-commit, commit, and post-commit phases, and support rollback and failure reporting when errors occur.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordRepresents an error when one or more data connections fail during the commit phase.static final recordRepresents an error when one or more data connections fail during the post-commit phase.static final recordRepresents an error when one or more data connections fail during the pre-commit phase. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes and disposes of this data connection, releasing any held resources.voidcommit(AsyncGroup ag) Commits changes made through this connection.booleanChecks whether this connection has been successfully committed.default voidonTxnFailure(AsyncGroup ag, List<TxnFailureReport> reports) Notifies this connection of a transaction failure with detailed failure reports.default voidpostCommit(AsyncGroup ag) Performs post-commit operations after all connections in a transaction have successfully committed.default voidpreCommit(AsyncGroup ag) Prepares this connection for commit prior to the main commit phase.voidrollback(AsyncGroup ag) Rolls back changes made through this connection.
-
Method Details
-
commit
Commits changes made through this connection.Async background tasks may be registered to the provided
AsyncGroupduring commit processing.- Parameters:
ag- the asynchronous group for registering background tasks- Throws:
com.github.sttk.errs.Err- if committing the transaction changes fails
-
preCommit
Prepares this connection for commit prior to the main commit phase.The default implementation does nothing. Subclasses can override this method to perform pre-commit checks or flush pending writes.
- Parameters:
ag- the asynchronous group for registering background tasks- Throws:
com.github.sttk.errs.Err- if pre-commit preparation or validation fails
-
postCommit
Performs post-commit operations after all connections in a transaction have successfully committed.The default implementation does nothing. Subclasses can override this method to perform cleanup or trigger post-commit notifications.
- Parameters:
ag- the asynchronous group for registering background tasks- Throws:
com.github.sttk.errs.Err- if post-commit processing fails
-
isCommitted
boolean isCommitted()Checks whether this connection has been successfully committed.- Returns:
trueif this connection was committed;falseotherwise
-
rollback
Rolls back changes made through this connection.This method is invoked when a transaction fails and must restore the connection or underlying storage to its pre-transaction state.
- Parameters:
ag- the asynchronous group for registering background tasks- Throws:
com.github.sttk.errs.Err- if rolling back connection changes fails
-
onTxnFailure
Notifies this connection of a transaction failure with detailed failure reports.The default implementation does nothing. Implementations can inspect failure reports to log diagnostics or take recovery actions.
- Parameters:
ag- the asynchronous group for registering background tasksreports- the list of transaction failure reports
-
close
void close()Closes and disposes of this data connection, releasing any held resources.
-