コード例 #1
0
 public void conc2(ExtObjectContainer oc) {
   oc.store(new CreateIndexFor("d"));
   tQueryB(oc);
   tUpdateB(oc);
   oc.store(new CreateIndexFor("z"));
   oc.store(new CreateIndexFor("y"));
 }
コード例 #2
0
 void checkHelper(Db4oHashMapHelper helper) {
   ExtObjectContainer con = db();
   if (con.isActive(helper)) {
     Assert.areEqual("hi", helper.i_childList.get(0));
     checkHelper(helper.i_child);
   }
 }
コード例 #3
0
  /*
   * 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();
    }
  }
コード例 #4
0
 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());
 }
コード例 #5
0
 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);
 }
コード例 #6
0
  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();
    }
  }
コード例 #7
0
  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());
  }
コード例 #8
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);
 }
コード例 #9
0
 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);
 }
コード例 #10
0
 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);
   }
 }
コード例 #11
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);
 }
コード例 #12
0
 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);
 }
コード例 #13
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);

  }
コード例 #14
0
 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);
   }
 }
コード例 #15
0
 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());
 }
コード例 #16
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);
  }
コード例 #17
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());
    }
  }
コード例 #18
0
  /**
   * This is to ensure that reflector.forObject(GenericArray) returns an instance of
   * GenericArrayClass instead of GenericClass http://tracker.db4o.com/jira/browse/COR-376
   */
  public void testGenericArrayClass() {
    ExtObjectContainer oc = fixture().db();
    initGenericObjects();
    ReflectClass elementType = oc.reflector().forName(PERSON_CLASSNAME);

    Object array = reflector().array().newInstance(elementType, 5);

    ReflectClass arrayClass = oc.reflector().forObject(array);
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    arrayClass = oc.reflector().forName(array.getClass().getName());
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    arrayClass = oc.reflector().forClass(array.getClass());
    Assert.isTrue(arrayClass.isArray());
    Assert.isTrue(arrayClass instanceof GenericArrayClass);

    Assert.areEqual(arrayClass.getName(), ReflectPlatform.fullyQualifiedName(array.getClass()));

    Assert.areEqual("(GA) " + elementType.getName(), array.toString());
  }
コード例 #19
0
  public void test() throws Exception {
    int total = 10;
    ExtObjectContainer[] containers = new ExtObjectContainer[total];
    ExtObjectContainer container = null;
    try {
      for (int i = 0; i < total; i++) {
        containers[i] = openNewSession();
        Assert.areEqual(ELEMENT_COUNT, countOccurences(containers[i], SimpleObject.class));
      }

      for (int i = 0; i < total; i++) {
        deleteAll(containers[i], SimpleObject.class);
      }

      container = openNewSession();

      assertOccurrences(container, SimpleObject.class, ELEMENT_COUNT);
      // ocs[0] deletes all SimpleObject
      containers[0].commit();
      containers[0].close();
      // FIXME: the following assertion fails
      assertOccurrences(container, SimpleObject.class, 0);
      for (int i = 1; i < total; i++) {
        containers[i].close();
      }
      assertOccurrences(container, SimpleObject.class, 0);
    } finally {
      if (container != null) {
        container.close();
      }
      for (int i = 0; i < total; i++) {
        if (containers[i] != null) {
          containers[i].close();
        }
      }
    }
  }
コード例 #20
0
 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);
   }
 }
コード例 #21
0
 public void conc2(ExtObjectContainer oc) throws Exception {
   ObjectSet os = oc.query(Item.class);
   Thread.sleep(500);
   deleteObjectSet(oc, os);
   assertOccurrences(oc, Atom.class, 0);
 }
コード例 #22
0
 public void concQueryCaseInsenstive(ExtObjectContainer oc) {
   Query q = oc.query();
   q.constrain(CaseInsensitiveTestCase.class);
   q.constrain(new CaseInsensitiveEvaluation("helloworld"));
   Assert.areEqual(1, q.execute().size());
 }
コード例 #23
0
 private ReflectClass getReflectClass(ExtObjectContainer oc, String className) {
   return oc.reflector().forName(className);
 }
コード例 #24
0
  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);
  }
コード例 #25
0
  /*
   * 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();
    }
  }
コード例 #26
0
 public void conc1(ExtObjectContainer oc) throws Exception {
   ObjectSet os = oc.query(Item.class);
   Thread.sleep(500);
   deleteObjectSet(oc, os);
   oc.rollback();
 }
コード例 #27
0
 private ObjectSet query(ExtObjectContainer oc, String n) {
   Query q = oc.query();
   q.constrain(CreateIndexFor.class);
   q.descend("i_name").constrain(n);
   return q.execute();
 }