Package org.locationtech.geogig.storage

Examples of org.locationtech.geogig.storage.ObjectDatabase


                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()) {
View Full Code Here


            subtreeId = RevTree.EMPTY_TREE_ID;
        }
        if (RevTree.EMPTY_TREE_ID.equals(subtreeId)) {
            return RevTree.EMPTY;
        }
        ObjectDatabase target = indexDb ? stagingDatabase() : objectDatabase();
        RevTree tree = target.getTree(subtreeId);
        return tree;
    }
View Full Code Here

                "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));
    }
View Full Code Here

    @Override
    protected ObjectId _call() {
        final ProgressListener progress = getProgressListener();

        final RevTree oldRootTree = resolveRootTree();
        final ObjectDatabase repositoryDatabase = objectDatabase();

        Iterator<DiffEntry> diffs = null;
        long numChanges = 0;
        if (diffSupplier == null) {
            diffs = index().getStaged(pathFilters);
            numChanges = index().countStaged(pathFilters).count();
        } else {
            diffs = diffSupplier.get();
        }

        if (!diffs.hasNext()) {
            return oldRootTree.getId();
        }
        if (progress.isCanceled()) {
            return null;
        }

        Map<String, RevTreeBuilder> repositoryChangedTrees = Maps.newHashMap();
        Map<String, NodeRef> indexChangedTrees = Maps.newHashMap();
        Map<String, ObjectId> changedTreesMetadataId = Maps.newHashMap();
        Set<String> deletedTrees = Sets.newHashSet();
        final boolean moveObjects = this.moveObjects;
        NodeRef ref;
        int i = 0;
        RevTree stageHead = index().getTree();
        while (diffs.hasNext()) {
            if (numChanges != 0) {
                progress.setProgress((float) (++i * 100) / numChanges);
            }
            if (progress.isCanceled()) {
                return null;
            }

            DiffEntry diff = diffs.next();
            // ignore the root entry
            if (NodeRef.ROOT.equals(diff.newName()) || NodeRef.ROOT.equals(diff.oldName())) {
                continue;
            }
            ref = diff.getNewObject();

            if (ref == null) {
                ref = diff.getOldObject();
            }

            final String parentPath = ref.getParentPath();
            final boolean isDelete = ChangeType.REMOVED.equals(diff.changeType());
            final TYPE type = ref.getType();
            if (isDelete && deletedTrees.contains(parentPath)) {
                // this is to avoid re-creating the parentTree for a feature delete after its parent
                // tree delete entry was processed
                continue;
            }
            RevTreeBuilder parentTree = resolveTargetTree(oldRootTree, parentPath,
                    repositoryChangedTrees, changedTreesMetadataId, ObjectId.NULL,
                    repositoryDatabase);
            if (type == TYPE.TREE && !isDelete) {
                // cache the tree
                resolveTargetTree(oldRootTree, ref.name(), repositoryChangedTrees,
                        changedTreesMetadataId, ref.getMetadataId(), repositoryDatabase);
            }

            resolveSourceTreeRef(parentPath, indexChangedTrees, changedTreesMetadataId, stageHead);

            Preconditions.checkState(parentTree != null);

            if (isDelete) {
                String oldName = diff.getOldObject().getNode().getName();
                parentTree.remove(oldName);
                if (TYPE.TREE.equals(type)) {
                    deletedTrees.add(ref.path());
                }
            } else {
                if (moveObjects && ref.getType().equals(TYPE.TREE)) {
                    RevTree tree = stagingDatabase().getTree(ref.objectId());
                    if (!ref.getMetadataId().isNull()) {
                        repositoryDatabase.put(stagingDatabase()
                                .getFeatureType(ref.getMetadataId()));
                    }
                    if (tree.isEmpty()) {
                        repositoryDatabase.put(tree);
                    } else {
                        continue;
                    }
                } else if (moveObjects) {
                    deepMove(ref.getNode());
                }
                parentTree.put(ref.getNode());
            }
        }

        if (progress.isCanceled()) {
            return null;
        }

        // now write back all changed trees
        ObjectId newTargetRootId = oldRootTree.getId();
        RevTreeBuilder directRootEntries = repositoryChangedTrees.remove(NodeRef.ROOT);
        if (directRootEntries != null) {
            RevTree newRoot = directRootEntries.build();
            repositoryDatabase.put(newRoot);
            newTargetRootId = newRoot.getId();
        }
        for (Map.Entry<String, RevTreeBuilder> e : repositoryChangedTrees.entrySet()) {
            String treePath = e.getKey();
            ObjectId metadataId = changedTreesMetadataId.get(treePath);
View Full Code Here

        } 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;
View Full Code Here

     *
     * @return the {@link MutableTree} that was created by the operation
     */
    @Override
    protected  RevTreeBuilder _call() {
        ObjectDatabase storage = index ? stagingDatabase() : objectDatabase();
        return new RevTreeBuilder(storage);
    }
View Full Code Here

            default:
                throw new IllegalStateException("Unknown strategy: " + this.strategy);
            }

            RevTree tree = (RevTree) revObject.get();
            ObjectDatabase database = stagingDatabase();
            DepthTreeIterator iter = new DepthTreeIterator(path, metadataId, tree, database,
                    iterStrategy);
            iter.setBoundsFilter(refBoundsFilter);
            return iter;
        default:
View Full Code Here

        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);
View Full Code Here

        progress.complete();

        MutableTree newLeftTree = treeDifference.getLeftTree();

        final ObjectDatabase repositoryDatabase = objectDatabase();
        final RevTree newRoot = newLeftTree.build(stagingDatabase(), repositoryDatabase);
        if (newRoot.trees().isPresent()) {
            for (Node n : newRoot.trees().get()) {
                if (n.getMetadataId().isPresent()) deepMove(n.getMetadataId().get());
            }
View Full Code Here

            @Nullable final NodeRef rightTreeRef) {

        Preconditions.checkArgument(leftTreeRef != null || rightTreeRef != null,
                "either left or right tree shall be non null");

        final ObjectDatabase repositoryDatabase = objectDatabase();
        final String treePath = rightTreeRef == null ? leftTreeRef.path() : rightTreeRef.path();

        final List<String> strippedPathFilters = stripParentAndFiltersThatDontApply(
                this.pathFilters, treePath);

        // find the diffs that apply to the path filters
        final ObjectId leftTreeId = leftTreeRef == null ? RevTree.EMPTY_TREE_ID : leftTreeRef
                .objectId();
        final ObjectId rightTreeId = rightTreeRef == null ? RevTree.EMPTY_TREE_ID : rightTreeRef
                .objectId();

        final Predicate<Bounded> existsFilter = new Predicate<Bounded>() {

            private final ObjectDatabase targetDb = repositoryDatabase;

            @Override
            public boolean apply(Bounded input) {
                ObjectId id = null;
                if (input instanceof Node && TYPE.TREE.equals(((Node) input).getType())) {
                    id = ((Node) input).getObjectId();
                } else if (input instanceof Bucket) {
                    Bucket b = (Bucket) input;
                    id = b.id();
                }
                if (id != null) {
                    if (targetDb.exists(id)) {
                        LOGGER.trace("Ignoring {}. Already exists in target database.", input);
                        return false;
                    }
                }
                return true;
            }
        };
        DiffTree diffs = command(DiffTree.class).setRecursive(false).setReportTrees(false)
                .setOldTree(leftTreeId).setNewTree(rightTreeId).setPathFilter(strippedPathFilters)
                .setCustomFilter(existsFilter);

        // move new blobs from the index to the repository (note: this could be parallelized)
        Supplier<Iterator<Node>> nodesToMove = asNodeSupplierOfNewContents(diffs,
                strippedPathFilters);
        command(DeepMove.class).setObjects(nodesToMove).call();

        final StagingDatabase stagingDatabase = stagingDatabase();

        final RevTree currentLeftTree = stagingDatabase.getTree(leftTreeId);

        final RevTreeBuilder builder = currentLeftTree.builder(repositoryDatabase);

        // remove the exists filter, we need to create the new trees taking into account all the
        // nodes
        diffs.setCustomFilter(null);
        Iterator<DiffEntry> iterator = diffs.get();
        if (!strippedPathFilters.isEmpty()) {
            final Set<String> expected = Sets.newHashSet(strippedPathFilters);
            iterator = Iterators.filter(iterator, new Predicate<DiffEntry>() {
                @Override
                public boolean apply(DiffEntry input) {
                    boolean applies;
                    if (input.isDelete()) {
                        applies = expected.contains(input.oldName());
                    } else {
                        applies = expected.contains(input.newName());
                    }
                    return applies;
                }
            });
        }

        for (; iterator.hasNext();) {
            final DiffEntry diff = iterator.next();
            if (diff.isDelete()) {
                builder.remove(diff.oldName());
            } else {
                NodeRef newObject = diff.getNewObject();
                Node node = newObject.getNode();
                builder.put(node);
            }
        }

        final RevTree newTree = builder.build();
        repositoryDatabase.put(newTree);
        return newTree;
    }
View Full Code Here

TOP

Related Classes of org.locationtech.geogig.storage.ObjectDatabase

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.