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();
}
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;
}
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;
}
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();
}
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();
}
Aggregations