本文整理了Java中com.couchbase.client.java.Bucket.get()
方法的一些代码示例,展示了Bucket.get()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bucket.get()
方法的具体详情如下:
包路径:com.couchbase.client.java.Bucket
类名称:Bucket
方法名:get
[英]Retrieves any type of Document with the default key/value timeout. The document ID is taken out of the Document provided, as well as the target type to return. Note that not the same document is returned, but rather a new one of the same type with the freshly loaded properties. If the document is found, a Document is returned. If the document is not found, the Observable completes without an item emitted. This method throws under the following conditions: - The operation takes longer than the specified timeout: TimeoutException wrapped in a RuntimeException- The producer outpaces the SDK: BackpressureException- The operation had to be cancelled while on the wire or the retry strategy cancelled it instead of retrying: RequestCancelledException- The server is currently not able to process the request, retrying may help: TemporaryFailureException- The server is out of memory: CouchbaseOutOfMemoryException- Unexpected errors are caught and contained in a generic CouchbaseException.
[中]检索具有默认键/值超时的任何类型的文档。文档ID将从提供的文档以及要返回的目标类型中取出。请注意,返回的不是相同的文档,而是具有新加载属性的相同类型的新文档。如果找到文档,则返回文档。如果找不到文档,可观察对象将完成,而不发出项目。此方法在以下条件下引发:-该操作花费的时间超过指定的超时时间:RuntimeException中包装的TimeoutException-生产者的速度超过SDK:BackpressureException-必须在连线时取消该操作,或者重试策略取消了它,而不是重试:RequestCancelleException-服务器当前无法处理请求,重试可能会有帮助:暂时故障异常-服务器内存不足:CouchbaseOutOfMemoryException-捕获意外错误并将其包含在通用CouchbaseException中。
代码示例来源:origin: brianfrankcooper/YCSB
/**
* Performs the {@link #read(String, String, Set, Map)} operation via Key/Value ("get").
*
* @param docId the document ID
* @param fields the fields to be loaded
* @param result the result map where the doc needs to be converted into
* @return The result of the operation.
*/
private Status readKv(final String docId, final Set<String> fields, final Map<String, ByteIterator> result)
throws Exception {
RawJsonDocument loaded = bucket.get(docId, RawJsonDocument.class);
if (loaded == null) {
return Status.NOT_FOUND;
}
decode(loaded.content(), fields, result);
return Status.OK;
}
代码示例来源:origin: org.springframework.data/spring-data-couchbase
@Override
public RawJsonDocument doInBucket() {
if (entity.isTouchOnRead()) {
return client.getAndTouch(id, entity.getExpiry(), RawJsonDocument.class);
} else {
return client.get(id, RawJsonDocument.class);
}
}
});
代码示例来源:origin: apache/nifi
@Override
public <K, V> V get(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException {
final String docId = toDocumentId(key, keySerializer);
final BinaryDocument doc = bucket.get(BinaryDocument.create(docId));
return deserialize(doc, valueDeserializer);
}
代码示例来源:origin: apache/nifi
/**
* A convenient method to retrieve String value when Document type is unknown.
* This method uses LegacyDocument to get, then tries to convert content based on its class.
* @param bucket the bucket to get a document
* @param id the id of the target document
* @return String representation of the stored value, or null if not found
*/
public static String getStringContent(Bucket bucket, String id) {
final LegacyDocument doc = bucket.get(LegacyDocument.create(id));
if (doc == null) {
return null;
}
final Object content = doc.content();
return getStringContent(content);
}
代码示例来源:origin: apache/nifi
.map(key -> bucket.get(key, BinaryDocument.class))
.map(doc -> new ByteBufInputStream(doc.content()));
break;
.map(key -> bucket.get(key, RawJsonDocument.class))
.map(doc -> new ByteArrayInputStream(doc.content().getBytes(StandardCharsets.UTF_8)));
break;
代码示例来源:origin: apache/nifi
@Override
public <K, V> AtomicCacheEntry<K, V, Long> fetch(K key, Serializer<K> keySerializer, Deserializer<V> valueDeserializer) throws IOException {
final String docId = toDocumentId(key, keySerializer);
final BinaryDocument doc = bucket.get(BinaryDocument.create(docId));
if (doc == null) {
return null;
}
final V value = deserialize(doc, valueDeserializer);
return new AtomicCacheEntry<>(key, value, doc.cas());
}
代码示例来源:origin: apache/incubator-gobblin
void verify(Bucket bucket)
throws UnsupportedEncodingException {
// verify
System.out.println("Starting verification procedure");
for (Map.Entry<String, byte[]> cacheEntry : verificationCache.entrySet()) {
Object doc = bucket.get(cacheEntry.getKey(), recordClass);
if (doc instanceof TupleDocument) {
ByteBuf returnedBuf = (((TupleDocument) doc).content()).value1();
byte[] returnedBytes = new byte[returnedBuf.readableBytes()];
returnedBuf.getBytes(0, returnedBytes);
Assert.assertEquals(returnedBytes, cacheEntry.getValue(), "Returned content for TupleDoc should be equal");
} else if (doc instanceof RawJsonDocument) {
byte[] returnedBytes = ((RawJsonDocument) doc).content().getBytes("UTF-8");
Assert.assertEquals(returnedBytes, cacheEntry.getValue(), "Returned content for JsonDoc should be equal");
} else {
Assert.fail("Returned type was neither TupleDocument nor RawJsonDocument");
}
}
System.out.println("Verification success!");
}
}
代码示例来源:origin: apache/incubator-gobblin
/**
* Test that a single Json document can be written successfully
* @throws IOException
* @throws DataConversionException
* @throws ExecutionException
* @throws InterruptedException
*/
@Test(groups={"timeout"})
public void testJsonDocumentWrite()
throws IOException, DataConversionException, ExecutionException, InterruptedException {
CouchbaseWriter writer = new CouchbaseWriter(_couchbaseEnvironment, ConfigFactory.empty());
try {
String key = "hello";
String testContent = "hello world";
HashMap<String, String> contentMap = new HashMap<>();
contentMap.put("value", testContent);
Gson gson = new Gson();
String jsonString = gson.toJson(contentMap);
RawJsonDocument jsonDocument = RawJsonDocument.create(key, jsonString);
writer.write(jsonDocument, null).get();
RawJsonDocument returnDoc = writer.getBucket().get(key, RawJsonDocument.class);
Map<String, String> returnedMap = gson.fromJson(returnDoc.content(), Map.class);
Assert.assertEquals(testContent, returnedMap.get("value"));
} finally {
writer.close();
}
}
代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures
/**
* Retrieves a {@link JsonDocument} by its unique ID.
*
* @param documentId the unique ID of the document
* @return the found {@link JsonDocument} or null if not found
* @see Bucket#get(String)
*/
public JsonDocument get(String documentId) {
return this.bucket.get(documentId);
}
代码示例来源:origin: apache/nifi
RawJsonDocument document = bucket.get(docId, RawJsonDocument.class);
if (document != null) {
outputStreamCallback = out -> {
BinaryDocument document = bucket.get(docId, BinaryDocument.class);
if (document != null) {
outputStreamCallback = out -> {
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void shouldInsertDocument() {
RawJsonDocument expected = RawJsonDocument.create(ID, DOCUMENT);
getBucket().upsert(expected);
RawJsonDocument result = getBucket().get(ID, RawJsonDocument.class);
Assert.assertEquals(expected.content(), result.content());
}
代码示例来源:origin: apache/incubator-gobblin
TupleDocument returnDoc = writer.getBucket().get("hello", TupleDocument.class);
代码示例来源:origin: Impetus/Kundera
@Override
public Object find(Class entityClass, Object key)
{
EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass);
JsonDocument doc;
String id = generateJsonDocId(entityMetadata.getTableName(), key.toString());
doc = bucket.get(id);
LOGGER.debug("Found result for ID : " + key.toString() + " in the " + bucket.name() + " Bucket");
if (doc == null)
{
return null;
}
else
{
MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata()
.getMetamodel(entityMetadata.getPersistenceUnit());
EntityType entityType = metaModel.entity(entityMetadata.getEntityClazz());
return handler.getEntityFromDocument(entityClass, doc.content(), entityType);
}
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public int size() {
//TODO use subdoc GET_COUNT when available
JsonArrayDocument current = bucket.get(id, JsonArrayDocument.class);
return current.content().size();
}
代码示例来源:origin: com.couchbase.client/java-client
@Override
public boolean contains(Object t) {
//TODO subpar implementation for a Set, use ARRAY_CONTAINS when available
enforcePrimitive(t);
JsonArrayDocument current = bucket.get(id, JsonArrayDocument.class);
for (Object in : current.content()) {
if (safeEquals(in, t)) {
return true;
}
}
return false;
}
代码示例来源:origin: ff4j/ff4j
/** {@inheritDoc} */
@Override
public Feature read(String uid) {
assertFeatureExist(uid);
return FEATURE_MAPPER.fromStore(getFeatureBucket().get(uid));
}
代码示例来源:origin: ff4j/ff4j
/** {@inheritDoc} */
@Override
public Property<?> readProperty(String name) {
assertPropertyExist(name);
return PROPERTY_MAPPER.fromStore(getPropertyBucket().get(name));
}
代码示例来源:origin: lordofthejars/nosql-unit
private static void checkEachDocument(final Map<String, Document> expectedDocuments, final List<String> allDocumentIds,
final Bucket bucket) {
for (final String id : allDocumentIds) {
final Object real = bucket.get(id);
final Object expected = toJson(expectedDocuments.get(id).getDocument());
if (!deepEquals(real, expected)) {
throw FailureHandler.createFailure(
"Expected element # %s # is not found but # %s # was found.",
toJson(expected), toJson(real));
}
}
}
代码示例来源:origin: ff4j/ff4j
/** {@inheritDoc} */
@Override
public void disable(String uid) {
assertFeatureExist(uid);
Feature f1 = FEATURE_MAPPER.fromStore(getFeatureBucket().get(uid));
f1.disable();
update(f1);
}
代码示例来源:origin: ff4j/ff4j
/** {@inheritDoc} */
@Override
public void enable(String uid) {
assertFeatureExist(uid);
Feature f1 = FEATURE_MAPPER.fromStore(getFeatureBucket().get(uid));
f1.enable();
update(f1);
}
内容来源于网络,如有侵权,请联系作者删除!