本文整理汇总了Java中com.couchbase.client.java.Cluster.openBucket方法的典型用法代码示例。如果您正苦于以下问题:Java Cluster.openBucket方法的具体用法?Java Cluster.openBucket怎么用?Java Cluster.openBucket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.couchbase.client.java.Cluster
的用法示例。
在下文中一共展示了Cluster.openBucket方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: CouchbaseTtsDao
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
@Inject
CouchbaseTtsDao(Cluster cluster) {
bucket = cluster.openBucket(TTS_BUCKET_NAME);
// Clear all designs docs
bucket.bucketManager().getDesignDocuments().forEach(designDocument -> bucket.bucketManager().removeDesignDocument(designDocument.name()));
// Insert designs docs
designDocuments().forEach(designDocument -> bucket.bucketManager().insertDesignDocument(designDocument));
}
示例2: loadJSONDocumentsTest
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
@Test
public void loadJSONDocumentsTest()
{
System.out.println("starting db...");
Cluster cluster = CouchbaseCluster.create();
System.out.println("creted db...");
System.out.println("opening bucket...");
Bucket defaultBucket = cluster.openBucket("default");
System.out.println("opened bucket...");
SpotifyCouchbaseLoader loader = new SpotifyCouchbaseLoader();
String u2ArtistId = "51Blml2LZPmy7TTiAg47vQ";
loader.loadJson(defaultBucket, u2ArtistId);
//Get JSON Document "albums"
JsonDocument jsonDocument = defaultBucket.get("albums");
cluster.disconnect();
//Check if JSON Document "albums" is loaded
Assert.assertNotNull(jsonDocument);
Object items = jsonDocument.content().get("items");
Assert.assertNotNull(items);
}
示例3: bucket
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
@Bean(destroyMethod = "close")
@Autowired
Bucket bucket(
final Cluster cluster,
@Value("${database.bucket.name:default}") final String name,
@Value("${database.bucket.password:}") final String password) {
return cluster.openBucket(name, password);
}
示例4: loadRecords
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
public CouchbaseResult loadRecords(ServerConfiguration configuration, CouchbaseDatabase database, CouchbaseQuery couchbaseQuery) {
Cluster cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment
.builder()
.queryEnabled(true)
.build(),
configuration.getServerUrl());
// AuthenticationSettings authenticationSettings = configuration.getAuthenticationSettings();
// ClusterManager clusterManager = cluster.clusterManager(authenticationSettings.getUsername(), authenticationSettings.getPassword());
Bucket beerBucket = cluster.openBucket(database.getName(), 10, TimeUnit.SECONDS);
N1qlQueryResult queryResult = beerBucket.query(N1qlQuery.simple(select("*").from(i(database.getName())).limit(couchbaseQuery.getLimit())));
//TODO dirty zone :(
CouchbaseResult result = new CouchbaseResult(database.getName());
List<JsonObject> errors = queryResult.errors();
if (!errors.isEmpty()) {
cluster.disconnect();
result.addErrors(errors);
return result;
}
for (N1qlQueryRow row : queryResult.allRows()) {
result.add(row.value());
}
cluster.disconnect();
return result;
}
示例5: main
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
public static void main(String[] args) {
Cluster cluster = CouchbaseCluster.create(DefaultCouchbaseEnvironment
.builder()
.queryEnabled(true)
.build());
Bucket defaultBucket = cluster.openBucket("default");
defaultBucket.remove("user:walter");
JsonArray friends = JsonArray.empty()
.add(JsonObject.empty().put("name", "Mike Ehrmantraut"))
.add(JsonObject.empty().put("name", "Jesse Pinkman"));
JsonObject content = JsonObject.empty()
.put("firstname", "Walter")
.put("lastname", "White")
.put("age", 52)
.put("aliases", JsonArray.from("Walt Jackson", "Mr. Mayhew", "David Lynn"))
.put("friends", friends);
JsonDocument walter = JsonDocument.create("user:walter", content);
JsonDocument inserted = defaultBucket.insert(walter);
JsonDocument foundGuy = defaultBucket.get("user:walter");
System.out.println(foundGuy.content().toMap());
Bucket beerBucket = cluster.openBucket("beer-sample");
N1qlQueryResult result = beerBucket.query(N1qlQuery.simple(select("*").from(i("beer-sample")).limit(10)));
System.out.println("Errors found: " + result.errors());
for (N1qlQueryRow row : result.allRows()) {
JsonObject jsonObject = row.value();
System.out.println(jsonObject.toMap());
}
cluster.disconnect();
}
示例6: test
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
@Test
public void test() throws IOException {
System.out.println("Starting DB...");
Cluster cluster = CouchbaseCluster.create();
System.out.println("Created DB");
System.out.println("Opening bucket...");
Bucket bucket = cluster.openBucket("default");
System.out.println("Opened bucket");
int docs = 0;
String artistId = "51Blml2LZPmy7TTiAg47vQ";
String albumsUrl = "https://api.spotify.com/v1/artists/" + artistId + "/albums";
System.out.println("Getting the artist's albums...");
String albumsJson = this.getRequest(albumsUrl);
System.out.println("Got the artist's albums...");
docs++;
JsonObject albumsObject = JsonObject.fromJson(albumsJson);
String albumsId = albumsObject.getString("id");
albumsId = albumsId == null ? "albums" + artistId : albumsId;
JsonDocument albumsDocument = JsonDocument.create(albumsId, albumsObject);
bucket.upsert(albumsDocument);
JsonArray albums = albumsObject.getArray("items");
for (Object albumObj : albums) {
JsonObject item = (JsonObject) albumObj;
String itemHref = item.getString("href");
System.out.println("Getting the album...");
String albumJson = this.getRequest(itemHref);
System.out.println("Got the album...");
docs++;
JsonObject albumObject = JsonObject.fromJson(albumJson);
String albumId = albumObject.getString("id");
JsonDocument albumDocument = JsonDocument.create(albumId, albumObject);
bucket.upsert(albumDocument);
JsonArray tracks = albumObject.getObject("tracks").getArray("items");
for (Object trackObj : tracks) {
JsonObject track = (JsonObject) trackObj;
String trackHref = track.getString("href");
System.out.println("Getting the track...");
String trackJson = this.getRequest(trackHref);
System.out.println("Got the track...");
docs++;
JsonObject trackObject = JsonObject.fromJson(trackJson);
String trackId = trackObject.getString("id");
JsonDocument trackDocument = JsonDocument.create(trackId, trackObject);
bucket.upsert(trackDocument);
}
}
System.out.println("Total documents " + docs);
}
示例7: shouldTraceChangesOnCouchbase
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
@Test
public void shouldTraceChangesOnCouchbase() {
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder().dcpEnabled(true).build();
Cluster cluster = CouchbaseCluster.create(env);
CouchbaseEventDispatcher couchbaseEventHandler = new CouchbaseEventDispatcher(cluster.core(), "default",
Arrays.asList("127.0.0.1"), "", new CouchbaseEventHandler());
couchbaseEventHandler.start();
Bucket defaultBucket = cluster.openBucket();
JsonObject user = JsonObject.empty().put("firstname", "Lorenzo").put("lastname", "Speranzoni")
.put("job", "CEO @ LARUS Business Automation").put("age", 41);
JsonDocument doc = JsonDocument.create("inserpio", user);
JsonDocument response = defaultBucket.upsert(doc);
System.out.println(response);
cluster.disconnect();
}
示例8: testConnection
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
private static void testConnection(Cluster cluster) {
Bucket bucket = cluster.openBucket(2, TimeUnit.SECONDS);
bucket.close();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:5,代码来源:CouchbaseTestServer.java
示例9: CouchbaseExecutor
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
public CouchbaseExecutor(Cluster cluster) {
this(cluster, cluster.openBucket());
}
示例10: getBucket
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
private Bucket getBucket() {
final Cluster connection = getConnection();
return connection.openBucket(BUCKET);
}
示例11: sendJSONDocumentsToCouchbase
import com.couchbase.client.java.Cluster; //导入方法依赖的package包/类
/**
*
* @param jsonDocuments
*/
public void sendJSONDocumentsToCouchbase(List<JsonDocument> jsonDocuments) {
Cluster cluster = CouchbaseCluster.create();
Bucket defaultBucket = cluster.openBucket();
for (JsonDocument jsonDocument : jsonDocuments) {
defaultBucket.upsert(jsonDocument);
}
cluster.disconnect();
}