use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class MongoGraphDatabase method getChildren.
@Override
public ImmutableList<ObjectId> getChildren(ObjectId id) {
DBObject query = new BasicDBObject();
query.put("_label", Relationship.PARENT.name());
query.put("_out", id.toString());
DBCursor cursor = collection.find(query);
Function<DBObject, ObjectId> idMapper = new Function<DBObject, ObjectId>() {
@Override
public ObjectId apply(DBObject o) {
return ObjectId.valueOf((String) o.get("_in"));
}
};
return ImmutableList.copyOf(Iterators.transform(cursor.iterator(), idMapper));
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class DeepMove method moveObjects.
private void moveObjects(final ObjectDatabase from, final ObjectDatabase to, final Supplier<Iterator<Node>> nodesToMove, final Set<ObjectId> metadataIds) {
Iterable<ObjectId> ids = new Iterable<ObjectId>() {
final Function<Node, ObjectId> asId = new Function<Node, ObjectId>() {
@Override
public ObjectId apply(Node input) {
Optional<ObjectId> metadataId = input.getMetadataId();
if (metadataId.isPresent()) {
metadataIds.add(input.getMetadataId().get());
}
ObjectId id = input.getObjectId();
return id;
}
};
@Override
public Iterator<ObjectId> iterator() {
Iterator<Node> iterator = nodesToMove.get();
Iterator<ObjectId> ids = Iterators.transform(iterator, asId);
return ids;
}
};
final ExecutorService deletingService = Executors.newSingleThreadExecutor();
try {
final DeletingListener deletingListener = new DeletingListener(deletingService, from);
// store objects into the target db and remove them from the origin db in one shot
to.putAll(from.getAll(ids), deletingListener);
// in case there are some deletes pending cause the iterator finished and the listener
// didn't fill its buffer
deletingListener.deleteInserted();
} finally {
deletingService.shutdown();
while (!deletingService.isTerminated()) {
try {
deletingService.awaitTermination(100, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
// ok, still awaiting for delete tasks to finish
}
}
}
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class DiffIndex method _call.
/**
* Finds differences between the tree pointed to by the given ref and the index.
*
* @return an iterator to a set of differences between the two trees
* @see DiffEntry
*/
@Override
protected Iterator<DiffEntry> _call() {
final String oldVersion = Optional.fromNullable(refSpec).or(Ref.HEAD);
final Optional<ObjectId> rootTreeId;
rootTreeId = command(ResolveTreeish.class).setTreeish(oldVersion).call();
Preconditions.checkArgument(rootTreeId.isPresent(), "refSpec %s did not resolve to a tree", oldVersion);
final RevTree rootTree;
rootTree = command(RevObjectParse.class).setObjectId(rootTreeId.get()).call(RevTree.class).get();
final RevTree newTree = index().getTree();
DiffTree diff = command(DiffTree.class).setPathFilter(this.pathFilters).setReportTrees(this.reportTrees).setOldTree(rootTree.getId()).setNewTree(newTree.getId());
return diff.call();
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class FileObjectDatabase method lookUp.
/**
* Searches the database for {@link ObjectId}s that match the given partial id.
*
* @param partialId the partial id to search for
* @return a list of matching results
*/
@Override
public List<ObjectId> lookUp(final String partialId) {
File parent = filePath(partialId).getParentFile();
String[] list = parent.list();
if (null == list) {
return ImmutableList.of();
}
Builder<ObjectId> builder = ImmutableList.builder();
for (String oid : list) {
if (oid.startsWith(partialId)) {
builder.add(ObjectId.valueOf(oid));
}
}
return builder.build();
}
use of org.locationtech.geogig.api.ObjectId in project GeoGig by boundlessgeo.
the class RevParseTest method testResolveToMultipleIds.
@Test
public void testResolveToMultipleIds() {
StagingDatabase mockIndexDb = mock(StagingDatabase.class);
Context mockCommands = mock(Context.class);
RefParse mockRefParse = mock(RefParse.class);
when(mockRefParse.setName(anyString())).thenReturn(mockRefParse);
when(mockCommands.command(eq(RefParse.class))).thenReturn(mockRefParse);
Optional<Ref> ref = Optional.absent();
when(mockRefParse.call()).thenReturn(ref);
List<ObjectId> oIds = Arrays.asList(ObjectId.forString("Object 1"), ObjectId.forString("Object 2"));
when(mockIndexDb.lookUp(anyString())).thenReturn(oIds);
when(mockCommands.stagingDatabase()).thenReturn(mockIndexDb);
RevParse command = new RevParse();
command.setContext(mockCommands);
exception.expect(IllegalArgumentException.class);
command.setRefSpec(commitId1.toString().substring(0, commitId1.toString().length() - 2)).call();
}
Aggregations