Begin Transaction
Siminov Framework edited this page Jan 16, 2016
·
8 revisions
Begins a transaction in EXCLUSIVE mode.
Transactions can be nested. When the outer transaction is ended all of the work done in that transaction and all of the nested transactions will be committed or rolled back. The changes will be rolled back if any transaction is ended without being marked as clean(by calling commitTransaction). Otherwise they will be committed.
public static final void beginTransaction(final DatabaseDescriptor databaseDescriptor) throws DatabaseException;
Book c = new Book();
c.setTitle(Book.BOOK_TYPE_C);
c.setDescription(applicationContext.getString(R.string.c_description));
c.setAuthor(applicationContext.getString(R.string.c_author));
c.setLink(applicationContext.getString(R.string.c_link));
DatabaseDescriptor databaseDescriptor = c.getDatabaseDescriptor();
try {
Database.beginTransaction(databaseDescriptor);
c.save();
Database.commitTransaction(databaseDescriptor);
} catch(DatabaseException de) {
//Log it.
} finally {
Database.endTransaction(databaseDescriptor);
}
+ (void)beginTransaction:(SICDatabaseDescriptor *)databaseDescriptor;
Book *c = [[Book alloc] init];
[c setTitle:[Book BOOK_TYPE_C]];
[c setDescription:@"c_description"];
[c setAuthor:@"c_author"];
[c setLink:@"c_link"];
SICDatabaseDescriptor *databaseDescriptor = [c getDatabaseDescriptor];
@try {
[SICDatabase beginTransaction:databaseDescriptor];
[c save];
[SICDatabase commitTransaction:databaseDescriptor];
} @catch(SICDatabaseException *databaseException) {
//Log it.
} @finally {
[SICDatabase endTransaction:databaseDescriptor];
}
public static void BeginTransaction(DatabaseDescriptor databaseDescriptor);
Book c = new Book();
c.SetTitle(Book.BOOK_TYPE_C);
c.SetDescription("c_description");
c.SetAuthor("c_author");
c.SetLink("c_link");
DatabaseDescriptor databaseDescriptor = c.GetDatabaseDescriptor();
try
{
Database.BeginTransaction(databaseDescriptor);
c.Save();
Database.CommitTransaction(databaseDescriptor);
}
catch(DatabaseException de)
{
//Log it.
}
finally
{
Database.EndTransaction(databaseDescriptor);
}
- this.beginTransaction = function(databaseDescriptor);
- this.beginTransactionAsync = function(databaseDescriptor, callback);
/** Begin Transaction Sample **/
var c = new Book();
c.setTitle(Book.BOOK_TYPE_C);
c.setDescription("C_description");
c.setAuthor("C_author");
c.setLink("C_link");
var databaseDescriptor = c.getDatabaseDescriptor();
try {
Database.beginTransaction(databaseDescriptor);
c.save();
Database.commitTransaction(databaseDescriptor);
} catch(de) {
//Log it.
} finally {
Database.endTransaction(databaseDescriptor);
}
/** Begin Transaction Async Sample **/
var c = new Book();
c.setTitle(Book.BOOK_TYPE_C);
c.setDescription("C_description");
c.setAuthor("C_author");
c.setLink("C_link");
var callback = new Callback();
callback.onExecute = function(transaction) {
}
callback.onSuccess = function() {
}
var databaseDescriptor = new Book().getDatabaseDescriptor();
Database.beginTransactionAsync(databaseDescriptor, callback);