Java Code Examples for com.couchbase.client.java.document.JsonDocument#content()

The following examples show how to use com.couchbase.client.java.document.JsonDocument#content() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CouchbaseProcessor.java    From datacollector with Apache License 2.0 6 votes vote down vote up
/**
 * Writes full document lookup values to the record
 *
 * @param record the record being processed
 * @param doc the JsonDocument from Couchbase
 * @return an Observable of the updated record
 */
private Observable<Record> setDocumentInRecord(Record record, JsonDocument doc) {
  if(doc.content() == null) {
    LOG.debug("Document does not exist: {}", doc.id());
    return handleError(record, Errors.COUCHBASE_26, true);
  }

  try {
    record.set(config.outputField, jsonToField(doc.content().toMap()));
    record.getHeader().setAttribute(config.CAS_HEADER_ATTRIBUTE, String.valueOf(doc.cas()));
    return Observable.just(record);
  } catch (IOException e) {
    LOG.debug("Unable to set KV lookup in record for: {}", doc.id());
    return handleError(record, Errors.COUCHBASE_19, e, false);
  }
}
 
Example 2
Source File: CouchbaseCacheDAO.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * Insert a TimeSeriesDataPoint into Couchbase. If a document for this data point already
 * exists within Couchbase and the data value for the metricURN already exists in the cache,
 * we don't do anything. An example document generated and inserted for this might look like:
 * {
 *   "timestamp": 123456700000
 *   "metricId": 123456,
 *   "61427020": "3.0",
 *   "83958352": "59.6",
 *   "98648743": "0.0"
 * }
 * @param point data point
 */
public void insertTimeSeriesDataPoint(TimeSeriesDataPoint point) {

  JsonDocument doc = bucket.getAndTouch(point.getDocumentKey(), CacheConfig.getInstance().getCentralizedCacheSettings().getTTL());
  ThirdeyeMetricsUtil.couchbaseCallCounter.inc();

  if (doc == null) {
    JsonObject documentBody = CacheUtils.buildDocumentStructure(point);
    doc = JsonDocument.create(point.getDocumentKey(), CacheConfig.getInstance().getCentralizedCacheSettings().getTTL(), documentBody);
  } else {
    JsonObject dimensions = doc.content();
    if (dimensions.containsKey(point.getMetricUrnHash())) {
      return;
    }

    dimensions.put(point.getMetricUrnHash(), point.getDataValueAsDouble());
  }

  bucket.upsert(doc);
  ThirdeyeMetricsUtil.couchbaseWriteCounter.inc();
}
 
Example 3
Source File: PersonDocumentConverter.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Person fromDocument(JsonDocument doc) {
    JsonObject content = doc.content();
    Person p = new Person();
    p.setId(doc.id());
    p.setType("Person");
    p.setName(content.getString("name"));
    p.setHomeTown(content.getString("homeTown"));
    return p;
}
 
Example 4
Source File: CodeSnippets.java    From tutorials with MIT License 5 votes vote down vote up
static JsonDocument retrieveAndUpsertExample(Bucket bucket, String id) {
    JsonDocument document = bucket.get(id);
    JsonObject content = document.content();
    content.put("homeTown", "Kansas City");
    JsonDocument upserted = bucket.upsert(document);
    return upserted;
}
 
Example 5
Source File: CodeSnippets.java    From tutorials with MIT License 5 votes vote down vote up
static JsonDocument replaceExample(Bucket bucket, String id) {
    JsonDocument document = bucket.get(id);
    JsonObject content = document.content();
    content.put("homeTown", "Milwaukee");
    JsonDocument replaced = bucket.replace(document);
    return replaced;
}
 
Example 6
Source File: PersonDocumentConverter.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Person fromDocument(JsonDocument doc) {
    JsonObject content = doc.content();
    Person p = new Person();
    p.setId(doc.id());
    p.setType("Person");
    p.setName(content.getString("name"));
    p.setHomeTown(content.getString("homeTown"));
    return p;
}