コード例 #1
0
  @Test
  public void testConsistencyOnDelete() {
    OGraphDatabase db = new OGraphDatabase(url);
    db.open("admin", "admin");

    if (db.getVertexType("Foo") == null) db.createVertexType("Foo");

    try {
      // Step 1
      // Create several foo's
      db.createVertex("Foo").field("address", "test1").save();
      db.createVertex("Foo").field("address", "test2").save();
      db.createVertex("Foo").field("address", "test3").save();

      // just show what is there
      List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo"));

      for (ODocument d : result) {
        System.out.println("Vertex: " + d);
      }

      // remove those foos in a transaction
      // Step 2
      db.begin(TXTYPE.OPTIMISTIC);

      // Step 3a
      result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test1'"));
      Assert.assertEquals(1, result.size());
      // Step 4a
      db.removeVertex(result.get(0));

      // Step 3b
      result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test2'"));
      Assert.assertEquals(1, result.size());
      // Step 4b
      db.removeVertex(result.get(0));

      // Step 3c
      result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test3'"));
      Assert.assertEquals(1, result.size());
      // Step 4c
      db.removeVertex(result.get(0));

      // Step 6
      db.commit();

      // just show what is there
      result = db.query(new OSQLSynchQuery<ODocument>("select * from Foo"));

      for (ODocument d : result) {
        System.out.println("Vertex: " + d);
      }

    } finally {
      db.close();
    }
  }
コード例 #2
0
  @Test
  public void deletesWithinTransactionArentWorking() throws IOException {
    OGraphDatabase db = new OGraphDatabase(url);
    db.open("admin", "admin");

    try {
      if (db.getVertexType("Foo") == null) db.createVertexType("Foo");
      if (db.getVertexType("Bar") == null) db.createVertexType("Bar");
      if (db.getVertexType("Sees") == null) db.createEdgeType("Sees");

      // Commenting out the transaction will result in the test succeeding.
      db.begin(TXTYPE.OPTIMISTIC);
      ODocument foo = (ODocument) db.createVertex("Foo").field("prop", "test1").save();

      // Comment out these two lines and the test will succeed. The issue appears to be related to
      // an edge
      // connecting a deleted vertex during a transaction
      ODocument bar = (ODocument) db.createVertex("Bar").field("prop", "test1").save();
      ODocument sees = db.createEdge(foo, bar, "Sees");
      db.commit();

      List<ODocument> foos = db.query(new OSQLSynchQuery("select * from Foo"));
      Assert.assertEquals(foos.size(), 1);

      db.begin(TXTYPE.OPTIMISTIC);
      db.removeVertex(foos.get(0));
      db.commit();

    } finally {
      db.close();
    }
  }