Transactions



Simple transactional

For transactions, Daobab provides two simple scenarios:

  • automatic transactions for each Insert/Update/Delete Query (default)
    Transaction openned automatically before query execution, commited or rollbacked automatically after
  • transactions manually openned and closed
    Transaction openned and closed manually. Commited or rollbacked programically.

For automatic commitment, just use default database modification methods:

entity.insert(db);
Delete.from(db,tabApp).where(tabApp.colName(),"AppName").execute();

When you want to avoid commit per query, use noTx() methods.

Delete.from(db,tabApp).where(tabApp.colName(),"AppName").executeNoTx();

Annotations are not in use, so that transaction usage into interfaces is possible.

Manual transactions

To control transaction, you need beginTransation - this opration created new Target with opened transaction. Make multiple operations with NoTx() methods... finally commit or close target (transaction)

OpenedTransactionTarget odb=db.beginTransaction();
try {
	Delete.from(odb, tabApp).where(tabApp.colName(), "App1").executeNoTx();
	Delete.from(odb, tabApp).where(tabApp.colName(), "App2").executeNoTx();
	odb.commit();
}catch(Exception e){
	odb.rollback();
}