-
Notifications
You must be signed in to change notification settings - Fork 10
Transactions
Siim Kinks edited this page Nov 21, 2016
·
1 revision
By default every operation happens without explicitly defining a transaction. The only exception is when operation involved table has any complex columns - then the whole operation is wrapped inside a transaction.
SqliteMagic also supports creating transactions manually:
Transaction transaction = SqliteMagic.newTransaction();
try {
// Perform DB operations
transaction.markSuccessful();
} finally {
transaction.end();
}
// OR use try-with-resource when available
try (Transaction transaction = SqliteMagic.newTransaction()) {
// Perform DB operations
transaction.markSuccessful();
}In the example above the transaction is created on the default database connection. To create transactions on any other database connection just call newTransaction() on the desired connection:
DbConnection dbConnection = // ...
try (Transaction transaction = dbConnection.newTransaction()) {
// Perform DB operations
transaction.markSuccessful();
}For more information about database connections see Multiple Database Connections.