use of com.cinchapi.concourse.thrift.TCriteria in project concourse by cinchapi.
the class ConcourseServer method selectCriteriaTimeOrder.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Map<Long, Map<String, Set<TObject>>> selectCriteriaTimeOrder(TCriteria criteria, long timestamp, TOrder order, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AbstractSyntaxTree ast = compiler.parse(criteria);
AtomicSupport store = getStore(transaction, environment);
SortableTable<Set<TObject>> result = emptySortableResultDataset();
AtomicOperations.executeWithRetry(store, atomic -> Operations.selectAstAtomic(ast, timestamp, result, null, $result -> $result.sort(Sorting.byValues(Orders.from(order), atomic), timestamp), atomic));
return result;
}
use of com.cinchapi.concourse.thrift.TCriteria in project concourse by cinchapi.
the class ConcourseServer method findCriteria.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Set<Long> findCriteria(TCriteria criteria, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AbstractSyntaxTree ast = compiler.parse(criteria);
AtomicSupport store = getStore(transaction, environment);
Function<Store, Set<Long>> function = $store -> ast.accept(Finder.instance(), $store);
try {
return function.apply(store);
} catch (InsufficientAtomicityException e) {
return AtomicOperations.supplyWithRetry(store, atomic -> function.apply(atomic));
}
}
use of com.cinchapi.concourse.thrift.TCriteria in project concourse by cinchapi.
the class Command method init.
/**
* Inspect the operation and populate the operation variables if they
* haven't already been {@link #initialized}.
*/
private void init() {
if (!initialized) {
String function = method.getName();
String[] toks = CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, function).split("-");
Association args = Association.of();
if (function.equals("getServerVersion")) {
operation = function;
} else if (function.equals("verifyOrSet")) {
operation = function;
args.put("key", params[0]);
args.put("value", params[1]);
args.put("record", params[2]);
} else if (function.equals("verifyAndSwap")) {
operation = function;
args.put("key", params[0]);
args.put("record", params[2]);
args.put("values", ImmutableList.of(params[1], params[3]));
} else if (function.equals("findOrInsertCclJson")) {
operation = "findOrInsert";
args.put("ccl", params[0]);
} else if (function.equals("findOrInsertCriteriaJson")) {
operation = "findOrInsert";
args.put("criteria", params[0]);
} else if (function.equals("findOrAddKeyValue")) {
operation = "findOrAdd";
args.put("key", params[0]);
conditionKeys = ImmutableSet.of((String) params[0]);
} else {
operation = toks[0];
for (int i = 1; i < toks.length; ++i) {
args.put(toks[i].toLowerCase(), params[i - 1]);
}
}
// Parser
if (args.containsKey("ccl")) {
String ccl = args.fetch("ccl");
conditionTree = (ConditionTree) ConcourseCompiler.get().parse(ccl);
} else if (args.containsKey("criteria")) {
TCriteria tcriteria = args.fetch("criteria");
Criteria criteria = Language.translateFromThriftCriteria(tcriteria);
conditionTree = (ConditionTree) ConcourseCompiler.get().parse(criteria.ccl());
} else {
conditionTree = null;
}
// operationKeys
if (args.containsKey("key")) {
String key = args.fetch("key");
operationKeys = Sets.newHashSet(key);
} else if (args.containsKey("keys")) {
Collection<String> keys = args.fetch("keys");
operationKeys = Sets.newHashSet(keys);
} else {
operationKeys = ImmutableSet.of();
}
// operationRecords
if (args.containsKey("record")) {
long record = args.fetch("record");
operationRecords = Sets.newHashSet(record);
} else if (args.containsKey("records")) {
Collection<Long> records = args.fetch("records");
operationRecords = Sets.newHashSet(records);
} else {
operationRecords = ImmutableSet.of();
}
// order
if (args.containsKey("order")) {
TOrder torder = args.fetch("order");
order = JavaThriftBridge.convert(torder);
} else {
order = null;
}
// methods above.
if (conditionKeys == null && conditionTree != null) {
conditionKeys = ConcourseCompiler.get().analyze(conditionTree).keys();
} else if (function.startsWith("findKey")) {
conditionKeys = ImmutableSet.of((String) params[0]);
} else if (conditionKeys == null) {
conditionKeys = ImmutableSet.of();
}
// operationTimestamp
if (args.containsKey("time")) {
operationTimestamp = args.fetch("time");
}
initialized = true;
}
}
use of com.cinchapi.concourse.thrift.TCriteria in project concourse by cinchapi.
the class ConcourseServer method selectKeysCriteriaTimeOrder.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Map<Long, Map<String, Set<TObject>>> selectKeysCriteriaTimeOrder(List<String> keys, TCriteria criteria, long timestamp, TOrder order, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AbstractSyntaxTree ast = compiler.parse(criteria);
AtomicSupport store = getStore(transaction, environment);
SortableTable<Set<TObject>> result = emptySortableResultDataset();
AtomicOperations.executeWithRetry(store, atomic -> Operations.selectKeysAstAtomic(keys, ast, timestamp, result, null, $result -> $result.sort(Sorting.byValues(Orders.from(order), atomic), timestamp), atomic));
return result;
}
use of com.cinchapi.concourse.thrift.TCriteria in project concourse by cinchapi.
the class ConcourseServer method getKeysCriteriaTimeOrder.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public Map<Long, Map<String, TObject>> getKeysCriteriaTimeOrder(List<String> keys, TCriteria criteria, long timestamp, TOrder order, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AbstractSyntaxTree ast = compiler.parse(criteria);
AtomicSupport store = getStore(transaction, environment);
SortableTable<TObject> result = SortableTable.singleValued(Maps.newLinkedHashMap());
AtomicOperations.executeWithRetry(store, atomic -> Operations.getKeysAstAtomic(keys, ast, timestamp, result, null, $result -> $result.sort(Sorting.byValue(Orders.from(order), atomic), timestamp), atomic));
return result;
}
Aggregations