Search in sources :

Example 26 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class DepthSearchTest method addTree.

private RevTreeBuilder addTree(RevTreeBuilder root, final String treePath, String... singleNodeNames) {
    Context mockInjector = mock(Context.class);
    when(mockInjector.objectDatabase()).thenReturn(odb);
    CreateTree op = new CreateTree().setIndex(false);
    op.setContext(mockInjector);
    RevTreeBuilder subTreeBuilder = op.call();
    if (singleNodeNames != null) {
        for (String singleNodeName : singleNodeNames) {
            String nodePath = NodeRef.appendChild(treePath, singleNodeName);
            ObjectId fakeFeatureOId = ObjectId.forString(nodePath);
            // forString(treePath);
            ObjectId fakeTypeOId = ObjectId.NULL;
            subTreeBuilder.put(Node.create(singleNodeName, fakeFeatureOId, fakeTypeOId, TYPE.FEATURE, null));
        }
    }
    RevTree subtree = subTreeBuilder.build();
    WriteBack writeBack = fakeGeogig.command(WriteBack.class).setAncestor(root).setChildPath(treePath).setTree(subtree).setMetadataId(fakeTreeMetadataId);
    ObjectId newRootId = writeBack.call();
    return fakeGeogig.command(RevObjectParse.class).setObjectId(newRootId).call(RevTree.class).get().builder(odb);
}
Also used : Context(org.locationtech.geogig.api.Context) WriteBack(org.locationtech.geogig.api.plumbing.WriteBack) CreateTree(org.locationtech.geogig.api.plumbing.CreateTree) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree)

Example 27 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class RevTreeBuilderTest method createAndSaveTree.

private ObjectId createAndSaveTree(final int numEntries, final boolean insertInAscendingKeyOrder) throws Exception {
    RevTreeBuilder treeBuilder = createTree(numEntries, insertInAscendingKeyOrder);
    RevTree tree = treeBuilder.build();
    odb.put(tree);
    return tree.getId();
}
Also used : RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree)

Example 28 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class RevTreeBuilderTest method testRemoveSplittedTree.

@Test
public void testRemoveSplittedTree() throws Exception {
    final int numEntries = (int) (1.5 * RevTree.NORMALIZED_SIZE_LIMIT);
    final ObjectId treeId = createAndSaveTree(numEntries, true);
    final RevTree tree = odb.getTree(treeId);
    // collect some keys to remove
    final Set<String> removedKeys = new HashSet<String>();
    {
        int i = 0;
        DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.CHILDREN);
        for (; it.hasNext(); i++) {
            NodeRef entry = it.next();
            if (i % 10 == 0) {
                removedKeys.add(entry.path());
            }
        }
        assertTrue(removedKeys.size() > 0);
    }
    RevTreeBuilder builder = tree.builder(odb);
    for (String key : removedKeys) {
        assertTrue(key, builder.get(key).isPresent());
        builder.remove(key);
        assertFalse(key, builder.get(key).isPresent());
    }
    for (String key : removedKeys) {
        assertFalse(builder.get(key).isPresent());
    }
    final RevTree tree2 = builder.build();
    for (String key : removedKeys) {
        assertFalse(key, repo.getTreeChild(tree2, key).isPresent());
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 29 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class RevTreeBuilderTest method testRemove.

@Test
public void testRemove() throws Exception {
    final int numEntries = 1000;
    ObjectId treeId = createAndSaveTree(numEntries, true);
    final RevTree tree = odb.getTree(treeId);
    // collect some keys to remove
    final Set<String> removedKeys = new HashSet<String>();
    {
        int i = 0;
        DepthTreeIterator it = new DepthTreeIterator("", ObjectId.NULL, tree, odb, Strategy.CHILDREN);
        for (; it.hasNext(); i++) {
            NodeRef entry = it.next();
            if (i % 10 == 0) {
                removedKeys.add(entry.path());
            }
        }
        assertEquals(100, removedKeys.size());
    }
    final RevTreeBuilder builder = tree.builder(odb);
    for (String key : removedKeys) {
        assertTrue(builder.get(key).isPresent());
        builder.remove(key);
        assertFalse(builder.get(key).isPresent());
    }
    final RevTree tree2 = builder.build();
    for (String key : removedKeys) {
        assertFalse(repo.getTreeChild(tree2, key).isPresent());
    }
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) DepthTreeIterator(org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 30 with RevTreeBuilder

use of org.locationtech.geogig.api.RevTreeBuilder in project GeoGig by boundlessgeo.

the class WriteBack method _call.

/**
     * Executes the write back operation.
     * 
     * @return the {@link ObjectId id} of the resulting new ancestor tree.
     */
@Override
protected ObjectId _call() {
    checkNotNull(tree, "child tree not set");
    checkNotNull(childPath, "child tree path not set");
    String ancestorPath = resolveAncestorPath();
    checkArgument(NodeRef.isChild(ancestorPath, childPath), String.format("child path '%s' is not a child of ancestor path '%s'", childPath, ancestorPath));
    RevTree tree = this.tree.get();
    checkState(null != tree, "child tree supplier returned null");
    ObjectDatabase targetDb = indexDb ? stagingDatabase() : objectDatabase();
    RevTreeBuilder root = resolveAncestor();
    return writeBack(root, ancestorPath, tree, childPath, targetDb, metadataId.or(ObjectId.NULL));
}
Also used : ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) RevTree(org.locationtech.geogig.api.RevTree)

Aggregations

RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)58 RevTree (org.locationtech.geogig.api.RevTree)47 ObjectId (org.locationtech.geogig.api.ObjectId)27 Test (org.junit.Test)25 NodeRef (org.locationtech.geogig.api.NodeRef)24 Node (org.locationtech.geogig.api.Node)14 DepthSearch (org.locationtech.geogig.repository.DepthSearch)6 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)5 Stopwatch (com.google.common.base.Stopwatch)4 Envelope (com.vividsolutions.jts.geom.Envelope)4 Map (java.util.Map)4 Context (org.locationtech.geogig.api.Context)4 FindTreeChild (org.locationtech.geogig.api.plumbing.FindTreeChild)4 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)4 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)4 Before (org.junit.Before)3 FindOrCreateSubtree (org.locationtech.geogig.api.plumbing.FindOrCreateSubtree)3 WriteBack (org.locationtech.geogig.api.plumbing.WriteBack)3 DepthTreeIterator (org.locationtech.geogig.api.plumbing.diff.DepthTreeIterator)3 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)3