Search in sources :

Example 51 with ObjectId

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));
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) Function(com.google.common.base.Function) DBCursor(com.mongodb.DBCursor) ObjectId(org.locationtech.geogig.api.ObjectId) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject)

Example 52 with ObjectId

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
            }
        }
    }
}
Also used : Optional(com.google.common.base.Optional) ObjectId(org.locationtech.geogig.api.ObjectId) Node(org.locationtech.geogig.api.Node) Function(com.google.common.base.Function) ExecutorService(java.util.concurrent.ExecutorService)

Example 53 with ObjectId

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();
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) RevTree(org.locationtech.geogig.api.RevTree)

Example 54 with ObjectId

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();
}
Also used : ObjectId(org.locationtech.geogig.api.ObjectId) File(java.io.File)

Example 55 with ObjectId

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();
}
Also used : Context(org.locationtech.geogig.api.Context) Ref(org.locationtech.geogig.api.Ref) ObjectId(org.locationtech.geogig.api.ObjectId) StagingDatabase(org.locationtech.geogig.storage.StagingDatabase) Test(org.junit.Test)

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