/* * delete - set - commit set - commit delete */ public void testSD() { ExtObjectContainer oc1 = openNewSession(); ExtObjectContainer oc2 = openNewSession(); ExtObjectContainer oc3 = openNewSession(); try { SimpleObject o1 = (SimpleObject) retrieveOnlyInstance(oc1, SimpleObject.class); oc1.delete(o1); SimpleObject o2 = (SimpleObject) retrieveOnlyInstance(oc2, SimpleObject.class); Assert.areEqual("hello", o2.getS()); o2.setS("o2"); oc2.store(o2); oc2.commit(); oc1.commit(); assertOccurrences(oc1, SimpleObject.class, 0); assertOccurrences(oc2, SimpleObject.class, 0); assertOccurrences(oc3, SimpleObject.class, 0); } finally { oc1.close(); oc2.close(); oc3.close(); } }
public void testSeparateSessions() { ExtObjectContainer oc1 = openNewSession(); ExtObjectContainer oc2 = openNewSession(); try { ObjectSet os1 = oc1.query(Item.class); ObjectSet os2 = oc2.query(Item.class); deleteObjectSet(oc1, os1); assertOccurrences(oc1, Atom.class, 0); assertOccurrences(oc2, Atom.class, 1); deleteObjectSet(oc2, os2); assertOccurrences(oc1, Atom.class, 0); assertOccurrences(oc2, Atom.class, 0); oc1.rollback(); assertOccurrences(oc1, Atom.class, 1); assertOccurrences(oc2, Atom.class, 0); oc1.commit(); assertOccurrences(oc1, Atom.class, 1); assertOccurrences(oc2, Atom.class, 0); deleteAll(oc2, Item.class); oc2.commit(); assertOccurrences(oc1, Atom.class, 0); assertOccurrences(oc2, Atom.class, 0); } finally { oc1.close(); oc2.close(); } }
/* * delete - set - commit delete - commit set */ public void _testDS() { ExtObjectContainer oc1 = openNewSession(); ExtObjectContainer oc2 = openNewSession(); ExtObjectContainer oc3 = openNewSession(); try { SimpleObject o1 = (SimpleObject) retrieveOnlyInstance(oc1, SimpleObject.class); oc1.delete(o1); SimpleObject o2 = (SimpleObject) retrieveOnlyInstance(oc2, SimpleObject.class); Assert.areEqual("hello", o2.getS()); o2.setS("o2"); oc2.store(o2); oc1.commit(); oc2.commit(); o1 = (SimpleObject) retrieveOnlyInstance(oc1, SimpleObject.class); oc1.refresh(o1, Integer.MAX_VALUE); Assert.areEqual("o2", o1.getS()); o2 = (SimpleObject) retrieveOnlyInstance(oc2, SimpleObject.class); oc2.refresh(o2, Integer.MAX_VALUE); Assert.areEqual("o2", o2.getS()); SimpleObject o3 = (SimpleObject) retrieveOnlyInstance(oc3, SimpleObject.class); oc1.refresh(o1, Integer.MAX_VALUE); Assert.areEqual("o2", o3.getS()); } finally { oc1.close(); oc2.close(); oc3.close(); } }
public void testRefresh() { ExtObjectContainer client1 = openNewSession(); ExtObjectContainer client2 = openNewSession(); TAItem item1 = (TAItem) retrieveInstance(client1); TAItem item2 = (TAItem) retrieveInstance(client2); assertDescendingRange(10, item1); assertDescendingRange(10, item2); item1.value(100); item1.next().value(200); client1.store(item1, 2); client1.commit(); Assert.areEqual(100, item1.value()); Assert.areEqual(200, item1.next().value()); Assert.areEqual(10, item2.value()); Assert.areEqual(9, item2.next().value()); // refresh 0 client2.refresh(item2, 0); Assert.areEqual(10, item2.value()); Assert.areEqual(9, item2.next().value()); // refresh 1 client2.refresh(item2, 1); Assert.areEqual(100, item2.value()); Assert.areEqual(9, item2.next().value()); // refresh 2 client2.refresh(item2, 2); Assert.areEqual(100, item2.value()); Assert.areEqual(200, item2.next().value()); updateAscendingWithRange(item1, 1000); client1.store(item1, 5); client1.commit(); client2.refresh(item2, 5); TAItem next2 = item2; for (int i = 1000; i < 1005; i++) { Assert.areEqual(i, next2.value()); next2 = next2.next(); } client1.close(); client2.close(); }
private void operateOnClient1And2( ArrayList4Operation<Integer> op1, ArrayList4Operation<Integer> op2) throws Exception { ExtObjectContainer client1 = openNewSession(); ExtObjectContainer client2 = openNewSession(); ArrayList4<Integer> list1 = retrieveAndAssertNullArrayList4(client1); ArrayList4<Integer> list2 = retrieveAndAssertNullArrayList4(client2); op1.operate(list1); op2.operate(list2); client1.store(list1); client2.store(list2); client1.commit(); client2.commit(); client1.close(); client2.close(); }
/** * Stores the config object in the database. Please call this after any modifications to the * config, it is not done automatically because the user interface will usually change many values * at once. */ public synchronized void storeAndCommit() { synchronized (mDB.lock()) { try { mDB.store(mStringParams, 3); mDB.store(mIntParams, 3); mDB.store(this); mDB.commit(); } catch (RuntimeException e) { System.gc(); mDB.rollback(); Logger.error(this, "ROLLED BACK!", e); throw e; } } }
public void testDelete() { ExtObjectContainer oc = fixture().db(); initGenericObjects(); ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME); Assert.isNotNull(rc); Query q = oc.query(); q.constrain(rc); ObjectSet results = q.execute(); while (results.hasNext()) { Object o = results.next(); oc.delete(o); } oc.commit(); // now query to make sure there are none left q = oc.query(); q.constrain(rc); q.descend("surname").constrain("John"); results = q.execute(); Assert.isTrue(results.size() == 0); }
public void concDelete(ExtObjectContainer oc) throws Exception { int size = countOccurences(oc, SimpleObject.class); if (size == 0) { // already deleted return; } Assert.areEqual(ELEMENT_COUNT, size); ObjectSet os = oc.query(ArrayItem.class); if (os.size() == 0) { // already deteled return; } Assert.areEqual(1, os.size()); ArrayItem item = (ArrayItem) os.next(); // waits for other threads Thread.sleep(500); oc.delete(item); oc.commit(); assertOccurrences(oc, SimpleObject.class, 0); }
public void testRefresh() { ExtObjectContainer client1 = openNewSession(); ExtObjectContainer client2 = openNewSession(); Item item1 = retrieveInstance(client1); Item item2 = retrieveInstance(client2); Item next1 = item1; int value = 10; while (next1 != null) { Assert.areEqual(value, next1.getValue()); next1 = next1.next(); value--; } Item next2 = item2; value = 10; while (next2 != null) { Assert.areEqual(value, next2.getValue()); next2 = next2.next(); value--; } item1.setValue(100); item1.next().setValue(200); client1.store(item1, 2); client1.commit(); Assert.areEqual(100, item1.getValue()); Assert.areEqual(200, item1.next().getValue()); Assert.areEqual(10, item2.getValue()); Assert.areEqual(9, item2.next().getValue()); // refresh 0 client2.refresh(item2, 0); Assert.areEqual(10, item2.getValue()); Assert.areEqual(9, item2.next().getValue()); // refresh 1 client2.refresh(item2, 1); Assert.areEqual(100, item2.getValue()); Assert.areEqual(9, item2.next().getValue()); // refresh 2 client2.refresh(item2, 2); Assert.areEqual(100, item2.getValue()); // FIXME: maybe a bug // Assert.areEqual(200, item2.next().getValue()); next1 = item1; value = 1000; while (next1 != null) { next1.setValue(value); next1 = next1.next(); value++; } client1.store(item1, 5); client1.commit(); client2.refresh(item2, 5); next2 = item2; for (int i = 1000; i < 1005; i++) { Assert.areEqual(i, next2.getValue()); next2 = next2.next(); } client1.close(); client2.close(); }