public void conc2(ExtObjectContainer oc) {
   oc.store(new CreateIndexFor("d"));
   tQueryB(oc);
   tUpdateB(oc);
   oc.store(new CreateIndexFor("z"));
   oc.store(new CreateIndexFor("y"));
 }
  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();
    }
  }
 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);
   }
 }
 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 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 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 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();
        }
      }
    }
  }
 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 conc1(ExtObjectContainer oc) throws Exception {
   ObjectSet os = oc.query(Item.class);
   Thread.sleep(500);
   deleteObjectSet(oc, os);
   oc.rollback();
 }
 public void conc2(ExtObjectContainer oc) throws Exception {
   ObjectSet os = oc.query(Item.class);
   Thread.sleep(500);
   deleteObjectSet(oc, os);
   assertOccurrences(oc, Atom.class, 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);
  }
 private ObjectSet query(ExtObjectContainer oc, String n) {
   Query q = oc.query();
   q.constrain(CreateIndexFor.class);
   q.descend("i_name").constrain(n);
   return q.execute();
 }