/** Loads the remaining entities (if any) that were not loaded before. Applies to cached lazy lists only. */ public void loadRemaining() { if (loadedCount != size) { checkCached(); // use single reader only for efficiency box.getStore().runInReadTx(new Runnable() { @Override public void run() { for (int i = 0; i < size; i++) { get(i); } } }); } }
@Test(expected = DbException.class) public void testRunInReadTx_putFails() { store.runInReadTx(new Runnable() { @Override public void run() { getTestEntityBox().put(new TestEntity()); } }); }
@Override public void run() { counts[0] = box.count(); store.runInReadTx(new Runnable() { @Override public void run() { counts[1] = box.count(); } }); } });
box.getStore().runInReadTx(new Runnable() { @Override public void run() {
@Test public void testRunInReadTx_recursiveWriteTxFails() { store.runInReadTx(new Runnable() { @Override public void run() { try { store.runInTx(new Runnable() { @Override public void run() { } }); fail("Should have thrown"); } catch (IllegalStateException e) { // OK } } }); }
@Test public void testGetInTx() { Customer customer = putCustomerWithOrders(2); customer = customerBox.get(customer.getId()); final ToMany<Order> toMany = customer.getOrdersStandalone(); store.runInReadTx(new Runnable() { @Override public void run() { assertGetOrder1And2(toMany); } }); }
@Test public void testRunInReadTxAndThenPut() { final Box<TestEntity> box = getTestEntityBox(); store.runInReadTx(new Runnable() { @Override public void run() { box.count(); } }); // Verify that box does not hang on to the read-only TX by doing a put box.put(new TestEntity()); assertEquals(1, box.count()); }
store.runInReadTx(new Runnable() { @Override public void run() {
@Test public void testRunInReadTx() { final Box<TestEntity> box = getTestEntityBox(); final long[] counts = {0, 0}; box.put(new TestEntity()); store.runInReadTx(new Runnable() { @Override public void run() { counts[0] = box.count(); store.runInReadTx(new Runnable() { @Override public void run() { counts[1] = box.count(); } }); } }); assertEquals(1, counts[0]); assertEquals(1, counts[1]); }
private void runQueryById(boolean randomIds, boolean inReadTx) { List<SimpleEntity> entities = prepareAndPutEntities(false); final long[] idsToLookup = new long[numberEntities]; for (int i = 0; i < numberEntities; i++) { idsToLookup[i] = randomIds ? 1 + random.nextInt(numberEntities) : 1 + i; } startBenchmark("query"); if(inReadTx) { store.runInReadTx(new Runnable() { @Override public void run() { getById(idsToLookup); } }); } else { getById(idsToLookup); } stopBenchmark(); }