Search in sources :

Example 91 with Node

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);
        }
    }
}
Also used : Bucket(org.locationtech.geogig.api.Bucket) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope) Map(java.util.Map) SortedMap(java.util.SortedMap) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) TreeMap(java.util.TreeMap)

Example 92 with Node

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);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Integer.toBinaryString(java.lang.Integer.toBinaryString)

Example 93 with Node

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();
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) FindOrCreateSubtree(org.locationtech.geogig.api.plumbing.FindOrCreateSubtree) Node(org.locationtech.geogig.api.Node) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder)

Example 94 with Node

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());
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Test(org.junit.Test)

Example 95 with Node

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;
}
Also used : Node(org.locationtech.geogig.api.Node) Stopwatch(com.google.common.base.Stopwatch)

Aggregations

Node (org.locationtech.geogig.api.Node)117 RevTree (org.locationtech.geogig.api.RevTree)56 Test (org.junit.Test)50 ObjectId (org.locationtech.geogig.api.ObjectId)44 NodeRef (org.locationtech.geogig.api.NodeRef)24 Bucket (org.locationtech.geogig.api.Bucket)20 TreeTestSupport.featureNode (org.locationtech.geogig.api.plumbing.diff.TreeTestSupport.featureNode)18 Envelope (com.vividsolutions.jts.geom.Envelope)16 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)14 RevCommit (org.locationtech.geogig.api.RevCommit)10 Map (java.util.Map)9 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)9 Patch (org.locationtech.geogig.api.plumbing.diff.Patch)9 File (java.io.File)7 RevFeature (org.locationtech.geogig.api.RevFeature)7 WorkingTree (org.locationtech.geogig.repository.WorkingTree)7 Feature (org.opengis.feature.Feature)7 SimpleFeature (org.opengis.feature.simple.SimpleFeature)7 Stopwatch (com.google.common.base.Stopwatch)6 SortedMap (java.util.SortedMap)5