Exemplo n.º 1
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();
    }
  }
  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();
        }
      }
    }
  }