Search in sources :

Example 21 with RevObject

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

the class MergeBase method runInternal.

@Override
public void runInternal(GeogigCLI cli) throws IOException {
    checkParameter(commits.size() == 2, "Two commit references must be provided");
    ConsoleReader console = cli.getConsole();
    GeoGIG geogig = cli.getGeogig();
    Optional<RevObject> left = geogig.command(RevObjectParse.class).setRefSpec(commits.get(0)).call();
    checkParameter(left.isPresent(), commits.get(0) + " does not resolve to any object.");
    checkParameter(left.get() instanceof RevCommit, commits.get(0) + " does not resolve to a commit");
    Optional<RevObject> right = geogig.command(RevObjectParse.class).setRefSpec(commits.get(1)).call();
    checkParameter(right.isPresent(), commits.get(1) + " does not resolve to any object.");
    checkParameter(right.get() instanceof RevCommit, commits.get(1) + " does not resolve to a commit");
    Optional<ObjectId> ancestor = geogig.command(FindCommonAncestor.class).setLeft((RevCommit) left.get()).setRight((RevCommit) right.get()).call();
    checkParameter(ancestor.isPresent(), "No common ancestor was found.");
    console.print(ancestor.get().toString());
}
Also used : ConsoleReader(jline.console.ConsoleReader) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) FindCommonAncestor(org.locationtech.geogig.api.plumbing.FindCommonAncestor) GeoGIG(org.locationtech.geogig.api.GeoGIG) RevCommit(org.locationtech.geogig.api.RevCommit)

Example 22 with RevObject

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

the class AbstractObjectDatabase method writeObject.

protected void writeObject(RevObject object, OutputStream target) {
    ObjectWriter<RevObject> writer = serializationFactory.createObjectWriter(object.getType());
    LZFOutputStream cOut = new LZFOutputStream(target);
    try {
        writer.write(object, cOut);
    } catch (IOException e) {
        throw Throwables.propagate(e);
    } finally {
        try {
            cOut.flush();
            cOut.close();
        } catch (Exception e) {
            throw Throwables.propagate(e);
        }
    }
// int size = ((ByteArrayOutputStream) target).size();
// System.err.printf("%d,%s,%s\n", size, object.getId(), object.getType());
}
Also used : RevObject(org.locationtech.geogig.api.RevObject) IOException(java.io.IOException) IOException(java.io.IOException) LZFOutputStream(com.ning.compress.lzf.LZFOutputStream)

Example 23 with RevObject

use of org.locationtech.geogig.api.RevObject 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 24 with RevObject

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

the class AbstractObjectDatabase method putAll.

/**
     * This default implementation calls {@link #putInternal(ObjectId, byte[])} for each object;
     * subclasses may override if appropriate.
     */
@Override
public void putAll(Iterator<? extends RevObject> objects, final BulkOpListener listener) {
    ByteArrayOutputStream rawOut = new ByteArrayOutputStream();
    while (objects.hasNext()) {
        RevObject object = objects.next();
        rawOut.reset();
        writeObject(object, rawOut);
        final byte[] rawData = rawOut.toByteArray();
        final ObjectId id = object.getId();
        final boolean added = putInternal(id, rawData);
        if (added) {
            listener.inserted(object.getId(), rawData.length);
        } else {
            listener.found(object.getId(), null);
        }
    }
}
Also used : RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 25 with RevObject

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

the class HashObject method _call.

/**
     * Hashes a RevObject using a SHA1 hasher.
     * 
     * @return a new ObjectId created from the hash of the RevObject.
     */
@Override
protected ObjectId _call() {
    Preconditions.checkState(object != null, "Object has not been set.");
    final Hasher hasher = ObjectId.HASH_FUNCTION.newHasher();
    @SuppressWarnings("unchecked") final Funnel<RevObject> funnel = (Funnel<RevObject>) FUNNELS[object.getType().value()];
    funnel.funnel(object, hasher);
    final byte[] rawKey = hasher.hash().asBytes();
    final ObjectId id = ObjectId.createNoClone(rawKey);
    return id;
}
Also used : Funnel(com.google.common.hash.Funnel) Hasher(com.google.common.hash.Hasher) RevObject(org.locationtech.geogig.api.RevObject) ObjectId(org.locationtech.geogig.api.ObjectId)

Aggregations

RevObject (org.locationtech.geogig.api.RevObject)84 ObjectId (org.locationtech.geogig.api.ObjectId)51 RevCommit (org.locationtech.geogig.api.RevCommit)30 NodeRef (org.locationtech.geogig.api.NodeRef)22 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)22 RevTree (org.locationtech.geogig.api.RevTree)21 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 RevFeature (org.locationtech.geogig.api.RevFeature)17 RevObjectParse (org.locationtech.geogig.api.plumbing.RevObjectParse)16 Feature (org.opengis.feature.Feature)16 IOException (java.io.IOException)15 LinkedList (java.util.LinkedList)15 LogOp (org.locationtech.geogig.api.porcelain.LogOp)14 GeoGIG (org.locationtech.geogig.api.GeoGIG)13 DiffEntry (org.locationtech.geogig.api.plumbing.diff.DiffEntry)11 HashMap (java.util.HashMap)10 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)10 Optional (com.google.common.base.Optional)8 ObjectDatabase (org.locationtech.geogig.storage.ObjectDatabase)8