当前位置: 首页>>代码示例>>Java>>正文


Java Bucket.upsert方法代码示例

本文整理汇总了Java中com.couchbase.client.java.Bucket.upsert方法的典型用法代码示例。如果您正苦于以下问题:Java Bucket.upsert方法的具体用法?Java Bucket.upsert怎么用?Java Bucket.upsert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.couchbase.client.java.Bucket的用法示例。


在下文中一共展示了Bucket.upsert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
}
 
开发者ID:larusba,项目名称:neo4j-couchbase-connector,代码行数:23,代码来源:SpotifyCouchbaseLoader.java

示例2: main

import com.couchbase.client.java.Bucket; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
    CouchbaseCluster cluster = CouchbaseCluster.create("127.0.0.1");
    Bucket bucket = cluster.openBucket("default");

    while (true) {
        for (int i = 0; i < 1024; i++) {
            bucket.upsert(JsonDocument.create("doc:" + i, JsonObject.create().put("uuid", UUID.randomUUID().toString())));
            Thread.sleep(1000);
        }
    }
}
 
开发者ID:couchbase,项目名称:java-dcp-client,代码行数:12,代码来源:WorkloadGenerator.java

示例3: populateBucket

import com.couchbase.client.java.Bucket; //导入方法依赖的package包/类
private void populateBucket() {
    CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
            .socketConnectTimeout(60000)
            .connectTimeout(60000)
            .keepAliveInterval(60000)
            .build();
    CouchbaseCluster cluster = CouchbaseCluster.create(env, bootstrapNodes);
    Bucket bucket = cluster.openBucket(bucketName, password);
    assertTrue(bucket.bucketManager().flush());
    JsonDocument document = JsonDocument.create("foo", JsonObject.create().put("bar", 42));
    bucket.upsert(document, PersistTo.MASTER);
    bucket.close();

    cluster.disconnect();
}
 
开发者ID:Talend,项目名称:components,代码行数:16,代码来源:CouchbaseInputTestIT.java

示例4: createDocumentFirstTime

import com.couchbase.client.java.Bucket; //导入方法依赖的package包/类
public static void createDocumentFirstTime(String coilID, Measurement record, ArrayList<String> topicList,
		Bucket proteusBucket) {
	List<JsonObject> proteusRealtime = new ArrayList<>();
	List<JsonObject> proteusHSM = new ArrayList<>();
	List<JsonObject> proteusFlatness = new ArrayList<>();

	JsonObject row1d = JsonObject.create();
	JsonObject row2d = JsonObject.create();
	JsonObject hsm = JsonObject.create();

	if (record.getType() == 0x00) {
		row1d = JsonObject.empty().put("position-x", record.getPositionX()).put("value", record.getValue())
				.put("var", record.getVarName());

	}

	if (record.getType() == 0x01) {
		row2d = JsonObject.empty().put("position-x", record.getPositionX()).put("position-y", record.getPositionY())
				.put("value", record.getValue()).put("var", record.getVarName());
	}

	if (record.getClass().equals(HSMMeasurement.class)) {

		hsm = JsonObject.empty().put("variables-counter", record.getHSMVarCounter()).put("variables",
				record.getHSMVariables());

	}

	try {

		if (getKafkaTopic(topicList).equals("proteus-realtime")) {
			if (!row1d.isEmpty())
				proteusRealtime.add(row1d);
			if (!row2d.isEmpty())
				proteusRealtime.add(row2d);
		}
		if (getKafkaTopic(topicList).equals("proteus-hsm")) {
			if (!hsm.isEmpty())
				proteusHSM.add(hsm);
		}
		if (getKafkaTopic(topicList).equals("proteus-flatness")) {
			if (!row1d.isEmpty())
				proteusRealtime.add(row1d);
			if (!row2d.isEmpty())
				proteusRealtime.add(row2d);
		}
	} catch (NullPointerException e) {
		System.out.println(e);
	}

	JsonObject structureProteusDocument = JsonObject.empty().put("coilID", coilID)
			.put("proteus-realtime", proteusRealtime).put("proteus-flatness", proteusFlatness)
			.put("proteus-hsm", proteusHSM);
	JsonDocument doc = JsonDocument.create(coilID, structureProteusDocument);
	proteusBucket.upsert(doc);

}
 
开发者ID:proteus-h2020,项目名称:proteus-consumer-couchbase,代码行数:58,代码来源:CouchbaseUtils.java

示例5: test

import com.couchbase.client.java.Bucket; //导入方法依赖的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);
}
 
开发者ID:larusba,项目名称:neo4j-couchbase-connector,代码行数:50,代码来源:SpotifyRecursiveLoaderTest.java

示例6: shouldTraceChangesOnCouchbase

import com.couchbase.client.java.Bucket; //导入方法依赖的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();
}
 
开发者ID:larusba,项目名称:neo4j-couchbase-connector,代码行数:26,代码来源:CouchbaseEventHandlerTest.java

示例7: sendJSONDocumentsToCouchbase

import com.couchbase.client.java.Bucket; //导入方法依赖的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();
}
 
开发者ID:larusba,项目名称:neo4j-couchbase-connector,代码行数:18,代码来源:Neo4jEventListener.java


注:本文中的com.couchbase.client.java.Bucket.upsert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。