本文整理了Java中com.couchbase.client.java.Bucket.lookupIn()
方法的一些代码示例,展示了Bucket.lookupIn()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket.lookupIn()
方法的具体详情如下:
包路径:com.couchbase.client.java.Bucket
类名称:Bucket
方法名:lookupIn
[英]Prepare a sub-document lookup through a LookupInBuilder. You can use the builder to describe one or several lookup operations inside an existing JsonDocument, then execute the lookup synchronously by calling the LookupInBuilder#execute() method. Only the paths that you looked up inside the document will be transferred over the wire, limiting the network overhead for large documents.
[中]通过LookupInBuilder准备子文档查找。您可以使用构建器描述现有JsonDocument中的一个或多个查找操作,然后通过调用LookupInBuilder#execute()方法同步执行查找。只有在文档中查找的路径将通过网络传输,从而限制了大型文档的网络开销。
代码示例来源:origin: apache/nifi
@Override
public Optional<String> lookup(Map<String, Object> coordinates) throws LookupFailureException {
try {
final Bucket bucket = couchbaseClusterService.openBucket(bucketName);
final Optional<String> docId = Optional.ofNullable(coordinates.get(KEY)).map(Object::toString);
if (!StringUtils.isBlank(subDocPath)) {
return docId.map(key -> {
try {
return bucket.lookupIn(key).get(subDocPath).execute();
} catch (DocumentDoesNotExistException e) {
getLogger().debug("Document was not found for {}", new Object[]{key});
return null;
}
}).map(fragment -> fragment.content(0)).map(Object::toString);
} else {
return docId.map(key -> CouchbaseUtils.getStringContent(bucket, key));
}
} catch (CouchbaseException e) {
throw new LookupFailureException("Failed to lookup from Couchbase using this coordinates: " + coordinates);
}
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public boolean containsKey(Object key) {
return (Boolean) bucket
.lookupIn(id).exists(String.valueOf(key))
.execute()
.content(0);
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public V get(Object key) {
if (key == null) {
throw new NullPointerException("Unsupported null key");
}
try {
return (V) bucket.lookupIn(id)
.get(String.valueOf(key))
.execute()
.content(0);
} catch (PathNotFoundException e) {
return null;
}
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public E get(int index) {
//fail fast on negative values, as they are interpreted as "starting from the back of the array" otherwise
if (index < 0) {
throw new IndexOutOfBoundsException("Index: " + index);
}
String idx = "[" + index + "]";
DocumentFragment<Lookup> result = bucket.lookupIn(id).get(idx).execute();
if (result.status(idx) == ResponseStatus.SUBDOC_PATH_NOT_FOUND) {
throw new IndexOutOfBoundsException("Index: " + index);
}
return (E) result.content(idx);
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public boolean isEmpty() {
DocumentFragment<Lookup> current = bucket.lookupIn(id).exists("[0]").execute();
return current.status("[0]") == ResponseStatus.SUBDOC_PATH_NOT_FOUND;
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public boolean isEmpty() {
DocumentFragment<Lookup> current = bucket.lookupIn(id).exists("[0]").execute();
return current.status(0) == ResponseStatus.SUBDOC_PATH_NOT_FOUND;
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public E peek() {
try {
DocumentFragment<Lookup> current = bucket.lookupIn(id).get("[0]").execute();
Object result = current.content(0);
return (E) result;
} catch (MultiMutationException ex) {
if (ex.firstFailureStatus() == ResponseStatus.SUBDOC_PATH_NOT_FOUND) {
return null; //the queue is empty
}
throw ex;
}
}
}
代码示例来源:origin: couchbase/couchbase-elasticsearch-connector
private JsonNode readDocument(String documentId) throws IOException {
if (xattrs) {
try {
final DocumentFragment<Lookup> lookup = bucket.lookupIn(documentId)
.get(XATTR_NAME, new SubdocOptionsBuilder().xattr(true))
.execute();
final JsonObject content = (JsonObject) lookup.content(0);
return mapper.readTree(content.toString());
} catch (Exception e) {
return null;
}
} else {
RawJsonDocument doc = bucket.get(RawJsonDocument.create(documentId));
if (doc == null) {
return null;
}
return mapper.readTree(doc.content());
}
}
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public V remove(Object key) {
if (key == null) {
throw new NullPointerException("Unsupported null key");
}
String idx = String.valueOf(key);
for(int i = 0; i < MAX_OPTIMISTIC_LOCKING_ATTEMPTS; i++) {
try {
DocumentFragment<Lookup> current = bucket.lookupIn(id).get(idx).execute();
long returnCas = current.cas();
Object result = current.content(idx);
DocumentFragment<Mutation> updated = bucket.mutateIn(id).remove(idx).withCas(returnCas).execute();
return (V) result;
} catch (CASMismatchException ex) {
//will have to retry get-and-remove
} catch (MultiMutationException ex) {
if (ex.firstFailureStatus() == ResponseStatus.SUBDOC_PATH_NOT_FOUND) {
return null;
}
throw ex;
}
}
throw new ConcurrentModificationException("Couldn't perform remove in less than " + MAX_OPTIMISTIC_LOCKING_ATTEMPTS + " iterations");
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public E remove(int index) {
//fail fast on negative values, as they are interpreted as "starting from the back of the array" otherwise
if (index < 0) {
throw new IndexOutOfBoundsException("Index: " + index);
}
String idx = "[" + index + "]";
for(int i = 0; i < MAX_OPTIMISTIC_LOCKING_ATTEMPTS; i++) {
try {
DocumentFragment<Lookup> current = bucket.lookupIn(id).get(idx).execute();
long returnCas = current.cas();
Object result = current.content(idx);
DocumentFragment<Mutation> updated = bucket.mutateIn(id).remove(idx).withCas(returnCas).execute();
return (E) result;
} catch (CASMismatchException ex) {
//will have to retry get-and-remove
} catch (MultiMutationException ex) {
if (ex.firstFailureStatus() == ResponseStatus.SUBDOC_PATH_NOT_FOUND) {
throw new IndexOutOfBoundsException("Index: " + index);
}
throw ex;
}
}
throw new ConcurrentModificationException("Couldn't perform remove in less than " + MAX_OPTIMISTIC_LOCKING_ATTEMPTS + " iterations");
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public E set(int index, E element) {
//fail fast on negative values, as they are interpreted as "starting from the back of the array" otherwise
if (index < 0) {
throw new IndexOutOfBoundsException("Index: " + index);
}
if (!JsonValue.checkType(element)) {
throw new IllegalArgumentException("Unsupported value type.");
}
String idx = "["+index+"]";
for(int i = 0; i < MAX_OPTIMISTIC_LOCKING_ATTEMPTS; i++) {
try {
DocumentFragment<Lookup> current = bucket.lookupIn(id).get(idx).execute();
long returnCas = current.cas();
Object result = current.content(idx);
bucket.mutateIn(id).replace(idx, element).withCas(returnCas).execute();
return (E) result;
} catch (CASMismatchException ex) {
//will need to retry get-and-set
} catch (MultiMutationException ex) {
if (ex.firstFailureStatus() == ResponseStatus.SUBDOC_PATH_NOT_FOUND
|| ex.firstFailureStatus() == ResponseStatus.SUBDOC_PATH_INVALID) {
throw new IndexOutOfBoundsException("Index: " + index);
}
throw ex;
}
}
throw new ConcurrentModificationException("Couldn't perform set in less than " + MAX_OPTIMISTIC_LOCKING_ATTEMPTS + " iterations");
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public V put(String key, V value) {
if (key == null) {
throw new NullPointerException("Unsupported null key");
}
if (!JsonValue.checkType(value)) {
throw new IllegalArgumentException("Unsupported value type.");
}
for(int i = 0; i < MAX_OPTIMISTIC_LOCKING_ATTEMPTS; i++) {
try {
DocumentFragment<Lookup> current = bucket.lookupIn(id).get(key).execute();
long returnCas = current.cas();
Object result = null;
if (current.exists(key)) {
result = current.content(key);
}
bucket.mutateIn(id).upsert(key, value, false).withCas(returnCas).execute();
return (V) result;
} catch (CASMismatchException ex) {
//will need to retry get-and-set
}
}
throw new ConcurrentModificationException("Couldn't perform put in less than " + MAX_OPTIMISTIC_LOCKING_ATTEMPTS + " iterations");
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public E poll() {
String idx = "[-1]"; //FIFO queue as offer uses ARRAY_PREPEND
for(int i = 0; i < MAX_OPTIMISTIC_LOCKING_ATTEMPTS; i++) {
try {
DocumentFragment<Lookup> current = bucket.lookupIn(id).get(idx).execute();
long returnCas = current.cas();
Object result = current.content(idx);
DocumentFragment<Mutation> updated = bucket.mutateIn(id).remove(idx).withCas(returnCas).execute();
return (E) result;
} catch (CASMismatchException ex) {
//will have to retry get-and-remove
} catch (MultiMutationException ex) {
if (ex.firstFailureStatus() == ResponseStatus.SUBDOC_PATH_NOT_FOUND) {
return null; //the queue is empty
}
throw ex;
}
}
throw new ConcurrentModificationException("Couldn't perform poll in less than " + MAX_OPTIMISTIC_LOCKING_ATTEMPTS + " iterations");
}
内容来源于网络,如有侵权,请联系作者删除!