use of com.cinchapi.concourse.thrift.DuplicateEntryException in project concourse by cinchapi.
the class ConcourseServer method findOrAddKeyValue.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyReadPermission
public long findOrAddKeyValue(String key, TObject value, AccessToken creds, TransactionToken transaction, String environment) throws TException {
AtomicSupport store = getStore(transaction, environment);
Set<Long> records = Sets.newLinkedHashSetWithExpectedSize(1);
AtomicOperations.executeWithRetry(store, (atomic) -> {
records.clear();
records.addAll(atomic.find(key, Operator.EQUALS, value));
if (records.isEmpty()) {
long record = Time.now();
Operations.addIfEmptyAtomic(key, value, record, atomic);
records.add(record);
}
});
if (records.size() == 1) {
return Iterables.getOnlyElement(records);
} else {
throw new DuplicateEntryException(AnyStrings.joinWithSpace("Found", records.size(), "records that match", key, "=", value));
}
}
use of com.cinchapi.concourse.thrift.DuplicateEntryException in project concourse by cinchapi.
the class ConcourseServer method findOrInsertCriteriaJson.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public long findOrInsertCriteriaJson(TCriteria criteria, String json, AccessToken creds, TransactionToken transaction, String environment) throws TException {
List<Multimap<String, Object>> objects = Lists.newArrayList(Convert.jsonToJava(json));
AbstractSyntaxTree ast = compiler.parse(criteria);
AtomicSupport store = getStore(transaction, environment);
Set<Long> records = Sets.newLinkedHashSet();
AtomicOperations.executeWithRetry(store, (atomic) -> {
records.clear();
Operations.findOrInsertAtomic(records, objects, ast, atomic);
});
if (records.size() == 1) {
return Iterables.getOnlyElement(records);
} else {
throw new DuplicateEntryException(AnyStrings.joinWithSpace("Found", records.size(), "records that match", Language.translateFromThriftCriteria(criteria).ccl()));
}
}
use of com.cinchapi.concourse.thrift.DuplicateEntryException in project concourse by cinchapi.
the class ConcourseServer method findOrInsertCclJson.
@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public long findOrInsertCclJson(String ccl, String json, AccessToken creds, TransactionToken transaction, String environment) throws TException {
List<Multimap<String, Object>> objects = Lists.newArrayList(Convert.jsonToJava(json));
AtomicSupport store = getStore(transaction, environment);
Set<Long> records = Sets.newLinkedHashSet();
AtomicOperations.executeWithRetry(store, (atomic) -> {
records.clear();
AbstractSyntaxTree ast;
if (objects.size() == 1) {
// CON-321: Support local resolution when the data blob is a
// single object
ast = compiler.parse(ccl, objects.get(0));
} else {
ast = compiler.parse(ccl);
}
Operations.findOrInsertAtomic(records, objects, ast, atomic);
});
if (records.size() == 1) {
return Iterables.getOnlyElement(records);
} else {
throw new DuplicateEntryException(AnyStrings.joinWithSpace("Found", records.size(), "records that match", ccl));
}
}
Aggregations