public void testQueryEvents() { EventRegistry registry = EventRegistryFactory.forObjectContainer(db()); EventRecorder recorder = new EventRecorder(fileSession().lock()); registry.queryStarted().addListener(recorder); registry.queryFinished().addListener(recorder); Assert.areEqual(0, recorder.size()); Query q = db().query(); q.execute(); Assert.areEqual(2, recorder.size()); EventRecord e1 = recorder.get(0); Assert.areSame(registry.queryStarted(), e1.e); Assert.areSame(q, ((QueryEventArgs) e1.args).query()); EventRecord e2 = recorder.get(1); Assert.areSame(registry.queryFinished(), e2.e); Assert.areSame(q, ((QueryEventArgs) e2.args).query()); recorder.clear(); registry.queryStarted().removeListener(recorder); registry.queryFinished().removeListener(recorder); db().query().execute(); Assert.areEqual(0, recorder.size()); }
public void conc(ExtObjectContainer oc) { oc.queryByExample((new QueryNonExistantTestCase(true))); assertOccurrences(oc, QueryNonExistantTestCase.class, 0); Query q = oc.query(); q.constrain(new QueryNonExistantTestCase(true)); Assert.areEqual(0, q.execute().size()); }
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 Item itemByName(String string) { Query q = db().query(); q.constrain(Item.class); q.descend("_name").constrain(string); Object object = q.execute().next(); return (Item) object; }
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 testLastOrderWins() { Query query = newQuery(Data.class); query.descend("_id").orderDescending(); query.descend("_id").orderAscending(); query.descend("_id").constrain(new Integer(0)).greater(); assertOrdered(query.execute()); }
@SuppressWarnings("unchecked") private ObjectSet executeSODAQuery(final A a, Evaluation e) { Query q = db().query(); q.constrain(e); ObjectSet set = q.execute(); return set; }
public void _test() throws Exception { Query query = newQuery(); query.constrain(new TestEvaluation()); query.constrain(Item.class); query.descend("name").orderDescending(); ObjectSet set = query.execute(); Assert.areEqual(3, set.size()); }
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()); }
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); }
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); } }
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); }
public void testUpdate() { ExtObjectContainer oc = fixture().db(); initGenericObjects(); // Db4oUtil.dump(oc); ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME); Assert.isNotNull(rc); Query q = oc.query(); q.constrain(rc); ObjectSet results = q.execute(); // Db4oUtil.dumpResults(oc, results); Assert.isTrue(results.size() == 1); }
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 testQuery() { ExtObjectContainer oc = fixture().db(); initGenericObjects(); ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME); Assert.isNotNull(rc); // now query to make sure there are none left Query q = oc.query(); q.constrain(rc); q.descend("surname").constrain("John"); ObjectSet results = q.execute(); Assert.isTrue(results.size() == 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 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()); }
public void testCreate() throws Exception { initGenericObjects(); // fixture().reopen(); ExtObjectContainer oc = fixture().db(); // now check to see if person was saved ReflectClass rc = getReflectClass(oc, PERSON_CLASSNAME); Assert.isNotNull(rc); Query q = oc.query(); q.constrain(rc); ObjectSet results = q.execute(); Assert.isTrue(results.size() == 1); // Db4oUtil.dumpResults(fixture().db(), results); }
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); } }
public void conc(ExtObjectContainer oc) { Query q = oc.query(); q.constrain(QueryForUnknownFieldTestCase.class); q.descend("_name").constrain("name"); Assert.areEqual(1, q.execute().size()); q = oc.query(); q.constrain(QueryForUnknownFieldTestCase.class); q.descend("name").constrain("name"); Assert.areEqual(0, q.execute().size()); }
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 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); } }
private void assertNoItemFoundByQuery() { Query q = db().query(); q.constrain(Item.class); Assert.areEqual(0, q.execute().size()); }
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)); }
private void assertSingleElementQuery(Object element) { Query q = db().query(); q.constrain(Item.class); q.descend("list").constrain(element); assertSingleElementQueryResult(q, element); }
public void concQueryCaseInsenstive(ExtObjectContainer oc) { Query q = oc.query(); q.constrain(CaseInsensitiveTestCase.class); q.constrain(new CaseInsensitiveEvaluation("helloworld")); Assert.areEqual(1, q.execute().size()); }
private Object retrieveInstance(ExtObjectContainer client) { Query query = client.query(); query.constrain(_class); query.descend("_isRoot").constrain(new Boolean(true)); return query.execute().next(); }
private ObjectSet query(ExtObjectContainer oc, String n) { Query q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_name").constrain(n); return q.execute(); }
private void asserItemCount(final int expectedCount) { Query query = db().query(); query.constrain(Item.class); int itemCount = query.execute().size(); Assert.areEqual(expectedCount, itemCount); }
private void tQueryInts(ExtObjectContainer oc, int expectedZeroSize) { Query q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(0)); int zeroSize = q.execute().size(); Assert.areEqual(expectedZeroSize, zeroSize); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(4)).greater().equal(); tExpectInts(q, new int[] {5, 7}); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(4)).greater(); tExpectInts(q, new int[] {5, 7}); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(3)).greater(); tExpectInts(q, new int[] {5, 7}); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(3)).greater().equal(); tExpectInts(q, new int[] {3, 3, 5, 7}); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(2)).greater().equal(); tExpectInts(q, new int[] {2, 3, 3, 5, 7}); q = oc.query(); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(2)).greater(); tExpectInts(q, new int[] {3, 3, 5, 7}); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(1)).greater().equal(); tExpectInts(q, new int[] {1, 2, 3, 3, 5, 7}); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(1)).greater(); tExpectInts(q, new int[] {2, 3, 3, 5, 7}); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(4)).smaller(); tExpectInts(q, new int[] {1, 2, 3, 3}, zeroSize); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(4)).smaller().equal(); tExpectInts(q, new int[] {1, 2, 3, 3}, zeroSize); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(3)).smaller(); tExpectInts(q, new int[] {1, 2}, zeroSize); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(3)).smaller().equal(); tExpectInts(q, new int[] {1, 2, 3, 3}, zeroSize); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(2)).smaller().equal(); tExpectInts(q, new int[] {1, 2}, zeroSize); q = oc.query(); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(2)).smaller(); tExpectInts(q, new int[] {1}, zeroSize); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(1)).smaller().equal(); tExpectInts(q, new int[] {1}, zeroSize); q = oc.query(); q.constrain(CreateIndexFor.class); q.descend("i_int").constrain(new Integer(1)).smaller(); tExpectInts(q, new int[] {}, zeroSize); }