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);
}
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);
}
}
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();
}
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;
}
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;
}
Aggregations