Search in sources :

Example 6 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission in project concourse by cinchapi.

the class ConcourseServer method setKeyValueRecords.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public void setKeyValueRecords(String key, TObject value, List<Long> records, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AtomicSupport store = getStore(transaction, environment);
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        for (long record : records) {
            atomic.set(key, value, record);
        }
    });
}
Also used : AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 7 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission 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 8 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission in project concourse by cinchapi.

the class ConcourseServer method clearKeyRecords.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public void clearKeyRecords(String key, List<Long> records, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AtomicSupport store = getStore(transaction, environment);
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        for (long record : records) {
            Operations.clearKeyRecordAtomic(key, record, atomic);
        }
    });
}
Also used : AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 9 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission in project concourse by cinchapi.

the class ConcourseServer method insertJson.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public Set<Long> insertJson(String json, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    List<Multimap<String, Object>> objects = Convert.anyJsonToJava(json);
    AtomicSupport store = getStore(transaction, environment);
    Set<Long> records = Sets.newLinkedHashSet();
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        records.clear();
        List<DeferredWrite> deferred = Lists.newArrayList();
        for (Multimap<String, Object> object : objects) {
            long record;
            if (object.containsKey(Constants.JSON_RESERVED_IDENTIFIER_NAME)) {
                // If the $id$ is specified in the JSON blob, insert the
                // data into that record since no record(s) are provided
                // as method parameters.
                // WARNING: This means that doing the equivalent of
                // `insert(jsonify(records))` will cause an infinite
                // loop because this method will attempt to insert the
                // data into the same records from which it was
                // exported. Therefore, advise users to not export data
                // with the $id and import that same data in the same
                // environment.
                record = ((Number) Iterables.getOnlyElement(object.get(Constants.JSON_RESERVED_IDENTIFIER_NAME))).longValue();
            } else {
                record = Time.now();
            }
            atomic.touch(record);
            if (Operations.insertAtomic(object, record, atomic, deferred)) {
                records.add(record);
            } else {
                throw AtomicStateException.RETRY;
            }
        }
        Operations.insertDeferredAtomic(deferred, atomic);
    });
    return records;
}
Also used : Multimap(com.google.common.collect.Multimap) AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) ComplexTObject(com.cinchapi.concourse.thrift.ComplexTObject) TObject(com.cinchapi.concourse.thrift.TObject) VerifyWritePermission(com.cinchapi.concourse.server.aop.VerifyWritePermission) VerifyAccessToken(com.cinchapi.concourse.server.aop.VerifyAccessToken) TranslateClientExceptions(com.cinchapi.concourse.server.aop.TranslateClientExceptions)

Example 10 with VerifyWritePermission

use of com.cinchapi.concourse.server.aop.VerifyWritePermission in project concourse by cinchapi.

the class ConcourseServer method revertKeyRecordsTime.

@Override
@TranslateClientExceptions
@VerifyAccessToken
@VerifyWritePermission
public void revertKeyRecordsTime(String key, List<Long> records, long timestamp, AccessToken creds, TransactionToken transaction, String environment) throws TException {
    AtomicSupport store = getStore(transaction, environment);
    AtomicOperations.executeWithRetry(store, (atomic) -> {
        for (long record : records) {
            Operations.revertAtomic(key, record, timestamp, atomic);
        }
    });
}
Also used : AtomicSupport(com.cinchapi.concourse.server.storage.AtomicSupport) 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)22 VerifyAccessToken (com.cinchapi.concourse.server.aop.VerifyAccessToken)22 VerifyWritePermission (com.cinchapi.concourse.server.aop.VerifyWritePermission)22 AtomicSupport (com.cinchapi.concourse.server.storage.AtomicSupport)22 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)6 TObject (com.cinchapi.concourse.thrift.TObject)6 Multimap (com.google.common.collect.Multimap)3 AbstractSyntaxTree (com.cinchapi.ccl.syntax.AbstractSyntaxTree)2 AtomicOperation (com.cinchapi.concourse.server.storage.AtomicOperation)2 AtomicStateException (com.cinchapi.concourse.server.storage.AtomicStateException)2 TransactionStateException (com.cinchapi.concourse.server.storage.TransactionStateException)2 DuplicateEntryException (com.cinchapi.concourse.thrift.DuplicateEntryException)2 TransactionException (com.cinchapi.concourse.thrift.TransactionException)2 SortableSet (com.cinchapi.concourse.data.sort.SortableSet)1 Set (java.util.Set)1