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 test() {
   SubClass subClass = retrieveOnlyInstance(SubClass.class);
   db().delete(subClass);
   db().commit();
   ObjectSet objectSet = db().query(Member.class);
   Assert.areEqual(0, objectSet.size());
 }
示例#3
0
 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 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 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 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 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 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 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 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);
   }
 }
示例#12
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);
  }
 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 tQueryB(ExtObjectContainer oc) {
   ObjectSet res = query(oc, "b");
   Assert.areEqual(1, res.size());
   CreateIndexFor ci = (CreateIndexFor) res.next();
   Assert.areEqual("b", ci.i_name);
 }