use of com.squareup.sqlbrite3.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, CONFLICT_NONE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, 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.sqlbrite3.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method synchronousQueryWithSupportSQLiteQueryDuringTransactionSeesChanges.
@Test
public void synchronousQueryWithSupportSQLiteQueryDuringTransactionSeesChanges() {
Transaction transaction = db.newTransaction();
try {
assertCursor(db.query(new SimpleSQLiteQuery(SELECT_EMPLOYEES))).hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("nick", "Nick Nickers"));
assertCursor(db.query(new SimpleSQLiteQuery(SELECT_EMPLOYEES))).hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").hasRow("john", "John Johnson").hasRow("nick", "Nick Nickers").isExhausted();
transaction.markSuccessful();
} finally {
transaction.end();
}
}
use of com.squareup.sqlbrite3.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method callingEndMultipleTimesThrows.
@Test
public void callingEndMultipleTimesThrows() {
Transaction transaction = db.newTransaction();
transaction.end();
try {
transaction.end();
fail();
} catch (IllegalStateException e) {
assertThat(e).hasMessage("Not in transaction.");
}
}
use of com.squareup.sqlbrite3.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, CONFLICT_NONE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("nick", "Nick Nickers"));
// No call to set successful.
} finally {
transaction.end();
}
o.assertNoMoreEvents();
}
use of com.squareup.sqlbrite3.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, CONFLICT_NONE, employee("john", "John Johnson"));
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, 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();
}
Aggregations