pub trait Trigger: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn put(
&self,
txn_id: Option<u64>,
key: &[u8],
old_data: Option<&[u8]>,
new_data: &[u8],
);
fn delete(&self, txn_id: Option<u64>, key: &[u8], old_data: &[u8]);
// Provided methods
fn commit(&self, _txn_id: u64) { ... }
fn abort(&self, _txn_id: u64) { ... }
fn add_trigger(&self, _txn_id: Option<u64>) { ... }
fn remove_trigger(&self, _txn_id: Option<u64>) { ... }
}Expand description
A user-supplied database / transaction trigger.
Register one or more triggers on a crate::DatabaseConfig; the engine
fires the record-operation methods (put /
delete) within the transaction after each change, and
the transaction-lifecycle methods (commit /
abort) when the transaction resolves.
JE com.sleepycat.je.trigger.Trigger + TransactionTrigger.
Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
The trigger’s name. All triggers on one database must have unique
names. JE Trigger.getName.
Sourcefn put(
&self,
txn_id: Option<u64>,
key: &[u8],
old_data: Option<&[u8]>,
new_data: &[u8],
)
fn put( &self, txn_id: Option<u64>, key: &[u8], old_data: Option<&[u8]>, new_data: &[u8], )
The trigger method invoked after a successful put, i.e. one that
actually modified the database.
For a new insert, old_data is None; for an update of an existing
record, old_data is Some(previous). new_data is always present.
Fired within the transaction, after the change is applied.
JE Trigger.put(Transaction, DatabaseEntry key, DatabaseEntry oldData, DatabaseEntry newData).
txn_id— the transaction id, orNoneif non-transactional.key— the (non-null) primary key.old_data— the data before the change, orNoneif the record did not previously exist.new_data— the (non-null) data after the change.
Sourcefn delete(&self, txn_id: Option<u64>, key: &[u8], old_data: &[u8])
fn delete(&self, txn_id: Option<u64>, key: &[u8], old_data: &[u8])
The trigger method invoked after a successful delete, i.e. one that
actually removed a key/data pair. Fired within the transaction, after
the change is applied.
JE Trigger.delete(Transaction, DatabaseEntry key, DatabaseEntry oldData).
txn_id— the transaction id, orNoneif non-transactional.key— the (non-null) primary key.old_data— the (non-null) data that was associated with the deleted key.
Provided Methods§
Sourcefn commit(&self, _txn_id: u64)
fn commit(&self, _txn_id: u64)
The trigger method invoked after the transaction that modified this
trigger’s database has committed. Only invoked if the database was
modified during the transaction. Default: no-op (JE: trigger does not
implement TransactionTrigger).
JE TransactionTrigger.commit(Transaction).
Sourcefn abort(&self, _txn_id: u64)
fn abort(&self, _txn_id: u64)
The trigger method invoked after the transaction that modified this trigger’s database has aborted. Only invoked if the database was modified during the transaction. Default: no-op.
JE TransactionTrigger.abort(Transaction).
Sourcefn add_trigger(&self, _txn_id: Option<u64>)
fn add_trigger(&self, _txn_id: Option<u64>)
Lifecycle hook invoked when the trigger is added to the database (the first trigger method invoked, exactly once). Default: no-op.
JE Trigger.addTrigger(Transaction).
Sourcefn remove_trigger(&self, _txn_id: Option<u64>)
fn remove_trigger(&self, _txn_id: Option<u64>)
Lifecycle hook invoked when the trigger is removed from the database (e.g. on close). Default: no-op.
JE Trigger.removeTrigger(Transaction).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".