Search in sources :

Example 11 with ObjectId

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

the class PostOrderIterator method computeNext.

@Override
protected RevObject computeNext() {
    while (!toVisit.isEmpty()) {
        List<ObjectId> currentList = toVisit.get(0);
        if (currentList.isEmpty()) {
            // No more ids at this depth - pop a level off of the stack and switch to "visiting"
            // mode
            enqueue = false;
            toVisit.remove(0);
        } else {
            if (enqueue) {
                // We're building up a list of objects to visit, so add all the reachable
                // objects from here to the front of the toVisit stack
                final ObjectId id = currentList.get(0);
                final RevObject object = database.get(id);
                final List<ObjectId> next = new ArrayList<ObjectId>();
                successors.findSuccessors(object, next);
                toVisit.add(0, next);
            } else {
                // We just visited a node, so switch back to enqueuing mode in order to make
                // sure the successors of the next one at this depth are visited.
                enqueue = true;
                final ObjectId id = currentList.remove(0);
                if (successors.previsit(id)) {
                    return database.get(id);
                }
            }
        }
    }
    // when the toVisit list becomes empty, we are done
    return endOfData();
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevObject(org.locationtech.geogig.api.RevObject) ArrayList(java.util.ArrayList)

Example 12 with ObjectId

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

the class WorkingTree method putInDatabase.

/**
     * Adds a single feature to the staging database.
     * 
     * @param feature the feature to add
     * @param metadataId
     * @return the Node for the inserted feature
     */
private Node putInDatabase(final Feature feature, final ObjectId metadataId) {
    checkNotNull(feature);
    checkNotNull(metadataId);
    final RevFeature newFeature = RevFeatureBuilder.build(feature);
    final ObjectId objectId = newFeature.getId();
    final Envelope bounds = (ReferencedEnvelope) feature.getBounds();
    final String nodeName = feature.getIdentifier().getID();
    indexDatabase.put(newFeature);
    Node newObject = Node.create(nodeName, objectId, metadataId, TYPE.FEATURE, bounds);
    return newObject;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) RevFeature(org.locationtech.geogig.api.RevFeature) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(com.vividsolutions.jts.geom.Envelope)

Example 13 with ObjectId

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

the class WorkingTree method insertBlobs.

@SuppressWarnings("rawtypes")
private List<Future<Integer>> insertBlobs(final FeatureSource source, final Query baseQuery, final ExecutorService executorService, final ProgressListener listener, @Nullable final Long collectionSize, int nTasks, RevTreeBuilder2 builder) {
    int partitionSize = 0;
    BulkOpListener bulkOpListener;
    if (collectionSize == null) {
        nTasks = 1;
        partitionSize = Integer.MAX_VALUE;
        bulkOpListener = BulkOpListener.NOOP_LISTENER;
    } else {
        final int total = collectionSize.intValue();
        partitionSize = total / nTasks;
        bulkOpListener = new BulkOpListener() {

            int inserted = 0;

            @Override
            public synchronized void inserted(ObjectId object, @Nullable Integer storageSizeBytes) {
                listener.setProgress((float) (++inserted * 100) / total);
            }
        };
    }
    List<Future<Integer>> results = Lists.newArrayList();
    for (int i = 0; i < nTasks; i++) {
        Integer offset = nTasks == 1 ? null : i * partitionSize;
        Integer limit = nTasks == 1 ? null : partitionSize;
        if (i == nTasks - 1) {
            // let the last task take any remaining
            limit = null;
        // feature
        }
        results.add(executorService.submit(new BlobInsertTask(source, offset, limit, bulkOpListener, builder)));
    }
    return results;
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) Future(java.util.concurrent.Future) BulkOpListener(org.locationtech.geogig.storage.BulkOpListener)

Example 14 with ObjectId

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

the class WorkingTree method createTypeTree.

public synchronized NodeRef createTypeTree(final String treePath, final FeatureType featureType) {
    final RevTree workHead = getTree();
    Optional<NodeRef> typeTreeRef = context.command(FindTreeChild.class).setIndex(true).setParent(workHead).setChildPath(treePath).call();
    final RevFeatureType revType = RevFeatureTypeImpl.build(featureType);
    if (typeTreeRef.isPresent()) {
        throw new IllegalArgumentException("Tree already exists at " + treePath);
    }
    indexDatabase.put(revType);
    final ObjectId metadataId = revType.getId();
    final RevTree newTree = new RevTreeBuilder(indexDatabase).build();
    ObjectId newWorkHeadId = context.command(WriteBack.class).setToIndex(true).setAncestor(workHead.builder(indexDatabase)).setChildPath(treePath).setTree(newTree).setMetadataId(metadataId).call();
    updateWorkHead(newWorkHeadId);
    return context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(treePath).call().get();
}
Also used : NodeRef(org.locationtech.geogig.api.NodeRef) ObjectId(org.locationtech.geogig.api.ObjectId) RevTreeBuilder(org.locationtech.geogig.api.RevTreeBuilder) FindTreeChild(org.locationtech.geogig.api.plumbing.FindTreeChild) RevFeatureType(org.locationtech.geogig.api.RevFeatureType) RevTree(org.locationtech.geogig.api.RevTree)

Example 15 with ObjectId

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

the class WorkingTree method insert.

/**
     * Insert a single feature into the working tree and updates the WORK_HEAD ref.
     * 
     * @param parentTreePath path of the parent tree to insert the feature into
     * @param feature the feature to insert
     */
public Node insert(final String parentTreePath, final Feature feature) {
    final FeatureType featureType = feature.getType();
    NodeRef treeRef;
    Optional<NodeRef> typeTreeRef = context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(parentTreePath).call();
    ObjectId metadataId;
    if (typeTreeRef.isPresent()) {
        treeRef = typeTreeRef.get();
        RevFeatureType newFeatureType = RevFeatureTypeImpl.build(featureType);
        metadataId = newFeatureType.getId().equals(treeRef.getMetadataId()) ? ObjectId.NULL : newFeatureType.getId();
        if (!newFeatureType.getId().equals(treeRef.getMetadataId())) {
            indexDatabase.put(newFeatureType);
        }
    } else {
        treeRef = createTypeTree(parentTreePath, featureType);
        // treeRef.getMetadataId();
        metadataId = ObjectId.NULL;
    }
    // ObjectId metadataId = treeRef.getMetadataId();
    final Node node = putInDatabase(feature, metadataId);
    RevTreeBuilder parentTree = context.command(FindOrCreateSubtree.class).setIndex(true).setParent(Suppliers.ofInstance(Optional.of(getTree()))).setChildPath(parentTreePath).call().builder(indexDatabase);
    parentTree.put(node);
    final ObjectId treeMetadataId = treeRef.getMetadataId();
    ObjectId newTree = context.command(WriteBack.class).setAncestor(getTreeSupplier()).setChildPath(parentTreePath).setToIndex(true).setTree(parentTree.build()).setMetadataId(treeMetadataId).call();
    updateWorkHead(newTree);
    final String featurePath = NodeRef.appendChild(parentTreePath, node.getName());
    Optional<NodeRef> featureRef = context.command(FindTreeChild.class).setIndex(true).setParent(getTree()).setChildPath(featurePath).call();
    return featureRef.get().getNode();
}
Also used : RevFeatureType(org.locationtech.geogig.api.RevFeatureType) FeatureType(org.opengis.feature.type.FeatureType) 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) RevFeatureType(org.locationtech.geogig.api.RevFeatureType)

Aggregations

ObjectId (org.locationtech.geogig.api.ObjectId)361 Test (org.junit.Test)133 RevCommit (org.locationtech.geogig.api.RevCommit)109 NodeRef (org.locationtech.geogig.api.NodeRef)98 RevTree (org.locationtech.geogig.api.RevTree)91 RevObject (org.locationtech.geogig.api.RevObject)53 Ref (org.locationtech.geogig.api.Ref)46 Node (org.locationtech.geogig.api.Node)44 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)38 Feature (org.opengis.feature.Feature)35 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)34 LogOp (org.locationtech.geogig.api.porcelain.LogOp)28 RevTreeBuilder (org.locationtech.geogig.api.RevTreeBuilder)27 LinkedList (java.util.LinkedList)26 ArrayList (java.util.ArrayList)25 RevFeature (org.locationtech.geogig.api.RevFeature)25 IOException (java.io.IOException)23 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)23 UpdateRef (org.locationtech.geogig.api.plumbing.UpdateRef)23 SymRef (org.locationtech.geogig.api.SymRef)22