Search in sources :

Example 16 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase in project GeoGig by boundlessgeo.

the class DiffTree method _call.

/**
     * Finds differences between the two specified trees.
     * 
     * @return an iterator to a set of differences between the two trees
     * @see DiffEntry
     */
@Override
protected Iterator<DiffEntry> _call() throws IllegalArgumentException {
    checkNotNull(oldRefSpec, "old version not specified");
    checkNotNull(newRefSpec, "new version not specified");
    final RevTree oldTree = resolveTree(oldRefSpec);
    final RevTree newTree = resolveTree(newRefSpec);
    if (oldTree.equals(newTree)) {
        return Iterators.emptyIterator();
    }
    ObjectDatabase leftSource = resolveSource(oldTree.getId());
    ObjectDatabase rightSource = resolveSource(newTree.getId());
    final PreOrderDiffWalk visitor = new PreOrderDiffWalk(oldTree, newTree, leftSource, rightSource);
    final BlockingQueue<DiffEntry> queue = new ArrayBlockingQueue<>(100);
    final DiffEntryProducer diffProducer = new DiffEntryProducer(queue);
    diffProducer.setReportTrees(this.reportTrees);
    diffProducer.setRecursive(this.recursive);
    final List<RuntimeException> producerErrors = new LinkedList<>();
    Thread producerThread = new Thread("DiffTree producer thread") {

        @Override
        public void run() {
            Consumer consumer = diffProducer;
            if (customFilter != null) {
                // evaluated the latest
                consumer = new PreOrderDiffWalk.FilteringConsumer(consumer, customFilter);
            }
            if (changeTypeFilter != null) {
                consumer = new ChangeTypeFilteringDiffConsumer(changeTypeFilter, consumer);
            }
            if (boundsFilter != null) {
                consumer = new BoundsFilteringDiffConsumer(boundsFilter, consumer, stagingDatabase());
            }
            if (!pathFilters.isEmpty()) {
                // evaluated the former
                consumer = new PathFilteringDiffConsumer(pathFilters, consumer);
            }
            try {
                visitor.walk(consumer);
            } catch (RuntimeException e) {
                LOGGER.error("Error traversing diffs", e);
                producerErrors.add(e);
            } finally {
                diffProducer.finished = true;
            }
        }
    };
    producerThread.setDaemon(true);
    producerThread.start();
    Iterator<DiffEntry> consumerIterator = new AbstractIterator<DiffEntry>() {

        @Override
        protected DiffEntry computeNext() {
            if (!producerErrors.isEmpty()) {
                throw new RuntimeException("Error in producer thread", producerErrors.get(0));
            }
            BlockingQueue<DiffEntry> entries = queue;
            boolean finished = diffProducer.isFinished();
            boolean empty = entries.isEmpty();
            while (!finished || !empty) {
                try {
                    DiffEntry entry = entries.poll(10, TimeUnit.MILLISECONDS);
                    if (entry != null) {
                        return entry;
                    }
                    finished = diffProducer.isFinished();
                    empty = entries.isEmpty();
                } catch (InterruptedException e) {
                    throw Throwables.propagate(e);
                }
            }
            return endOfData();
        }

        @Override
        protected void finalize() {
            diffProducer.finished = true;
        }
    };
    return consumerIterator;
}
Also used : PreOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk) LinkedList(java.util.LinkedList) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Consumer(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk.Consumer) ForwardingConsumer(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk.ForwardingConsumer) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer) BoundsFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.BoundsFilteringDiffConsumer) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) BoundsFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.BoundsFilteringDiffConsumer) AbstractIterator(com.google.common.collect.AbstractIterator) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry)

Example 17 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase in project GeoGig by boundlessgeo.

the class FindTreeChild method _call.

/**
     * Executes the command.
     * 
     * @return an {@code Optional} that contains the Node if it was found, or
     *         {@link Optional#absent()} if it wasn't
     */
@Override
protected Optional<NodeRef> _call() {
    checkNotNull(childPath, "childPath");
    final RevTree tree;
    if (parent == null) {
        ObjectId rootTreeId = command(ResolveTreeish.class).setTreeish(Ref.HEAD).call().get();
        if (rootTreeId.isNull()) {
            return Optional.absent();
        }
        tree = command(RevObjectParse.class).setObjectId(rootTreeId).call(RevTree.class).get();
    } else {
        tree = parent.get();
    }
    final String path = childPath;
    final String parentPath = this.parentPath == null ? "" : this.parentPath;
    final ObjectDatabase target = indexDb ? stagingDatabase() : objectDatabase();
    DepthSearch depthSearch = new DepthSearch(target);
    Optional<NodeRef> childRef = depthSearch.find(tree, parentPath, path);
    return childRef;
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) DepthSearch(org.locationtech.geogig.repository.DepthSearch) ObjectId(org.locationtech.geogig.api.ObjectId) ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) RevTree(org.locationtech.geogig.api.RevTree)

Example 18 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase in project GeoGig by boundlessgeo.

the class DeepMove method _call.

/**
     * Executes a deep move using the supplied {@link Node}.
     * 
     * @return the {@link ObjectId} of the moved object, or {@code null} if {@link #setObjects} was
     *         used and hence no such information it available
     */
@Override
protected ObjectId _call() {
    ObjectDatabase from = toIndex ? objectDatabase() : stagingDatabase();
    ObjectDatabase to = toIndex ? stagingDatabase() : objectDatabase();
    Set<ObjectId> metadataIds = new HashSet<ObjectId>();
    final ObjectId ret;
    if (objectRef != null) {
        Node ref = objectRef.get();
        ret = ref.getObjectId();
        deepMove(ref, from, to, metadataIds);
    } else if (objectId != null) {
        ObjectId id = objectId.get();
        moveObject(id, from, to);
        ret = id;
    } else if (nodesToMove != null) {
        moveObjects(from, to, nodesToMove, metadataIds);
        ret = null;
    } else {
        throw new IllegalStateException("No object supplied to be moved");
    }
    for (ObjectId metadataId : metadataIds) {
        moveObject(metadataId, from, to);
    }
    return ret;
}
Also used : ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) HashSet(java.util.HashSet)

Example 19 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase in project GeoGig by boundlessgeo.

the class DiffBounds method _call.

@Override
protected DiffSummary<BoundingBox, BoundingBox> _call() {
    checkArgument(cached && oldVersion == null || !cached, String.format("compare index allows only one revision to check against, got %s / %s", oldVersion, newVersion));
    checkArgument(newVersion == null || oldVersion != null, "If new rev spec is specified then old rev spec is mandatory");
    final String leftRefSpec = fromNullable(oldVersion).or(Ref.HEAD);
    final String rightRefSpec = fromNullable(newVersion).or(cached ? Ref.STAGE_HEAD : Ref.WORK_HEAD);
    RevTree left = resolveTree(leftRefSpec);
    RevTree right = resolveTree(rightRefSpec);
    ObjectDatabase leftSource = resolveSafeDb(leftRefSpec);
    ObjectDatabase rightSource = resolveSafeDb(rightRefSpec);
    PreOrderDiffWalk visitor = new PreOrderDiffWalk(left, right, leftSource, rightSource);
    CoordinateReferenceSystem crs = resolveCrs();
    BoundsWalk walk = new BoundsWalk(crs, stagingDatabase());
    PreOrderDiffWalk.Consumer consumer = walk;
    if (!pathFilters.isEmpty()) {
        consumer = new PathFilteringDiffConsumer(pathFilters, walk);
    }
    visitor.walk(consumer);
    DiffSummary<BoundingBox, BoundingBox> diffBounds = walk.getResult();
    return diffBounds;
}
Also used : ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) BoundingBox(org.opengis.geometry.BoundingBox) PreOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PreOrderDiffWalk) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) RevTree(org.locationtech.geogig.api.RevTree) PathFilteringDiffConsumer(org.locationtech.geogig.api.plumbing.diff.PathFilteringDiffConsumer)

Example 20 with ObjectDatabase

use of org.locationtech.geogig.storage.ObjectDatabase in project GeoGig by boundlessgeo.

the class DiffTreeTest method testTreePathFiltering.

@Test
public void testTreePathFiltering() {
    ObjectDatabase db = geogit.getContext().objectDatabase();
    RevTree tree1 = tree(100, db);
    RevTree tree2 = tree(50, db);
    RevTree root = createRoot(db, tree1, tree2);
    List<String> pathFilters = ImmutableList.of("tree1");
    diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId()).setPathFilter(pathFilters);
    List<DiffEntry> diffs = ImmutableList.copyOf(diffTree.call());
    assertEquals(tree1.size(), diffs.size());
    pathFilters = ImmutableList.of("tree2");
    diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId()).setPathFilter(pathFilters);
    diffs = ImmutableList.copyOf(diffTree.call());
    assertEquals(tree2.size(), diffs.size());
    pathFilters = ImmutableList.of("tree1/1", "tree1/2", "tree1/3", "tree1/4", "tree2/2", "tree2/3", "tree2/10");
    diffTree.setOldTree(ObjectId.NULL).setNewTree(root.getId()).setPathFilter(pathFilters);
    diffs = ImmutableList.copyOf(diffTree.call());
    assertEquals(pathFilters.size(), diffs.size());
}
Also used : ObjectDatabase(org.locationtech.geogig.storage.ObjectDatabase) RevTree(org.locationtech.geogig.api.RevTree) DiffEntry(org.locationtech.geogig.api.plumbing.diff.DiffEntry) Test(org.junit.Test)

Aggregations

ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)27 RevTree (org.locationtech.geogig.api.RevTree)18 ObjectId (org.locationtech.geogig.api.ObjectId)13 RevObject (org.locationtech.geogig.api.RevObject)8 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)8 Test (org.junit.Test)7 NodeRef (org.locationtech.geogig.api.NodeRef)7 RevCommit (org.locationtech.geogig.api.RevCommit)5 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)5 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)4 HashSet (java.util.HashSet)3 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)3 Node (org.locationtech.geogig.api.Node)3 IOException (java.io.IOException)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 CommitBuilder (org.locationtech.geogig.api.CommitBuilder)2 ProgressListener (org.locationtech.geogig.api.ProgressListener)2 Ref (org.locationtech.geogig.api.Ref)2 TYPE (org.locationtech.geogig.api.RevObject.TYPE)2