use of com.squareup.sqlbrite3.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method synchronousQueryWithSupportSQLiteQueryDuringTransaction.
@Test
public void synchronousQueryWithSupportSQLiteQueryDuringTransaction() {
Transaction transaction = db.newTransaction();
try {
transaction.markSuccessful();
assertCursor(db.query(new SimpleSQLiteQuery(SELECT_EMPLOYEES))).hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
} finally {
transaction.end();
}
}
use of com.squareup.sqlbrite3.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method nonExclusiveTransactionWorks.
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.HONEYCOMB)
@Test
public void nonExclusiveTransactionWorks() throws InterruptedException {
final CountDownLatch transactionStarted = new CountDownLatch(1);
final CountDownLatch transactionProceed = new CountDownLatch(1);
final CountDownLatch transactionCompleted = new CountDownLatch(1);
new Thread() {
@Override
public void run() {
Transaction transaction = db.newNonExclusiveTransaction();
transactionStarted.countDown();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("hans", "Hans Hanson"));
transactionProceed.await(10, SECONDS);
} catch (InterruptedException e) {
throw new RuntimeException("Exception in transaction thread", e);
}
transaction.markSuccessful();
transaction.close();
transactionCompleted.countDown();
}
}.start();
assertThat(transactionStarted.await(10, SECONDS)).isTrue();
// Simple query
Employee employees = db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES + " LIMIT 1").lift(Query.mapToOne(Employee.MAPPER)).blockingFirst();
assertThat(employees).isEqualTo(new Employee("alice", "Alice Allison"));
transactionProceed.countDown();
assertThat(transactionCompleted.await(10, SECONDS)).isTrue();
}
use of com.squareup.sqlbrite3.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method nestedTransactionsOnlyNotifyOnce.
@Test
public void nestedTransactionsOnlyNotifyOnce() {
db.createQuery(TABLE_EMPLOYEE, SELECT_EMPLOYEES).subscribe(o);
o.assertCursor().hasRow("alice", "Alice Allison").hasRow("bob", "Bob Bobberson").hasRow("eve", "Eve Evenson").isExhausted();
Transaction transactionOuter = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
Transaction transactionInner = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("nick", "Nick Nickers"));
transactionInner.markSuccessful();
} finally {
transactionInner.end();
}
transactionOuter.markSuccessful();
} finally {
transactionOuter.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 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.sqlbrite3.BriteDatabase.Transaction in project sqlbrite by square.
the class BriteDatabaseTest method nestedTransactionsOnMultipleTables.
@Test
public void nestedTransactionsOnMultipleTables() {
db.createQuery(BOTH_TABLES, SELECT_MANAGER_LIST).subscribe(o);
o.assertCursor().hasRow("Eve Evenson", "Alice Allison").isExhausted();
Transaction transactionOuter = db.newTransaction();
try {
Transaction transactionInner = db.newTransaction();
try {
db.insert(TABLE_EMPLOYEE, CONFLICT_NONE, employee("john", "John Johnson"));
transactionInner.markSuccessful();
} finally {
transactionInner.end();
}
transactionInner = db.newTransaction();
try {
db.insert(TABLE_MANAGER, CONFLICT_NONE, manager(testDb.aliceId, testDb.bobId));
transactionInner.markSuccessful();
} finally {
transactionInner.end();
}
transactionOuter.markSuccessful();
} finally {
transactionOuter.end();
}
o.assertCursor().hasRow("Eve Evenson", "Alice Allison").hasRow("Alice Allison", "Bob Bobberson").isExhausted();
}
Aggregations