Search in sources :

Example 1 with PageTree

use of com.cinchapi.ccl.syntax.PageTree in project concourse by cinchapi.

the class ExportCli method init.

/**
 * Initialize the CLI based on the arguments that are provided.
 */
private void init() {
    ExportOptions opts = (ExportOptions) options;
    // file
    if (!Empty.ness().describes(opts.file)) {
        file = Paths.get(opts.file);
        File $file = file.toFile();
        $file.getParentFile().mkdirs();
        try {
            $file.createNewFile();
        } catch (IOException e) {
            CheckedExceptions.wrapAsRuntimeException(e);
        }
    }
    // records
    if (!Empty.ness().describes(opts.records)) {
        records = AnyObjects.split(opts.records, ',').stream().map(Long::parseLong).collect(Collectors.toCollection(LinkedHashSet::new));
    }
    // keys
    if (!Empty.ness().describes(opts.keys)) {
        keys = AnyObjects.split(opts.keys, ',').stream().collect(Collectors.toCollection(LinkedHashSet::new));
    }
    // order
    if (!Empty.ness().describes(opts.order)) {
        if (!opts.order.toLowerCase().startsWith("order by")) {
            opts.order = "ORDER BY " + opts.order;
        }
        try {
            AbstractSyntaxTree ast = ConcourseCompiler.get().parse(opts.order);
            OrderTree tree = (OrderTree) ast;
            order = Order.from(tree);
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid order CCL statement");
        }
    }
    // page
    String $page = "";
    if (!Empty.ness().describes(opts.page)) {
        $page += "PAGE " + opts.page + " ";
    }
    if (!Empty.ness().describes(opts.size)) {
        $page += "SIZE " + opts.size;
    }
    if (!Empty.ness().describes($page)) {
        try {
            AbstractSyntaxTree ast = ConcourseCompiler.get().parse($page);
            PageTree tree = (PageTree) ast;
            page = Page.from(tree);
        } catch (Exception e) {
            throw new IllegalArgumentException("Invalid page or size argument");
        }
    }
    excludeRecordId = opts.excludeRecordId;
    condition = opts.condition;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) OrderTree(com.cinchapi.ccl.syntax.OrderTree) PageTree(com.cinchapi.ccl.syntax.PageTree) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Aggregations

AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)1 OrderTree (com.cinchapi.ccl.syntax.OrderTree)1 PageTree (com.cinchapi.ccl.syntax.PageTree)1 File (java.io.File)1 IOException (java.io.IOException)1 LinkedHashSet (java.util.LinkedHashSet)1