pub trait DataConn {
// Required methods
fn commit(&mut self, ag: &mut AsyncGroup) -> Result<()>;
fn is_committed(&self) -> bool;
fn rollback(&mut self, ag: &mut AsyncGroup) -> Result<()>;
fn close(&mut self);
// Provided methods
fn pre_commit(&mut self, ag: &mut AsyncGroup) -> Result<()> { ... }
fn post_commit(&mut self, ag: &mut AsyncGroup) -> Result<()> { ... }
fn on_txn_failure(
&mut self,
ag: &mut AsyncGroup,
reports: &[TxnFailureReport],
) { ... }
}Expand description
The trait that abstracts a connection per session to an external data service, such as a database, file system, or messaging service.
Its primary purpose is to enable cohesive transaction operations across multiple external data services within a single transaction context. Implementations of this trait provide the concrete input/output operations for their respective data services.
Methods declared within this trait are designed to handle transactional logic.
The AsyncGroup parameter in various methods allows for concurrent processing
when commit or rollback operations are time-consuming.
Required Methods§
Sourcefn commit(&mut self, ag: &mut AsyncGroup) -> Result<()>
fn commit(&mut self, ag: &mut AsyncGroup) -> Result<()>
Attempts to commit the changes made within this data connection’s transaction.
This method should encapsulate the logic required to finalize the transaction for the specific external data service.
§Parameters
ag: A mutable reference to anAsyncGroupfor potentially offloading time-consuming commit operations to a separate thread.
§Returns
errs::Result<()>:Ok(())if the commit is successful, or anerrs::Errif the commit fails.
Sourcefn is_committed(&self) -> bool
fn is_committed(&self) -> bool
Returns whether the transaction on this connection has been successfully committed.
Sourcefn rollback(&mut self, ag: &mut AsyncGroup) -> Result<()>
fn rollback(&mut self, ag: &mut AsyncGroup) -> Result<()>
Rolls back any changes made within this data connection’s transaction.
This method undoes all operations performed since the beginning of the transaction, restoring the data service to its state before the transaction began.
§Parameters
ag: A mutable reference to anAsyncGroup. This can be used to run the rollback asynchronously in a separate thread.
§Returns
errs::Result<()>:Ok(())if the rollback is successful, or anerrs::Errif it fails.
Provided Methods§
Sourcefn pre_commit(&mut self, ag: &mut AsyncGroup) -> Result<()>
fn pre_commit(&mut self, ag: &mut AsyncGroup) -> Result<()>
This method is executed before the transaction commit process for all DataConn instances
involved in the transaction.
This method provides a timing to execute unusual commit processes or update operations not supported by transactions beforehand. This allows other update operations to be rolled back if the operations in this method fail.
§Parameters
ag: A mutable reference to anAsyncGroup. This can be used to run the pre-commit asynchronously in a separate thread.
§Returns
errs::Result<()>:Ok(())if pre-commit is successful, or anerrs::Errif it fails.
Sourcefn post_commit(&mut self, ag: &mut AsyncGroup) -> Result<()>
fn post_commit(&mut self, ag: &mut AsyncGroup) -> Result<()>
This method is executed after the transaction commit process has successfully completed
for all DataConn instances involved in the transaction.
It provides a moment to perform follow-up actions that depend on a successful commit.
For example, after a database commit, a messaging service’s DataConn might use this
method to send a “transaction completed” message.
§Parameters
ag: A mutable reference to anAsyncGroupfor potentially offloading concurrent post-commit operations.
§Returns
errs::Result<()>:Ok(())if post-commit tasks succeed, or anerrs::Errif they fail.
Sourcefn on_txn_failure(&mut self, ag: &mut AsyncGroup, reports: &[TxnFailureReport])
fn on_txn_failure(&mut self, ag: &mut AsyncGroup, reports: &[TxnFailureReport])
A lifecycle callback invoked when a transaction fails and a rollback is executed.
This allows the data connection to handle post-failure tasks or custom logic based on the provided transaction failure reports.
§Parameters
ag: A mutable reference to anAsyncGroupfor asynchronous task execution.reports: A slice ofTxnFailureReportcontaining failure details for all connections.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".