DatabasetTrigger
defines the trigger methods associated with a database. They provide a mechanism to track the database definition operations used to manage the lifecycle of the database itself, as well as the record operations used to modify the contents of the database. The following table captures the relationship between the database granularity operations and their associated trigger methods.
Database Operation | Trigger Method |
{@link Environment#openDatabase Environment.openDatabase} resulting inthe creation of a new primary database. Or the first open of a database for write operations. | {@link #open open} |
{@link Database#close Database.close} the close of a database that wasopened for write operations. | {@link #close close} |
{@link Environment#removeDatabase Environment.removeDatabase} | {@link #remove remove} |
{@link Environment#truncateDatabase Environment.truncateDatabase} | {@link #truncate truncate} |
{@link Environment#renameDatabase Environment.renameDatabase} | {@link #rename truncate} |
The trigger methods {@link #put put} and {@link #delete delete} are used totrack all record operations on the database.
A trigger method takes a transaction as its first argument. If the environment is not transactional, the argument is null. In all other cases, it's a valid transaction ( {@link Transaction#isValid() Transaction.isValid}is true) and the trigger can use this transaction to make it's own set of accompanying changes.
If the invocation of a trigger results in a runtime exception, the transaction (if one was associated with the method) is invalidated and any subsequent triggers associated with the operation are skipped. It's the caller's responsibility to handle the exception and abort the invalidated transaction. If the exception is thrown during the replay of a transaction on a replica in an HA application, the environment is invalidated and a new environment handle must be created.
A Trigger is associated with a database via {@link DatabaseConfig#setTriggers DatabaseConfig.setTriggers}.
Note that all subtypes of Trigger must be serializable, because they are stored persistently in the environment.
|
|
|
|