use of com.squareup.sqlbrite.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method transactionOnlyNotifiesOnce.
@Test
public void transactionOnlyNotifiesOnce() {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
Transaction transaction = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, employee("nick", "Nick Nickers"));
o.assertNoMoreEvents();
transaction.markSuccessful();
} finally {
transaction.end();
}
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
}
use of com.squareup.sqlbrite.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method transactionDoesNotThrow.
@Test
public void transactionDoesNotThrow() {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
Transaction transaction = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, employee("nick", "Nick Nickers"));
transaction.markSuccessful();
} finally {
// Transactions should not throw on close().
transaction.close();
}
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
}
use of com.squareup.sqlbrite.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method synchronousQueryDuringTransaction.
@Test
public void synchronousQueryDuringTransaction() {
Transaction transaction = db.newTransaction();
try {
transaction.markSuccessful();
assertCursor(db.query(SELECT_EMPLOYEES)).hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
} finally {
transaction.end();
}
}
use of com.squareup.sqlbrite.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method queryCreatedBeforeTransactionButSubscribedAfter.
@Test
public void queryCreatedBeforeTransactionButSubscribedAfter() {
Observable<Query> query = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES);
Transaction transaction = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, employee("nick", "Nick Nickers"));
transaction.markSuccessful();
} finally {
transaction.end();
}
query.subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
}
use of com.squareup.sqlbrite.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method transactionRollbackDoesNotNotify.
@Test
public void transactionRollbackDoesNotNotify() {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
Transaction transaction = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, employee("nick", "Nick Nickers"));
// No call to set successful.
} finally {
transaction.end();
}
o.assertNoMoreEvents();
}
Aggregations