Search in sources :

Example 1 with DurabilityLevel

use of com.couchbase.client.core.msg.kv.DurabilityLevel in project spring-data-couchbase by spring-projects.

the class CouchbaseTemplateQueryCollectionIntegrationTests method testFluentApi.

@Test
void testFluentApi() {
    User user1 = new User(UUID.randomUUID().toString(), "user1", "user1");
    DurabilityLevel dl = DurabilityLevel.NONE;
    User result;
    RemoveResult rr;
    result = couchbaseTemplate.insertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName).one(user1);
    assertEquals(user1, result);
    result = couchbaseTemplate.upsertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName).one(user1);
    assertEquals(user1, result);
    result = couchbaseTemplate.replaceById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName).one(user1);
    assertEquals(user1, result);
    rr = couchbaseTemplate.removeById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName).one(user1.getId());
    assertEquals(rr.getId(), user1.getId());
    assertEquals(user1, result);
    result = reactiveCouchbaseTemplate.insertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName).one(user1).block();
    assertEquals(user1, result);
    result = reactiveCouchbaseTemplate.upsertById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName).one(user1).block();
    assertEquals(user1, result);
    result = reactiveCouchbaseTemplate.replaceById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName).one(user1).block();
    assertEquals(user1, result);
    rr = reactiveCouchbaseTemplate.removeById(User.class).withDurability(dl).inScope(scopeName).inCollection(collectionName).one(user1.getId()).block();
    assertEquals(rr.getId(), user1.getId());
}
Also used : User(org.springframework.data.couchbase.domain.User) DurabilityLevel(com.couchbase.client.core.msg.kv.DurabilityLevel) Test(org.junit.jupiter.api.Test)

Example 2 with DurabilityLevel

use of com.couchbase.client.core.msg.kv.DurabilityLevel in project kafka-connect-couchbase by couchbase.

the class DurabilitySetter method create.

static DurabilitySetter create(DurabilityConfig config) {
    DurabilityLevel durabilityLevel = config.durability();
    if (durabilityLevel != DurabilityLevel.NONE) {
        if (config.persistTo() != PersistTo.NONE || config.replicateTo() != ReplicateTo.NONE) {
            String durabilityKey = keyName(DurabilityConfig.class, DurabilityConfig::durability);
            String replicateToKey = keyName(DurabilityConfig.class, DurabilityConfig::replicateTo);
            String persistToKey = keyName(DurabilityConfig.class, DurabilityConfig::persistTo);
            throw new ConnectException("Invalid durability config. When '" + durabilityKey + "' is set," + " you must not set '" + replicateToKey + "' or '" + persistToKey + "'.");
        }
        return options -> options.durability(durabilityLevel);
    }
    PersistTo persistTo = config.persistTo();
    ReplicateTo replicateTo = config.replicateTo();
    return options -> options.durability(persistTo, replicateTo);
}
Also used : Consumer(java.util.function.Consumer) DurabilityConfig(com.couchbase.connect.kafka.config.sink.DurabilityConfig) ConfigHelper.keyName(com.couchbase.connect.kafka.util.config.ConfigHelper.keyName) ConnectException(org.apache.kafka.connect.errors.ConnectException) DurabilityLevel(com.couchbase.client.core.msg.kv.DurabilityLevel) PersistTo(com.couchbase.client.java.kv.PersistTo) ReplicateTo(com.couchbase.client.java.kv.ReplicateTo) CommonDurabilityOptions(com.couchbase.client.java.kv.CommonDurabilityOptions) DurabilityConfig(com.couchbase.connect.kafka.config.sink.DurabilityConfig) ReplicateTo(com.couchbase.client.java.kv.ReplicateTo) DurabilityLevel(com.couchbase.client.core.msg.kv.DurabilityLevel) PersistTo(com.couchbase.client.java.kv.PersistTo) ConnectException(org.apache.kafka.connect.errors.ConnectException)

Aggregations

DurabilityLevel (com.couchbase.client.core.msg.kv.DurabilityLevel)2 CommonDurabilityOptions (com.couchbase.client.java.kv.CommonDurabilityOptions)1 PersistTo (com.couchbase.client.java.kv.PersistTo)1 ReplicateTo (com.couchbase.client.java.kv.ReplicateTo)1 DurabilityConfig (com.couchbase.connect.kafka.config.sink.DurabilityConfig)1 ConfigHelper.keyName (com.couchbase.connect.kafka.util.config.ConfigHelper.keyName)1 Consumer (java.util.function.Consumer)1 ConnectException (org.apache.kafka.connect.errors.ConnectException)1 Test (org.junit.jupiter.api.Test)1 User (org.springframework.data.couchbase.domain.User)1