本文整理汇总了Java中com.couchbase.client.java.Bucket类的典型用法代码示例。如果您正苦于以下问题:Java Bucket类的具体用法?Java Bucket怎么用?Java Bucket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bucket类属于com.couchbase.client.java包,在下文中一共展示了Bucket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: load
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Override
public List<RegisteredService> load() {
try {
logger.debug("Loading services");
final Bucket bucket = couchbase.bucket();
final ViewResult allKeys = bucket.query(ViewQuery.from(UTIL_DOCUMENT, ALL_SERVICES_VIEW.name()));
final List<RegisteredService> services = new LinkedList<>();
for (final ViewRow row : allKeys) {
final RawJsonDocument document = row.document(RawJsonDocument.class);
if (document != null) {
final String json = document.content();
logger.debug("Found service: {}", json);
final StringReader stringReader = new StringReader(json);
services.add(registeredServiceJsonSerializer.fromJson(stringReader));
}
}
return services;
} catch (final RuntimeException e) {
logger.error(e.getMessage(), e);
return new LinkedList<>();
}
}
示例2: appendEvents
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Override
public void appendEvents(Bucket bucket, List<? extends EventMessage<?>> events, Serializer serializer) {
List<JsonObject> jsonObjects = createEventDocuments(events, serializer).collect(Collectors.toList());
jsonObjects.forEach((e) -> {
String docId = EVENT_PREFIX + e.getString("aggregateIdentifier");
if (!bucket.exists(docId)) {
JsonArray eventArray = JsonArray.empty()
.add(e);
JsonObject data = JsonObject.empty()
.put("events", eventArray);
JsonDocument doc = JsonDocument.create(docId, data);
bucket.insert(doc);
} else {
bucket.mutateIn(docId)
.arrayAppend("events", e, false)
.execute();
}
});
}
示例3: findDomainEvents
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Override
public List<? extends DomainEventData<?>> findDomainEvents(Bucket bucket, String aggregateIdentifier, long firstSequenceNumber, int batchSize) {
String docId = EVENT_PREFIX + aggregateIdentifier;
JsonDocument doc = bucket.get(docId);
List<EventEntry> eventEntries = new ArrayList<>();
if (doc != null) {
DocumentFragment<Lookup> fragment = bucket.lookupIn(docId)
.get("events")
.execute();
JsonArray events = fragment.content("events", JsonArray.class);
events.forEach((event) -> {
eventEntries.add(new EventEntry((JsonObject) event));
});
}
return eventEntries;
}
示例4: loadJson
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
public void loadJson(Bucket bucket, String artistId)
{
SpotifyLoaderService loaderService = new SpotifyLoaderServiceImpl();
String jsonU2Artist = loaderService.getArtist(artistId);
JsonObject json = JsonObject.fromJson(jsonU2Artist);
JsonDocument docs = JsonDocument.create("artist", json);
bucket.upsert(docs);
String jsonU2Albums = loaderService.getAlbums(artistId);
json = JsonObject.fromJson(jsonU2Albums);
docs = JsonDocument.create("albums", json);
bucket.upsert(docs);
String jsonU2RelatedArtists = loaderService.getRelatedArtists(artistId);
json = JsonObject.fromJson(jsonU2RelatedArtists);
docs = JsonDocument.create("relArtists", json);
bucket.upsert(docs);
}
示例5: testSimple
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Test
public void testSimple() throws Exception {
CouchbaseCluster cc = couchbase.geCouchbaseCluster();
ClusterManager cm = cc.clusterManager("Administrator","password");
List<BucketSettings> buckets = cm.getBuckets();
Assert.assertNotNull(buckets);
Assert.assertTrue(buckets.size() == 3);
BucketSettings settings = DefaultBucketSettings.builder()
.enableFlush(true).name("default").quota(100).replicas(0).type(BucketType.COUCHBASE).build();
settings = cm.insertBucket(settings);
CouchbaseWaitStrategy s = new CouchbaseWaitStrategy();
s.withBasicCredentials("Administrator", "password");
s.waitUntilReady(couchbase);
Bucket bucket = cc.openBucket("default");
Assert.assertNotNull(bucket);
}
示例6: beerBucketTest
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Test
public void beerBucketTest() throws InterruptedException {
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
.bootstrapCarrierDirectPort(couchbase.getMappedPort(11210))
.bootstrapCarrierSslPort(couchbase.getMappedPort(11207))
.bootstrapHttpDirectPort(couchbase.getMappedPort(8091))
.bootstrapHttpSslPort(couchbase.getMappedPort(18091))
.build();
CouchbaseCluster cc = CouchbaseCluster.create(env);
ClusterManager cm = cc.clusterManager("Administrator", "password");
assertTrue(cm.hasBucket("beer-sample"));
Bucket bucket = cc.openBucket("beer-sample");
assertTrue(bucket.exists("21st_amendment_brewery_cafe"));
bucket.close();
}
示例7: connect
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Override
public void connect(ServerConfiguration serverConfiguration) {
CouchbaseCluster cluster = CouchbaseCluster.create(serverConfiguration.getServerUrl());
String userDatabase = serverConfiguration.getUserDatabase();
Bucket bucket = null;
try {
if (StringUtils.isEmpty(userDatabase)) {
bucket = cluster.openBucket();
} else {
bucket = cluster.openBucket(userDatabase);
}
} catch (Exception ex) {
throw new ConfigurationException(ex);
} finally {
if (bucket != null) {
bucket.close();
}
cluster.disconnect();
}
}
示例8: createDocument
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Test
public void createDocument() throws Exception {
new MockUnit(Bucket.class, Session.class)
.expect(session("sid", 2, 3, 4, "foo", "bar"))
.expect(unit -> {
Bucket bucket = unit.get(Bucket.class);
JsonDocument doc = JsonDocument.create("session::sid", 60, JsonObject.create()
.put("foo", "bar")
.put("_createdAt", 2L)
.put("_accessedAt", 3L)
.put("_savedAt", 4L));
expect(bucket.upsert(doc)).andReturn(doc);
})
.run(unit -> {
new CouchbaseSessionStore(unit.get(Bucket.class), "1m")
.create(unit.get(Session.class));
});
}
示例9: saveDocument
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Test
public void saveDocument() throws Exception {
new MockUnit(Bucket.class, Session.class)
.expect(session("sid", 2, 3, 4, "foo", "bar"))
.expect(unit -> {
Bucket bucket = unit.get(Bucket.class);
JsonDocument doc = JsonDocument.create("session::sid", 60, JsonObject.create()
.put("foo", "bar")
.put("_createdAt", 2L)
.put("_accessedAt", 3L)
.put("_savedAt", 4L));
expect(bucket.upsert(doc)).andReturn(doc);
})
.run(unit -> {
new CouchbaseSessionStore(unit.get(Bucket.class), "1m")
.save(unit.get(Session.class));
});
}
示例10: createDocumentWithSeconds
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Test
public void createDocumentWithSeconds() throws Exception {
new MockUnit(Bucket.class, Session.class)
.expect(session("sid", 2, 3, 4, "foo", "bar"))
.expect(unit -> {
Bucket bucket = unit.get(Bucket.class);
JsonDocument doc = JsonDocument.create("session::sid", 45, JsonObject.create()
.put("foo", "bar")
.put("_createdAt", 2L)
.put("_accessedAt", 3L)
.put("_savedAt", 4L));
expect(bucket.upsert(doc)).andReturn(doc);
})
.run(unit -> {
new CouchbaseSessionStore(unit.get(Bucket.class), "45")
.create(unit.get(Session.class));
});
}
示例11: createDocumentNoTimeout
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Test
public void createDocumentNoTimeout() throws Exception {
new MockUnit(Bucket.class, Session.class)
.expect(session("sid", 2, 3, 4, "foo", "bar"))
.expect(unit -> {
Bucket bucket = unit.get(Bucket.class);
JsonDocument doc = JsonDocument.create("session::sid", 0, JsonObject.create()
.put("foo", "bar")
.put("_createdAt", 2L)
.put("_accessedAt", 3L)
.put("_savedAt", 4L));
expect(bucket.upsert(doc)).andReturn(doc);
})
.run(unit -> {
new CouchbaseSessionStore(unit.get(Bucket.class), -1)
.create(unit.get(Session.class));
});
}
示例12: bucket
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
/**
* Retrieve the Couchbase bucket.
*
* @return the bucket.
*/
public Bucket bucket() {
if (bucket != null) {
return bucket;
}
throw new RuntimeException("Connection to bucket " + bucketName + " not initialized yet.");
}
示例13: bucket
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
/**
* Retrieve the Couchbase bucket.
*
* @return the bucket.
*/
public Bucket bucket() {
if (this.bucket != null) {
return this.bucket;
}
throw new RuntimeException("Connection to bucket " + this.bucketName + " not initialized yet.");
}
示例14: doWork
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Override
public void doWork(int coil, Measurement record, Bucket proteusBucket, ArrayList<String> topicList) {
logger.info("< " + this.getClass().getName() + " > - Flatness for coil " + record.getCoilID() + " inserted");
if (CouchbaseUtils.checkIfDocumentExists(String.valueOf(coil), proteusBucket)) {
CouchbaseUtils.updateDocument(proteusBucket, topicList, record);
} else {
CouchbaseUtils.createDocumentFirstTime(String.valueOf(record.getCoilID()), record, topicList,
proteusBucket);
}
}
示例15: doWork
import com.couchbase.client.java.Bucket; //导入依赖的package包/类
@Override
public void doWork(int coil, Measurement record, Bucket proteusBucket, ArrayList<String> topicList) {
if (CouchbaseUtils.checkIfDocumentExists(String.valueOf(coil), proteusBucket)) {
CouchbaseUtils.updateDocument(proteusBucket, topicList, record);
} else {
CouchbaseUtils.createDocumentFirstTime(String.valueOf(record.getCoilID()), record, topicList,
proteusBucket);
}
}