// It will fail for C/S because the reference system in the
  // server is not in sync.
  @SuppressWarnings("unchecked")
  public void _testChangingSODA() throws Exception {
    populate();
    _b.a = new A();

    ObjectSet set = executeSODAQuery(_a, new Evaluator(_a));
    Assert.areEqual(0, set.size());

    set = executeSODAQuery(_b.a, new Evaluator(_b.a));
    Assert.areEqual(1, set.size());
  }
 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());
 }
示例#4
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);
   }
 }
 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);
   }
 }
 @SuppressWarnings("unchecked")
 public void testCircularEvaluation() throws Exception {
   populate();
   CircularEvaluator.D one = new CircularEvaluator.D(null, _a);
   CircularEvaluator.D two = new CircularEvaluator.D(one, _a);
   one._d = two;
   ObjectSet set = executeSODAQuery(_a, new CircularEvaluator(one));
   Assert.areEqual(1, set.size());
 }
 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 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 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 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);
   }
 }
示例#14
0
 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);
 }
示例#15
0
 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 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 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());
  }
示例#19
0
  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);
   }
 }
 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]);
   }
 }
 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);
 }
 @SuppressWarnings("unchecked")
 public void testDeepTwoEvaluation() throws Exception {
   populate();
   ObjectSet set = executeSODAQuery(_a, new DeepTwoEvaluator(new DeepTwoEvaluator.C(_a)));
   Assert.areEqual(1, set.size());
 }
  /** @deprecated using deprecated api */
  private void runElementTest(Data data, boolean onOriginal) throws Exception {

    Map otherMap = new HashMap();

    AtomData atom = null;

    tDefaultValues(data);

    int itCount = 0;
    Iterator i = data.i_map.keySet().iterator();
    while (i.hasNext()) {
      String str = (String) i.next();
      itCount++;
      atom = (AtomData) data.i_map.get(str);
      Assert.areEqual(str, atom.name);
      otherMap.put(str, atom);
    }
    Assert.areEqual(DEFAULT.length, itCount);

    Assert.areEqual(DEFAULT.length, data.i_map.size());
    Assert.isFalse(data.i_map.isEmpty());
    db().deactivate(data.i_map, Integer.MAX_VALUE);
    data.i_map.get("great");
    Assert.areEqual("great", ((AtomData) data.i_map.get("great")).name);
    db().deactivate(data.i_map, Integer.MAX_VALUE);

    if (onOriginal) {
      Query q = newQuery();
      Data template = new Data();
      template.i_map = db().collections().newHashMap(1);
      template.i_map.put("cool", new AtomData("cool"));
      q.constrain(template);
      ObjectSet qResult = q.execute();
      Assert.areEqual(1, qResult.size());
      Assert.areEqual(data, qResult.next());
    }

    Assert.isTrue(data.i_map.keySet().containsAll(otherMap.keySet()));

    Object[] arr = data.i_map.keySet().toArray();
    tDefaultArray(arr);

    String[] cmp = new String[DEFAULT.length];
    System.arraycopy(DEFAULT, 0, cmp, 0, DEFAULT.length);

    i = data.i_map.keySet().iterator();
    while (i.hasNext()) {
      String str = (String) i.next();
      boolean found = false;
      for (int j = 0; j < cmp.length; j++) {
        if (str.equals(cmp[j])) {
          cmp[j] = null;
          found = true;
        }
      }
      Assert.isTrue(found);
    }

    for (int j = 0; j < cmp.length; j++) {
      Assert.isNull(cmp[j]);
    }

    db().deactivate(data.i_map, Integer.MAX_VALUE);
    Assert.isFalse(data.i_map.isEmpty());
    db().deactivate(data.i_map, Integer.MAX_VALUE);
    data.i_map.put("yup", new AtomData("yup"));

    db().store(data.i_map);
    db().store(data.i_map);
    db().store(data.i_map);
    db().store(data.i_helper);
    db().store(data.i_helper);
    db().store(data.i_helper);
    db().commit();

    Assert.areEqual(4, data.i_map.size());

    atom = (AtomData) data.i_map.get("yup");
    Assert.areEqual("yup", atom.name);

    AtomData removed = (AtomData) data.i_map.remove("great");

    Assert.areEqual("great", removed.name);
    Assert.isNull(data.i_map.remove("great"));
    db().deactivate(data.i_map, Integer.MAX_VALUE);
    Assert.areEqual(3, data.i_map.size());

    Assert.isTrue(data.i_map.keySet().removeAll(otherMap.keySet()));
    db().deactivate(data.i_map, Integer.MAX_VALUE);
    Assert.isFalse(data.i_map.keySet().removeAll(otherMap.keySet()));
    Assert.areEqual(1, data.i_map.size());
    i = data.i_map.keySet().iterator();
    String str = (String) i.next();
    Assert.areEqual("yup", str);
    Assert.isFalse(i.hasNext());

    data.i_map.clear();
    Assert.isTrue(data.i_map.isEmpty());
    Assert.areEqual(0, data.i_map.size());

    setDefaultValues(data.i_map);

    String[] strArr = new String[1];
    strArr = (String[]) data.i_map.keySet().toArray(strArr);
    tDefaultArray(strArr);

    data.i_map.clear();
    data.i_map.put("zero", "zero");

    for (int j = 0; j < COUNT; j++) {
      data.i_map.put(MORE + j, new AtomData(MORE + j));
    }
    Assert.areEqual(COUNT + 1, data.i_map.size());
    lookupLast(data);

    db().deactivate(data.i_map, Integer.MAX_VALUE);
    lookupLast(data);
    lookupLast(data);

    reopen();
    restoreMembers(data);
    lookupLast(data);

    atom = new AtomData("double");

    data.i_map.put("double", atom);

    int previousSize = data.i_map.size();

    db().deactivate(data.i_map, Integer.MAX_VALUE);

    AtomData doubleAtom = (AtomData) data.i_map.put("double", new AtomData("double"));
    Assert.areSame(atom, doubleAtom);

    Assert.areEqual(previousSize, data.i_map.size());
    data.i_map.put("double", doubleAtom);

    db().commit();

    data.i_map.put("rollBack", "rollBack");
    data.i_map.put("double", new AtomData("nono"));

    db().rollback();
    Assert.isNull(data.i_map.get("rollBack"));
    Assert.areEqual(previousSize, data.i_map.size());
    atom = (AtomData) data.i_map.get("double");
    Assert.areSame(atom, doubleAtom);
    Assert.isTrue(data.i_map.containsKey("double"));
    Assert.isFalse(data.i_map.containsKey("rollBack"));

    otherMap.clear();
    otherMap.put("other1", doubleAtom);
    otherMap.put("other2", doubleAtom);

    data.i_map.putAll(otherMap);
    db().deactivate(data.i_map, Integer.MAX_VALUE);

    Assert.areSame(doubleAtom, data.i_map.get("other1"));
    Assert.areSame(doubleAtom, data.i_map.get("other2"));

    data.i_map.clear();
    Assert.areEqual(0, data.i_map.size());
    setDefaultValues(data.i_map);

    int j = 0;
    i = data.i_map.keySet().iterator();
    while (i.hasNext()) {
      String key = (String) i.next();
      if (key.equals("cool")) {
        i.remove();
      }
      j++;
    }
    Assert.areEqual(2, data.i_map.size());
    Assert.isFalse(data.i_map.containsKey("cool"));
    Assert.areEqual(3, j);

    data.i_map.put("double", doubleAtom);
    ((Db4oMap) data.i_map).deleteRemoved(true);
    data.i_map.keySet().remove("double");
    Assert.isFalse(db().isStored(doubleAtom));
    ((Db4oMap) data.i_map).deleteRemoved(false);

    data.i_map.clear();
    Assert.areEqual(0, data.i_map.size());
    setDefaultValues(data.i_map);
  }
 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));
 }