Search in sources :

Example 11 with GetResult

use of com.couchbase.client.java.kv.GetResult in project spring-data-couchbase by spring-projects.

the class CouchbaseRepositoryKeyValueIntegrationTests method subscriptionToken.

@Test
void subscriptionToken() {
    SubscriptionToken st = new SubscriptionToken("id", 0, "type", "Dave Smith", "app123", "dev123", 0);
    st = subscriptionTokenRepository.save(st);
    st = subscriptionTokenRepository.findById(st.getId()).get();
    GetResult jdkResult = couchbaseTemplate.getCouchbaseClientFactory().getDefaultCollection().get(st.getId());
    assertNotEquals(0, st.getVersion());
    assertEquals(jdkResult.cas(), st.getVersion());
    subscriptionTokenRepository.delete(st);
}
Also used : SubscriptionToken(org.springframework.data.couchbase.domain.SubscriptionToken) GetResult(com.couchbase.client.java.kv.GetResult) Test(org.junit.jupiter.api.Test)

Example 12 with GetResult

use of com.couchbase.client.java.kv.GetResult in project connectors-se by Talend.

the class CouchbaseOutputTest method outputStringDocumentTest.

@Test
@DisplayName("Check String document output")
void outputStringDocumentTest() {
    log.info("Test start: outputStringDocumentTest");
    String idPrefix = "outputStringDocumentTest";
    String docContent = "StringDocumentContent";
    int docCount = 2;
    List<Record> records = new ArrayList<>();
    final Schema.Entry.Builder entryBuilder = recordBuilderFactory.newEntryBuilder();
    for (int i = 0; i < docCount; i++) {
        Record record = recordBuilderFactory.newRecordBuilder().withString(entryBuilder.withName("id").withType(Schema.Type.STRING).build(), generateDocId(idPrefix, i)).withString(entryBuilder.withName("content").withType(Schema.Type.STRING).build(), (docContent + "_" + i).toString()).build();
        records.add(record);
    }
    componentsHandler.setInputData(records);
    CouchbaseOutputConfiguration configuration = getOutputConfiguration();
    configuration.getDataSet().setDocumentType(DocumentType.STRING);
    configuration.setIdFieldName("id");
    executeJob(configuration);
    Collection collection = couchbaseCluster.bucket(BUCKET_NAME).defaultCollection();
    List<GetResult> resultList = new ArrayList<>();
    for (int i = 0; i < docCount; i++) {
        GetResult result = collection.get(generateDocId(idPrefix, i), GetOptions.getOptions().transcoder(RawStringTranscoder.INSTANCE));
        resultList.add(result);
    }
    assertEquals(2, resultList.size());
    for (int i = 0; i < docCount; i++) {
        GetResult getResult = resultList.get(i);
        String content = getResult.contentAs(String.class);
        assertEquals((docContent + "_" + i).toString(), content);
    }
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) ArrayList(java.util.ArrayList) Collection(com.couchbase.client.java.Collection) Record(org.talend.sdk.component.api.record.Record) Test(org.junit.jupiter.api.Test) CouchbaseUtilTest(org.talend.components.couchbase.CouchbaseUtilTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 13 with GetResult

use of com.couchbase.client.java.kv.GetResult in project connectors-se by Talend.

the class BinaryParser method parse.

@Override
public Record parse(Collection collection, String id) {
    GetResult result;
    try {
        result = collection.get(id, GetOptions.getOptions().transcoder(RawBinaryTranscoder.INSTANCE));
    } catch (TimeoutException | CouchbaseException e) {
        LOG.error(e.getMessage());
        throw new ComponentException(e.getMessage());
    }
    byte[] data = result.contentAs(byte[].class);
    final Record.Builder recordBuilder = builderFactory.newRecordBuilder(schemaBinaryDocument);
    recordBuilder.withString("id", id);
    recordBuilder.withBytes("content", data);
    return recordBuilder.build();
}
Also used : CouchbaseException(com.couchbase.client.core.error.CouchbaseException) GetResult(com.couchbase.client.java.kv.GetResult) ComponentException(org.talend.sdk.component.api.exception.ComponentException) Record(org.talend.sdk.component.api.record.Record) TimeoutException(com.couchbase.client.core.deps.io.netty.handler.timeout.TimeoutException)

Example 14 with GetResult

use of com.couchbase.client.java.kv.GetResult in project camel-quarkus by apache.

the class CouchbaseResource method getById.

@GET
@Path("{id}")
@Produces(MediaType.TEXT_PLAIN)
public String getById(@PathParam("id") String id) {
    LOG.infof("Getting object with id : %s", id);
    String endpoint = String.format("%s&operation=%s&queryTimeout=%s", connectionUri, COUCHBASE_GET, timeout);
    GetResult result = producerTemplate.requestBodyAndHeader(endpoint, null, CouchbaseConstants.HEADER_ID, id, GetResult.class);
    return result != null ? result.contentAs(String.class) : null;
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) COUCHBASE_GET(org.apache.camel.component.couchbase.CouchbaseConstants.COUCHBASE_GET)

Example 15 with GetResult

use of com.couchbase.client.java.kv.GetResult in project camel-quarkus by apache.

the class CouchbaseResource method poll.

@GET
@Path("poll")
@Produces(MediaType.TEXT_PLAIN)
public String poll() {
    LOG.infof("polling one document");
    String endpoint = String.format("%s&designDocumentName=%s&viewName=%s&limit=1", connectionUri, bucketName, bucketName);
    GetResult result = consumerTemplate.receiveBody(endpoint, timeout, GetResult.class);
    return result != null ? result.contentAs(String.class) : null;
}
Also used : GetResult(com.couchbase.client.java.kv.GetResult) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) COUCHBASE_GET(org.apache.camel.component.couchbase.CouchbaseConstants.COUCHBASE_GET)

Aggregations

GetResult (com.couchbase.client.java.kv.GetResult)39 Test (org.junit.jupiter.api.Test)25 JavaIntegrationTest (com.couchbase.client.java.util.JavaIntegrationTest)20 JsonObject (com.couchbase.client.java.json.JsonObject)18 IgnoreWhen (com.couchbase.client.test.IgnoreWhen)15 MutationResult (com.couchbase.client.java.kv.MutationResult)11 Collection (com.couchbase.client.java.Collection)7 DocumentNotFoundException (com.couchbase.client.core.error.DocumentNotFoundException)6 Bucket (com.couchbase.client.java.Bucket)5 Cluster (com.couchbase.client.java.Cluster)4 Record (org.talend.sdk.component.api.record.Record)4 CouchbaseException (com.couchbase.client.core.error.CouchbaseException)3 ReplaceBodyWithXattr (com.couchbase.client.java.kv.ReplaceBodyWithXattr)3 CasMismatchException (com.couchbase.client.core.error.CasMismatchException)2 TimeoutException (com.couchbase.client.core.error.TimeoutException)2 JsonArray (com.couchbase.client.java.json.JsonArray)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2