Search in sources :

Example 1 with Node

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

the class WorkingTreeInsertHelper method findOrCreateTree.

private NodeRef findOrCreateTree(final String treePath, final FeatureType type) {
    RevTree tree = context.command(FindOrCreateSubtree.class).setChildPath(treePath).setIndex(true).setParent(workHead).setParentPath(NodeRef.ROOT).call();
    ObjectId metadataId = ObjectId.NULL;
    if (type != null) {
        RevFeatureType revFeatureType = RevFeatureTypeImpl.build(type);
        if (tree.isEmpty()) {
            indexDatabase.put(revFeatureType);
        }
        metadataId = revFeatureType.getId();
    }
    Envelope bounds = SpatialOps.boundsOf(tree);
    Node node = Node.create(NodeRef.nodeFromPath(treePath), tree.getId(), metadataId, TYPE.TREE, bounds);
    String parentPath = NodeRef.parentPath(treePath);
    return new NodeRef(node, parentPath, ObjectId.NULL);
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) FindOrCreateSubtree(org.locationtech.geogig.api.plumbing.FindOrCreateSubtree) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Envelope(com.vividsolutions.jts.geom.Envelope) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 2 with Node

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

the class WorkingTreeInsertHelper method put.

public Node put(final ObjectId revFeatureId, final Feature feature) {
    final RevTreeBuilder2 treeBuilder = getTreeBuilder(feature);
    String fid = feature.getIdentifier().getID();
    BoundingBox bounds = feature.getBounds();
    FeatureType type = feature.getType();
    final Node node = treeBuilder.putFeature(revFeatureId, fid, bounds, type);
    return node;
}
Also used : FeatureType(org.opengis.feature.type.FeatureType) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) BoundingBox(org.opengis.geometry.BoundingBox) Node(org.locationtech.geogig.api.Node)

Example 3 with Node

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

the class FormatCommonV2 method readNode.

public static Node readNode(DataInput in) throws IOException {
    final int typeAndMasks = in.readByte() & 0xFF;
    final int nodeType = typeAndMasks & TYPE_READ_MASK;
    final int boundsMask = typeAndMasks & BOUNDS_READ_MASK;
    final int metadataMask = typeAndMasks & METADATA_READ_MASK;
    final RevObject.TYPE contentType = RevObject.TYPE.valueOf(nodeType);
    final String name = in.readUTF();
    final ObjectId objectId = readObjectId(in);
    ObjectId metadataId = ObjectId.NULL;
    if (metadataMask == METADATA_PRESENT_MASK) {
        metadataId = readObjectId(in);
    }
    @Nullable final Envelope bbox;
    if (boundsMask == BOUNDS_NULL_MASK) {
        bbox = null;
    } else if (boundsMask == BOUNDS_POINT_MASK) {
        bbox = readPointBoundingBox(in);
    } else if (boundsMask == BOUNDS_BOX2D_MASK) {
        bbox = readBoundingBox(in);
    } else {
        throw new IllegalStateException(String.format("Illegal bounds mask: %s, expected one of %s, %s, %s", toBinaryString(boundsMask), toBinaryString(BOUNDS_NULL_MASK), toBinaryString(BOUNDS_POINT_MASK), toBinaryString(BOUNDS_BOX2D_MASK)));
    }
    final Node node;
    node = Node.create(name, objectId, metadataId, contentType, bbox);
    return node;
}
Also used : TYPE(org.locationtech.geogig.api.RevObject.TYPE) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Integer.toBinaryString(java.lang.Integer.toBinaryString) Envelope(com.vividsolutions.jts.geom.Envelope) Nullable(javax.annotation.Nullable)

Example 4 with Node

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

the class FormatCommonV2 method readTree.

public static RevTree readTree(ObjectId id, DataInput in) throws IOException {
    final long size = readUnsignedVarLong(in);
    final int treeCount = readUnsignedVarInt(in);
    final ImmutableList.Builder<Node> featuresBuilder = new ImmutableList.Builder<Node>();
    final ImmutableList.Builder<Node> treesBuilder = new ImmutableList.Builder<Node>();
    final SortedMap<Integer, Bucket> buckets = new TreeMap<Integer, Bucket>();
    final int nFeatures = readUnsignedVarInt(in);
    for (int i = 0; i < nFeatures; i++) {
        Node n = readNode(in);
        checkState(RevObject.TYPE.FEATURE.equals(n.getType()), "Non-feature node in tree's feature list.");
        featuresBuilder.add(n);
    }
    final int nTrees = readUnsignedVarInt(in);
    for (int i = 0; i < nTrees; i++) {
        Node n = readNode(in);
        checkState(RevObject.TYPE.TREE.equals(n.getType()), "Non-tree node in tree's subtree list.");
        treesBuilder.add(n);
    }
    final int nBuckets = readUnsignedVarInt(in);
    for (int i = 0; i < nBuckets; i++) {
        int bucketIndex = readUnsignedVarInt(in);
        {
            Integer idx = Integer.valueOf(bucketIndex);
            checkState(!buckets.containsKey(idx), "duplicate bucket index: %s", idx);
        // checkState(bucketIndex < RevTree.MAX_BUCKETS, "Illegal bucket index: %s", idx);
        }
        Bucket bucket = readBucketBody(in);
        buckets.put(Integer.valueOf(bucketIndex), bucket);
    }
    checkState(nBuckets == buckets.size(), "expected %s buckets, got %s", nBuckets, buckets.size());
    ImmutableList<Node> trees = treesBuilder.build();
    ImmutableList<Node> features = featuresBuilder.build();
    checkArgument(buckets.isEmpty() || (trees.isEmpty() && features.isEmpty()), "Tree has mixed buckets and nodes; this is not supported.");
    if (trees.isEmpty() && features.isEmpty()) {
        return RevTreeImpl.createNodeTree(id, size, treeCount, buckets);
    }
    return RevTreeImpl.createLeafTree(id, size, features, trees);
}
Also used : Bucket(org.locationtech.geogig.api.Bucket) ImmutableList(com.google.common.collect.ImmutableList) SimpleFeatureTypeBuilder(org.geotools.feature.simple.SimpleFeatureTypeBuilder) Builder(com.google.common.collect.ImmutableList.Builder) Node(org.locationtech.geogig.api.Node) TreeMap(java.util.TreeMap)

Example 5 with Node

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

the class LocalRemoteRepo method copyNewObjects.

private void copyNewObjects(RevTree oldTree, RevTree newTree, final ObjectDatabase fromDb, final ObjectDatabase toDb, final ProgressListener progress) {
    checkNotNull(oldTree);
    checkNotNull(newTree);
    checkNotNull(fromDb);
    checkNotNull(toDb);
    checkNotNull(progress);
    // the diff walk uses fromDb as both left and right data source since we're comparing what
    // we have in the "origin" database against trees on the same repository
    PostOrderDiffWalk diffWalk = new PostOrderDiffWalk(oldTree, newTree, fromDb, fromDb);
    // holds object ids that need to be copied to the target db. Pruned when it reaches a
    // threshold.
    final Set<ObjectId> ids = new HashSet<ObjectId>();
    // This filter further refines the post order diff walk by making it ignore trees/buckets
    // that are already present in the target db
    Predicate<Bounded> filter = new Predicate<Bounded>() {

        @Override
        public boolean apply(@Nullable Bounded b) {
            if (b == null) {
                return false;
            }
            if (progress.isCanceled()) {
                // abort traversal
                return false;
            }
            ObjectId id;
            if (b instanceof Node) {
                Node node = (Node) b;
                if (RevObject.TYPE.TREE.equals(node.getType())) {
                    // check of existence of trees only. For features the diff filtering is good
                    // enough and checking for existence on each feature would be killer
                    // performance wise
                    id = node.getObjectId();
                } else {
                    return true;
                }
            } else {
                id = ((Bucket) b).id();
            }
            boolean exists = ids.contains(id) || toDb.exists(id);
            return !exists;
        }
    };
    // receives notifications of feature/bucket/tree diffs. Only interested in the "new"/right
    // side of the comparisons
    Consumer consumer = new Consumer() {

        final int bulkSize = 10_000;

        @Override
        public void feature(@Nullable Node left, Node right) {
            add(left);
            add(right);
        }

        @Override
        public void tree(@Nullable Node left, Node right) {
            add(left);
            add(right);
        }

        private void add(@Nullable Node node) {
            if (node == null) {
                return;
            }
            ids.add(node.getObjectId());
            Optional<ObjectId> metadataId = node.getMetadataId();
            if (metadataId.isPresent()) {
                ids.add(metadataId.get());
            }
            checkLimitAndCopy();
        }

        @Override
        public void bucket(int bucketIndex, int bucketDepth, @Nullable Bucket left, Bucket right) {
            if (left != null) {
                ids.add(left.id());
            }
            if (right != null) {
                ids.add(right.id());
            }
            checkLimitAndCopy();
        }

        private void checkLimitAndCopy() {
            if (ids.size() >= bulkSize) {
                copy(ids, fromDb, toDb, progress);
                ids.clear();
            }
        }
    };
    diffWalk.walk(filter, consumer);
    // copy remaining objects
    copy(ids, fromDb, toDb, progress);
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Predicate(com.google.common.base.Predicate) Bounded(org.locationtech.geogig.api.Bounded) Consumer(org.locationtech.geogig.api.plumbing.diff.PostOrderDiffWalk.Consumer) Bucket(org.locationtech.geogig.api.Bucket) PostOrderDiffWalk(org.locationtech.geogig.api.plumbing.diff.PostOrderDiffWalk) Nullable(javax.annotation.Nullable) HashSet(java.util.HashSet)

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