Search in sources :

Example 1 with DuplicateEntryException

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));
    }
}
Also used : AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) DuplicateEntryException(com.cinchapi.concourse.thrift.DuplicateEntryException) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) VerifyReadPermission(com.cinchapi.concourse.server.aop.VerifyReadPermission) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 2 with DuplicateEntryException

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()));
    }
}
Also used : Multimap(com.google.common.collect.Multimap) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) DuplicateEntryException(com.cinchapi.concourse.thrift.DuplicateEntryException) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 3 with DuplicateEntryException

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));
    }
}
Also used : Multimap(com.google.common.collect.Multimap) AbstractSyntaxTree(com.cinchapi.ccl.syntax.AbstractSyntaxTree) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) DuplicateEntryException(com.cinchapi.concourse.thrift.DuplicateEntryException) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Aggregations

TranslateClientExceptions (com.cinchapi.concourse.server.aop.TranslateClientExceptions)3 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)3 AtomicSupport (com.cinchapi.concourse.server.storage.AtomicSupport)3 DuplicateEntryException (com.cinchapi.concourse.thrift.DuplicateEntryException)3 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)2 VerifyWritePermission (com.cinchapi.concourse.server.aop.VerifyWritePermission)2 Multimap (com.google.common.collect.Multimap)2 VerifyReadPermission (com.cinchapi.concourse.server.aop.VerifyReadPermission)1