use of org.locationtech.geogig.api.Node in project GeoGig by boundlessgeo.
the class FormatCommonV2 method writeTree.
public static void writeTree(RevTree tree, DataOutput data) throws IOException {
writeUnsignedVarLong(tree.size(), data);
writeUnsignedVarInt(tree.numTrees(), data);
Envelope envBuff = new Envelope();
final int nFeatures = tree.features().isPresent() ? tree.features().get().size() : 0;
writeUnsignedVarInt(nFeatures, data);
if (nFeatures > 0) {
for (Node feature : tree.features().get()) {
writeNode(feature, data, envBuff);
}
}
final int nTrees = tree.trees().isPresent() ? tree.trees().get().size() : 0;
writeUnsignedVarInt(nTrees, data);
if (nTrees > 0) {
for (Node subTree : tree.trees().get()) {
writeNode(subTree, data, envBuff);
}
}
final int nBuckets = tree.buckets().isPresent() ? tree.buckets().get().size() : 0;
writeUnsignedVarInt(nBuckets, data);
if (tree.buckets().isPresent()) {
ImmutableSortedMap<Integer, Bucket> buckets = tree.buckets().get();
for (Map.Entry<Integer, Bucket> bucket : buckets.entrySet()) {
writeBucket(bucket.getKey(), bucket.getValue(), data, envBuff);
}
}
}
use of org.locationtech.geogig.api.Node in project GeoGig by boundlessgeo.
the class FormatCommonV2 method readNodeRef.
public static NodeRef readNodeRef(DataInput in) throws IOException {
Node node = readNode(in);
final ObjectId metadataId = readObjectId(in);
String parentPath = in.readUTF();
return new NodeRef(node, parentPath, metadataId);
}
use of org.locationtech.geogig.api.Node in project GeoGig by boundlessgeo.
the class WorkingTree method delete.
/**
* Deletes a single feature from the working tree and updates the WORK_HEAD ref.
*
* @param path the path of the feature
* @param featureId the id of the feature
* @return true if the object was found and deleted, false otherwise
*/
public boolean delete(final String path, final String featureId) {
Optional<NodeRef> typeTreeRef = context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(path).call();
ObjectId metadataId = null;
if (typeTreeRef.isPresent()) {
metadataId = typeTreeRef.get().getMetadataId();
}
RevTreeBuilder parentTree = context.command(FindOrCreateSubtree.class).setIndex(true).setParent(Suppliers.ofInstance(Optional.of(getTree()))).setChildPath(path).call().builder(indexDatabase);
String featurePath = NodeRef.appendChild(path, featureId);
Optional<Node> node = findUnstaged(featurePath);
if (node.isPresent()) {
parentTree.remove(node.get().getName());
}
ObjectId newTree = context.command(WriteBack.class).setAncestor(getTreeSupplier()).setChildPath(path).setToIndex(true).setMetadataId(metadataId).setTree(parentTree.build()).call();
updateWorkHead(newTree);
return node.isPresent();
}
use of org.locationtech.geogig.api.Node in project GeoGig by boundlessgeo.
the class IndexTest method testMultipleStaging.
@Test
public void testMultipleStaging() throws Exception {
// 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, index.findStaged(appendChild(pointsName, idP1)).get().getObjectId());
// 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
Optional<Node> treeChild;
assertNotNull(treeChild = index.findStaged(appendChild(pointsName, idP2)));
assertTrue(treeChild.isPresent());
assertEquals(oId1_2, treeChild.get().getObjectId());
assertNotNull(treeChild = index.findStaged(appendChild(pointsName, idP3)));
assertTrue(treeChild.isPresent());
assertEquals(oId1_3, treeChild.get().getObjectId());
assertNotNull(treeChild = index.findStaged(appendChild(linesName, idL1)));
assertTrue(treeChild.isPresent());
assertEquals(oId2_1, treeChild.get().getObjectId());
// as well as feature1_1 from the previous commit
assertNotNull(treeChild = index.findStaged(appendChild(pointsName, idP1)));
assertTrue(treeChild.isPresent());
assertEquals(oId1_1, treeChild.get().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 (i.e. its oids are set to NULL)
assertFalse(index.findStaged(appendChild(pointsName, idP1)).isPresent());
assertFalse(index.findStaged(appendChild(pointsName, idP3)).isPresent());
assertFalse(index.findStaged(appendChild(linesName, idL1)).isPresent());
assertEquals(oId1_2, index.findStaged(appendChild(pointsName, idP2)).get().getObjectId());
assertEquals(oId2_2, index.findStaged(appendChild(linesName, idL2)).get().getObjectId());
}
use of org.locationtech.geogig.api.Node in project GeoGig by boundlessgeo.
the class RevTreeBuilderPerformanceTest method createTree.
private RevTreeBuilder createTree(final Iterable<Node> nodes, final RevTreeBuilder b, final boolean buildTree) {
if (buildTree) {
System.err.printf("Creating treee with %d nodes...", numNodes);
}
Stopwatch sw = Stopwatch.createStarted();
for (Node n : nodes) {
b.put(n);
}
sw.stop();
if (buildTree) {
System.err.printf("Created in %s\n", sw);
}
return b;
}
Aggregations