public void test() { ObjectContainer oc = Test.objectContainer(); ObjectSet objectSet = oc.queryByExample(new CallbackCanDelete("p1", null)); CallbackCanDelete ccd = (CallbackCanDelete) objectSet.next(); oc.deactivate(ccd, Integer.MAX_VALUE); oc.delete(ccd); }
private Item storedItem(String id) { Query query = newQuery(Item.class); query.descend("_id").constrain(id); ObjectSet<Item> result = query.execute(); Assert.isTrue(result.hasNext()); return result.next(); }
private void restoreMembers(Data data) { Query q = newQuery(Data.class); ObjectSet objectSet = q.execute(); Data rdata = (Data) objectSet.next(); data.i_map = rdata.i_map; data.i_helper = rdata.i_helper; }
public void concRead(ExtObjectContainer oc) { for (int i = 0; i < COUNT; i++) { Query q = oc.query(); q.constrain(Atom.class); q.descend("name").constrain("ibi" + i); ObjectSet objectSet = q.execute(); Assert.areEqual(1, objectSet.size()); Atom child = (Atom) objectSet.next(); q = oc.query(); q.constrain(IndexedByIdentityTestCase.class); q.descend("atom").constrain(child).identity(); objectSet = q.execute(); Assert.areEqual(1, objectSet.size()); IndexedByIdentityTestCase ibi = (IndexedByIdentityTestCase) objectSet.next(); Assert.areSame(child, ibi.atom); } }
public void checkUpdateSameObject(ExtObjectContainer oc) throws Exception { Query query = oc.query(); query.descend("_s").constrain(testString + COUNT / 2); ObjectSet result = query.execute(); Assert.areEqual(1, result.size()); SimpleObject o = (SimpleObject) result.next(); int i = o.getI(); Assert.isTrue(COUNT <= i && i < COUNT + threadCount()); }
private void assertOrdered(ObjectSet result) { Assert.areEqual(IDS.length, result.size()); int previousId = 0; while (result.hasNext()) { Data data = (Data) result.next(); Assert.isTrue(previousId < data._id); previousId = data._id; } }
public void testAllThere() throws Exception { for (int i = 0; i < FOOS.length; i++) { Query q = createQuery(FOOS[i]); ObjectSet objectSet = q.execute(); Assert.areEqual(1, objectSet.size()); FieldIndexItem fii = (FieldIndexItem) objectSet.next(); Assert.areEqual(FOOS[i], fii.foo); } }
public void concUpdateSameObject(ExtObjectContainer oc, int seq) throws Exception { Query query = oc.query(); query.descend("_s").constrain(testString + COUNT / 2); ObjectSet result = query.execute(); Assert.areEqual(1, result.size()); SimpleObject o = (SimpleObject) result.next(); o.setI(COUNT + seq); oc.store(o); }
private void assertQueryForTimestamp(Item expected, long timestamp) { Query query = db().query(); query.constrain(Item.class); query.descend(VirtualField.COMMIT_TIMESTAMP).constrain(timestamp); ObjectSet<Object> objectSet = query.execute(); Assert.areEqual(1, objectSet.size()); Item actual = (Item) objectSet.next(); Assert.areSame(expected, actual); }
private boolean expect(ObjectContainer container, String[] names) { Collection4 expected = new Collection4(names); ObjectSet actual = container.query(CrashData.class); while (actual.hasNext()) { CrashData current = (CrashData) actual.next(); if (!expected.remove(current._name)) { return false; } } return expected.isEmpty(); }
public void testIdentity() { Query q = st.query(); q.constrain(new STInteger(1)); ObjectSet set = q.execute(); STInteger identityConstraint = (STInteger) set.next(); identityConstraint.i_int = 9999; q = st.query(); q.constrain(identityConstraint).identity(); identityConstraint.i_int = 1; st.expectOne(q, store()[1]); }
public void concUpdate(ExtObjectContainer oc, int seq) throws Exception { Query q = oc.query(); q.constrain(IndexedByIdentityTestCase.class); ObjectSet os = q.execute(); Assert.areEqual(COUNT, os.size()); while (os.hasNext()) { IndexedByIdentityTestCase idi = (IndexedByIdentityTestCase) os.next(); idi.atom.name = "updated" + seq; oc.store(idi); Thread.sleep(100); } }
public void testQuery() { Query q = Test.query(); ObjectSet objectSet = q.execute(); Test.ensure(objectSet.size() >= 2); int i = 0; while (objectSet.hasNext()) { Object obj = objectSet.next(); Test.ensure(obj != null); i++; } Test.ensure(i >= 2); }
public void testNotIdentity() { Query q = st.query(); q.constrain(new STInteger(1)); ObjectSet set = q.execute(); STInteger identityConstraint = (STInteger) set.next(); identityConstraint.i_int = 9080; q = st.query(); q.constrain(identityConstraint).identity().not(); identityConstraint.i_int = 1; Object[] r = store(); st.expect(q, new Object[] {r[0], r[2], r[3]}); }
public void concUpdateDifferentObject(ExtObjectContainer oc, int seq) throws Exception { Query query = oc.query(); query .descend("_s") .constrain(testString + seq) .and(query.descend("_i").constrain(new Integer(seq))); ObjectSet result = query.execute(); Assert.areEqual(1, result.size()); SimpleObject o = (SimpleObject) result.next(); o.setI(seq + COUNT); oc.store(o); }
public void test() { Query q = st.query(); Object[] r = store(); q.constrain(new Helper("aaa")); ObjectSet os = q.execute(); Helper helperA = (Helper) os.next(); q = st.query(); q.constrain(STIdentityEvaluation.class); q.descend("helper").constrain(helperA).identity(); q.constrain(new IncludeAllEvaluation()); st.expect(q, new Object[] {r[1], r[2], r[3]}); }
private void tUpdateB(ExtObjectContainer oc) { ObjectSet res = query(oc, "b"); CreateIndexFor ci = (CreateIndexFor) res.next(); ci.i_name = "j"; oc.store(ci); res = query(oc, "b"); Assert.areEqual(0, res.size()); res = query(oc, "j"); Assert.areEqual(1, res.size()); ci.i_name = "b"; oc.store(ci); tQueryB(oc); }
public void checkUpdateDifferentObject(ExtObjectContainer oc) throws Exception { ObjectSet result = oc.query(SimpleObject.class); Assert.areEqual(COUNT, result.size()); while (result.hasNext()) { SimpleObject o = (SimpleObject) result.next(); int i = o.getI(); if (i >= COUNT) { i -= COUNT; } Assert.areEqual(testString + i, o.getS()); } }
public void testQueryForVersionNumber() { store(new Item(NEWER)); db().commit(); Item newer = itemByName(NEWER); long version = version(newer); Query query = db().query(); query.descend(VirtualField.COMMIT_TIMESTAMP).constrain(new Long(version)).smaller().not(); ObjectSet<Item> set = query.execute(); Assert.areEqual(1, set.size()); Assert.areSame(newer, set.next()); }
private void populate(ObjectContainer container) { for (int i = 0; i < 10; i++) { container.store(new Item("delme")); } CrashData one = new CrashData(null, "one"); CrashData two = new CrashData(one, "two"); CrashData three = new CrashData(one, "three"); container.store(one); container.store(two); container.store(three); container.commit(); ObjectSet objectSet = container.query(Item.class); while (objectSet.hasNext()) { container.delete(objectSet.next()); } }
public void test() { Query q = Test.query(); q.constrain(new TestStringBuffer("Vera")); q.descend("sb").constraints().contains(); ObjectSet os = q.execute(); Test.ensure(os.size() == 1); TestStringBuffer tbs = (TestStringBuffer) os.next(); Test.ensure(tbs.sb.toString().equals("Aloe Vera")); // q = Test.query(); // q.constrain(new TestStringBuffer("Yohaa")); // os = q.execute(); // Test.ensure(os.size() == 1); // tbs = (TestStringBuffer)os.next(); // Test.ensure(tbs.sb.toString().equals("Yohaa")); }
public void checkUpdate(ExtObjectContainer oc) { Query q = oc.query(); q.constrain(IndexedByIdentityTestCase.class); ObjectSet os = q.execute(); Assert.areEqual(COUNT, os.size()); String expected = null; while (os.hasNext()) { IndexedByIdentityTestCase idi = (IndexedByIdentityTestCase) os.next(); if (expected == null) { expected = idi.atom.name; Assert.isTrue(expected.startsWith("updated")); Assert.isTrue(expected.length() > "updated".length()); } Assert.areEqual(expected, idi.atom.name); } }
private void tExpectInts(Query q, int[] ints, int zeroSize) { ObjectSet res = q.execute(); Assert.areEqual(ints.length + zeroSize, res.size()); while (res.hasNext()) { CreateIndexFor ci = (CreateIndexFor) res.next(); for (int i = 0; i < ints.length; i++) { if (ints[i] == ci.i_int) { ints[i] = 0; break; } } } for (int i = 0; i < ints.length; i++) { Assert.areEqual(0, ints[i]); } }
public void specific(ObjectContainer con, int step) { super.specific(con, step); TEntry entry = new TEntry().lastElement(); Stack stack = new Stack(); if (step > 0) { stack.addElement(entry.key); ObjectSet set = con.queryByExample(stack); if (set.size() != step) { Regression.addError("Stack member query not found"); } else { Stack res = (Stack) set.next(); if (!(stack.pop().equals(new TEntry().lastElement().key))) { Regression.addError("Stack order changed."); } } } }
public void test() { Query q = Test.query(); q.constrain(TuningMemberFieldQuery.class); q.descend("member").descend("name").constrain("1"); long start = System.currentTimeMillis(); ObjectSet objectSet = q.execute(); long stop = System.currentTimeMillis(); Test.ensure(objectSet.size() == 1); TuningMemberFieldQuery tmf = (TuningMemberFieldQuery) objectSet.next(); Test.ensure(tmf.member.name.equals("1")); long duration = stop - start; System.out.println("Querying " + COUNT + " objects for member identity: " + duration + "ms"); }
private void expect(Query query, Object[] results, boolean ordered) { testCases++; ObjectSet set = query.execute(); if (results == null || results.length == 0) { if (set.size() > 0) { error("No content expected."); } return; } int j = 0; if (set.size() == results.length) { while (set.hasNext()) { Object obj = set.next(); boolean found = false; if (ordered) { if (comparer.isEqual(results[j], obj)) { results[j] = null; found = true; } j++; } else { for (int i = 0; i < results.length; i++) { if (results[i] != null) { if (comparer.isEqual(results[i], obj)) { results[i] = null; found = true; break; } } } } if (!found) { error("Object not expected: " + obj); } } for (int i = 0; i < results.length; i++) { if (results[i] != null) { error("Expected object not returned: " + results[i]); } } } else { error("Unexpected size returned.\nExpected: " + results.length + " Returned: " + set.size()); } }
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 test() { Test.store(new Parent1(new Child1())); ObjectContainer container = Test.reOpen(); container .ext() .configure() .addAlias(new TypeAlias("com.db4o.test.aliases.Parent1", "com.db4o.test.aliases.Parent2")); container .ext() .configure() .addAlias(new TypeAlias("com.db4o.test.aliases.Child1", "com.db4o.test.aliases.Child2")); ObjectSet os = container.query(Parent2.class); Test.ensure(os.size() > 0); Parent2 p2 = (Parent2) os.next(); Test.ensure(p2.child != null); }
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); }
private void assertSingleElementQueryResult(Query query, Object element) { ObjectSet objectSet = query.execute(); Assert.areEqual(1, objectSet.size()); Item item = (Item) objectSet.next(); Assert.areEqual(element, item.list.get(0)); }