Search in sources :

Example 1 with DeferredWrite

use of com.cinchapi.concourse.server.ConcourseServer.DeferredWrite in project concourse by cinchapi.

the class Operations method insertDeferredAtomic.

/**
 * Atomically insert a list of {@link DeferredWrite deferred writes}. This
 * method should only be called after all necessary calls to
 * {@link #insertAtomic(Multimap, long, AtomicOperation, List)} have been
 * made.
 *
 * @param parser
 * @param deferred
 * @param atomic
 * @return {@code true} if all the writes are successful
 */
public static boolean insertDeferredAtomic(List<DeferredWrite> deferred, AtomicOperation atomic) {
    // have already been checked
    for (DeferredWrite write : deferred) {
        if (write.getValue() instanceof ResolvableLink) {
            ResolvableLink rlink = (ResolvableLink) write.getValue();
            AbstractSyntaxTree ast = ConcourseCompiler.get().parse(rlink.getCcl());
            Set<Long> targets = ast.accept(Finder.instance(), atomic);
            for (long target : targets) {
                if (target == write.getRecord()) {
                    // accidentally creates self links.
                    continue;
                }
                TObject link = Convert.javaToThrift(Link.to(target));
                if (!atomic.add(write.getKey(), link, write.getRecord())) {
                    return false;
                }
            }
        } else if (!atomic.add(write.getKey(), Convert.javaToThrift(write.getValue()), write.getRecord())) {
            return false;
        }
    }
    return true;
}
Also used : ResolvableLink(com.cinchapi.concourse.util.Convert.ResolvableLink) TObject(com.cinchapi.concourse.thrift.TObject) DeferredWrite(com.cinchapi.concourse.server.ConcourseServer.DeferredWrite) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree)

Aggregations

AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)1 DeferredWrite (com.cinchapi.concourse.server.ConcourseServer.DeferredWrite)1 TObject (com.cinchapi.concourse.thrift.TObject)1 ResolvableLink (com.cinchapi.concourse.util.Convert.ResolvableLink)1