use of com.cinchapi.ccl.syntax.OrderTree 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;
}
Aggregations