예제 #1
0
  public void testMultipleStaging() throws Exception {

    final StagingDatabase indexDb = index.getDatabase();

    // insert and commit feature1_1
    final ObjectId oId1_1 = insertAndAdd(points1);

    System.err.println("++++++++++++ stage 1:  ++++++++++++++++++++");
    // staged1.accept(new PrintVisitor(index.getDatabase(), new PrintWriter(System.err)));

    // check feature1_1 is there
    assertEquals(oId1_1, indexDb.findStaged(pointsNs, pointsName, idP1).getNewObjectId());

    // insert and commit feature1_2, feature1_2 and feature2_1
    final ObjectId oId1_2 = insertAndAdd(points2);
    final ObjectId oId1_3 = insertAndAdd(points3);
    final ObjectId oId2_1 = insertAndAdd(lines1);

    System.err.println("++++++++++++ stage 2: ++++++++++++++++++++");
    // staged2.accept(new PrintVisitor(index.getDatabase(), new PrintWriter(System.err)));

    // check feature1_2, feature1_3 and feature2_1
    Ref treeChild;
    assertNotNull(treeChild = indexDb.findStaged(pointsNs, pointsName, idP2).getNewObject());
    assertEquals(oId1_2, treeChild.getObjectId());

    assertNotNull(treeChild = indexDb.findStaged(pointsNs, pointsName, idP3).getNewObject());
    assertEquals(oId1_3, treeChild.getObjectId());

    assertNotNull(treeChild = indexDb.findStaged(linesNs, linesName, idL1).getNewObject());
    assertEquals(oId2_1, treeChild.getObjectId());

    // as well as feature1_1 from the previous commit
    assertNotNull(treeChild = indexDb.findStaged(pointsNs, pointsName, idP1).getNewObject());
    assertEquals(oId1_1, treeChild.getObjectId());

    // delete feature1_1, feature1_3, and feature2_1
    assertTrue(deleteAndAdd(points1));
    assertTrue(deleteAndAdd(points3));
    assertTrue(deleteAndAdd(lines1));
    // and insert feature2_2
    final ObjectId oId2_2 = insertAndAdd(lines2);

    System.err.println("++++++++++++ stage 3: ++++++++++++++++++++");
    // staged3.accept(new PrintVisitor(index.getDatabase(), new PrintWriter(System.err)));

    // and check only points2 and lines2 remain
    assertEquals(oId1_1, indexDb.findStaged(pointsNs, pointsName, idP1).getOldObjectId());
    assertEquals(oId1_3, indexDb.findStaged(pointsNs, pointsName, idP3).getOldObjectId());
    assertEquals(oId2_1, indexDb.findStaged(linesNs, linesName, idL1).getOldObjectId());

    assertEquals(oId1_2, indexDb.findStaged(pointsNs, pointsName, idP2).getNewObjectId());
    assertEquals(oId2_2, indexDb.findStaged(linesNs, linesName, idL2).getNewObjectId());
  }
 @Override
 public Feature apply(final Ref featureRef) {
   String featureId = featureRef.getName();
   ObjectId contentId = featureRef.getObjectId();
   StagingDatabase database = repo.getIndex().getDatabase();
   Feature feature;
   try {
     ObjectReader<Feature> featureReader =
         serialisingFactory.createFeatureReader(type, featureId);
     feature = database.get(contentId, featureReader);
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
   return VersionedFeatureWrapper.wrap(feature, featureRef.getObjectId().toString());
 }