Search in sources :

Example 1 with BackendTransaction

use of com.torodb.core.backend.BackendTransaction in project torodb by torodb.

the class DefaultConsistencyHandler method loadConsistent.

private void loadConsistent() {
    try (BackendConnection conn = backendService.openConnection();
        BackendTransaction trans = conn.openReadOnlyTransaction()) {
        Optional<KvValue<?>> valueOpt = trans.readMetaInfo(CONSISTENCY_KEY);
        if (!valueOpt.isPresent()) {
            consistent = false;
            return;
        }
        KvValue<?> value = valueOpt.get();
        if (!value.getType().equals(BooleanType.INSTANCE)) {
            throw new IllegalStateException("Unexpected consistency value " + "found. Expected a boolean but " + valueOpt + " was " + "found");
        }
        consistent = ((KvBoolean) value).getPrimitiveValue();
    }
}
Also used : BackendConnection(com.torodb.core.backend.BackendConnection) BackendTransaction(com.torodb.core.backend.BackendTransaction) WriteBackendTransaction(com.torodb.core.backend.WriteBackendTransaction) KvValue(com.torodb.kvdocument.values.KvValue)

Aggregations

BackendConnection (com.torodb.core.backend.BackendConnection)1 BackendTransaction (com.torodb.core.backend.BackendTransaction)1 WriteBackendTransaction (com.torodb.core.backend.WriteBackendTransaction)1 KvValue (com.torodb.kvdocument.values.KvValue)1