final AtomicInteger count = new AtomicInteger(0);
DatabaseManager dbMan = database.getDatabaseManager();
// add a transaction listener
TransactionListener l0 = new TransactionListener() {
public void transactionPerformed(Transaction txn) {
count.incrementAndGet();
}
};
dbMan.addTransactionListener(l0);
// create and execute a transaction
Transaction txn = dbMan.createTransaction();
txn.createDatabase("test", 1);
txn.insertRecord("test", 0, "hello".getBytes(), "world".getBytes());
txn.insertRecord("test", 0, "key".getBytes(), "value".getBytes());
dbMan.executeTransaction(txn);
assertEquals(1, count.get());
// create and execute another transaction (which is empty)
txn = dbMan.createTransaction();
// add a listener before executing the transaction and wait for the
// notification
TransactionListener l1 = new TransactionListener() {
public void transactionPerformed(Transaction txn) {
count.incrementAndGet();
}
};
dbMan.addTransactionListener(l1);