/** * Returns the count of all stored objects in this box. */ public long count() { return count(0); }
@Override public void run() { box.count(); } });
@Override public void run() { counts[0] = box.count(); store.runInReadTx(new Runnable() { @Override public void run() { counts[1] = box.count(); } }); } });
@Override public long[] call() throws Exception { long count1 = store.callInReadTx(new Callable<Long>() { @Override public Long call() throws Exception { return box.count(); } }); return new long[]{box.count(), count1}; } });
@Override public void run() { // Dummy TX, still will be committed, should not add anything to objectCounts getTestEntityBox().count(); } });
@Override public void run() { try { getTestEntityBox().count(); } catch (Exception e) { exHolder[0] = e; } } });
@Override public void run() { getTestEntityBox().count(); thread.start(); try { thread.join(5000); } catch (InterruptedException e) { e.printStackTrace(); } } });
@Override public void run() { // Dummy TX, still will be committed getTestEntityBox().count(); } });
@Override @SuppressWarnings("NullableProblems") public Long transform(Class source) throws Exception { assertNotSame(testThread, Thread.currentThread()); return store.boxFor(source).count(); } });
@Test public void testClear_removeFromTargetBox() { Customer customer = putCustomerWithOrders(5); ToMany<Order> toMany = (ToMany<Order>) customer.orders; toMany.setRemoveFromTargetBox(true); toMany.clear(); customerBox.put(customer); assertEquals(0, orderBox.count()); }
@Test public void testClear_removeFromTargetBox() { Customer customer = putCustomerWithOrders(5); ToMany<Order> toMany = customer.ordersStandalone; toMany.setRemoveFromTargetBox(true); toMany.clear(); customerBox.put(customer); assertEquals(0, orderBox.count()); }
@Test public void testPanicModeRemoveAllObjects() { assertEquals(0, box.panicModeRemoveAll()); putTestEntities(7); assertEquals(7, box.panicModeRemoveAll()); assertEquals(0, box.count()); }
@Test public void testAddRemove() { Customer customer = putCustomer(); ToMany<Order> toMany = (ToMany<Order>) customer.orders; Order order = new Order(); toMany.add(order); toMany.remove(order); toMany.applyChangesToDb(); assertEquals(0, orderBox.count()); }
@Test public void testAddRemove_notPersisted() { Customer customer = putCustomer(); ToMany<Order> toMany = customer.ordersStandalone; Order order = new Order(); toMany.add(order); toMany.remove(order); customerBox.put(customer); assertEquals(0, orderBox.count()); }
@Test public void testRemove() { putTestEntitiesScalars(); Query<TestEntity> query = box.query().greater(simpleInt, 2003).build(); assertEquals(6, query.remove()); assertEquals(4, box.count()); }
@Test public void testClear() { int count = 5; Customer customer = putCustomerWithOrders(count); ToMany<Order> toMany = customer.ordersStandalone; toMany.clear(); customerBox.put(customer); Customer customer2 = customerBox.get(customer.getId()); assertEquals(0, customer2.getOrdersStandalone().size()); assertEquals(count, orderBox.count()); }
private void assertOrder2And4Removed(int count, Customer customer, ToMany<Order> toMany) { assertEquals(count, orderBox.count()); toMany.reset(); assertEquals(3, toMany.size()); assertEquals("order1", toMany.get(0).getText()); assertEquals("order3", toMany.get(1).getText()); assertEquals("order5", toMany.get(2).getText()); }
private void assertOrder2And4Removed(int count, Customer customer, ToMany<Order> toMany) { assertEquals(count - 2, countOrdersWithCustomerId(customer.getId())); assertEquals(count, orderBox.count()); assertEquals(2, countOrdersWithCustomerId(0)); toMany.reset(); assertEquals(3, toMany.size()); assertEquals("order1", toMany.get(0).getText()); assertEquals("order3", toMany.get(1).getText()); assertEquals("order5", toMany.get(2).getText()); }