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


Java JsonDocument类代码示例

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


JsonDocument类属于com.couchbase.client.java.document包,在下文中一共展示了JsonDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: appendEvents

import com.couchbase.client.java.document.JsonDocument; //导入依赖的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();
        }

    });
}
 
开发者ID:haxorof,项目名称:axon-couchbase,代码行数:21,代码来源:DocumentPerAggregateStorageStrategy.java

示例2: findDomainEvents

import com.couchbase.client.java.document.JsonDocument; //导入依赖的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;
}
 
开发者ID:haxorof,项目名称:axon-couchbase,代码行数:17,代码来源:DocumentPerAggregateStorageStrategy.java

示例3: loadJson

import com.couchbase.client.java.document.JsonDocument; //导入依赖的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

示例4: toEntity

import com.couchbase.client.java.document.JsonDocument; //导入依赖的package包/类
/**
 * The id in the specified <code>jsonDocument</code> will be set to the returned object if and only if the id is not null or empty and the content in <code>jsonDocument</code> doesn't contain any "id" property, and it's acceptable to the <code>targetClass</code>.
 * 
 * @param targetClass an entity class with getter/setter method or <code>Map.class</code>
 * @param jsonDocument
 * @return
 */
public static <T> T toEntity(final Class<T> targetClass, final JsonDocument jsonDocument) {
    final T result = toEntity(targetClass, jsonDocument.content());
    final String id = jsonDocument.id();

    if (N.notNullOrEmpty(id) && result != null) {
        if (Map.class.isAssignableFrom(targetClass)) {
            ((Map<String, Object>) result).put(_ID, id);
        } else {
            final Method idSetMethod = getObjectIdSetMethod(targetClass);

            if (idSetMethod != null) {
                ClassUtil.setPropValue(result, idSetMethod, id);
            }
        }
    }

    return result;
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:26,代码来源:CouchbaseExecutor.java

示例5: fromJSON

import com.couchbase.client.java.document.JsonDocument; //导入依赖的package包/类
/**
 * Returns an instance of the specified target class with the property values from the specified JSON String.
 * 
 * @param targetClass <code>JsonArray.class</code>, <code>JsonObject.class</code> or <code>JsonDocument.class</code>
 * @param json
 * @return
 */
public static <T> T fromJSON(final Class<T> targetClass, final String json) {
    if (targetClass.equals(JsonObject.class)) {
        return (T) JsonObject.from(N.fromJSON(Map.class, json));
    } else if (targetClass.equals(JsonArray.class)) {
        return (T) JsonArray.from(N.fromJSON(List.class, json));
    } else if (targetClass.equals(JsonDocument.class)) {
        final JsonObject jsonObject = JsonObject.from(N.fromJSON(Map.class, json));
        final String id = N.stringOf(jsonObject.get(_ID));

        jsonObject.removeKey(_ID);

        return (T) JsonDocument.create(id, jsonObject);
    } else {
        throw new IllegalArgumentException("Unsupported type: " + ClassUtil.getCanonicalClassName(targetClass));
    }
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:24,代码来源:CouchbaseExecutor.java

示例6: toJsonDocument

import com.couchbase.client.java.document.JsonDocument; //导入依赖的package包/类
static JsonDocument toJsonDocument(final Object obj, final JsonObject jsonObject) {
    final Class<?> cls = obj.getClass();
    final Method idSetMethod = getObjectIdSetMethod(obj.getClass());
    final String idPropertyName = N.isEntity(cls) ? (idSetMethod == null ? null : ClassUtil.getPropNameByMethod(idSetMethod)) : _ID;

    String id = null;

    if (idPropertyName != null && jsonObject.containsKey(idPropertyName)) {
        id = N.stringOf(jsonObject.get(idPropertyName));

        jsonObject.removeKey(idPropertyName);
    }

    if (N.isNullOrEmpty(id)) {
        throw new IllegalArgumentException("No id property included the specified object: " + N.toString(jsonObject));
    }

    return JsonDocument.create(id, jsonObject);
}
 
开发者ID:landawn,项目名称:AbacusUtil,代码行数:20,代码来源:CouchbaseExecutor.java

示例7: basicJSONtest

import com.couchbase.client.java.document.JsonDocument; //导入依赖的package包/类
@Test
    public void basicJSONtest() {

        JsonObject user = JsonObject.empty()
                .put("firstname", "Walter")
                .put("lastname", "White")
                .put("job", "chemistry teacher")
                .put("age", 50);
        
        assertEquals( "{\"firstname\":\"Walter\",\"job\":\"chemistry teacher\",\"age\":50,\"lastname\":\"White\"}", user.toString());
        
        JsonDocument doc = JsonDocument.create("walter", user);
        
        assertEquals("JsonDocument{id='walter', cas=0, expiry=0, content={\"firstname\":\"Walter\",\"job\":\"chemistry teacher\",\"age\":50,\"lastname\":\"White\"}, mutationToken=null}\n" +
"", doc.toString());

    }
 
开发者ID:weXsol,项目名称:Couchbase,代码行数:18,代码来源:JSonTests.java

示例8: createDocument

import com.couchbase.client.java.document.JsonDocument; //导入依赖的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));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:19,代码来源:CouchbaseSessionStoreTest.java

示例9: saveDocument

import com.couchbase.client.java.document.JsonDocument; //导入依赖的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));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:19,代码来源:CouchbaseSessionStoreTest.java

示例10: createDocumentWithSeconds

import com.couchbase.client.java.document.JsonDocument; //导入依赖的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));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:19,代码来源:CouchbaseSessionStoreTest.java

示例11: createDocumentNoTimeout

import com.couchbase.client.java.document.JsonDocument; //导入依赖的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));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:19,代码来源:CouchbaseSessionStoreTest.java

示例12: handle

import com.couchbase.client.java.document.JsonDocument; //导入依赖的package包/类
@Override
public void handle(RoutingContext rc) {
  Long albumId = PathUtil.parseLongParam(rc.pathParam("albumId"));
  if (albumId == null) {
    rc.next();
    return;
  }

  User user = rc.user();
  if (user == null) {
    rc.response().setStatusCode(HTTP_UNAUTHORIZED).end();
    return;
  }

  String comment = rc.getBodyAsString();
  if (comment == null || comment.isEmpty()) {
    rc.response().setStatusCode(HTTP_BAD_REQUEST).end();
    return;
  }

  long timestamp = System.currentTimeMillis();

  JsonObject content = new JsonObject()
    .put("albumId", albumId)
    .put("username", user.principal().getValue("username"))
    .put("timestamp", timestamp)
    .put("comment", comment);

  JsonDocument document = JsonDocument.create("comment::" + timestamp, com.couchbase.client.java.document.json.JsonObject.from(content.getMap()));
  Vertx vertx = rc.vertx();
  Observable<JsonDocument> documentObservable = albumCommentsBucket.upsert(document);
  RxJavaInterop.toV2Single(documentObservable.toSingle())
    .observeOn(RxHelper.scheduler(vertx.getOrCreateContext()))
    .doOnSuccess(doc -> vertx.setTimer(1000, v -> {
      String address = "album." + albumId + ".comments.new";
      vertx.eventBus().<JsonObject>publish(address, content);
    }))
    .subscribe(doc -> rc.response().end(), rc::fail);
}
 
开发者ID:tsegismont,项目名称:vertx-musicstore,代码行数:40,代码来源:AddAlbumCommentHandler.java

示例13: checkIfDocumentExists

import com.couchbase.client.java.document.JsonDocument; //导入依赖的package包/类
public static boolean checkIfDocumentExists(String coilID, Bucket proteusBucket) {
	JsonDocument checkExists = proteusBucket.get(coilID);
	if (checkExists == null)
		return false;
	else
		return true;
}
 
开发者ID:proteus-h2020,项目名称:proteus-consumer-couchbase,代码行数:8,代码来源:CouchbaseUtils.java

示例14: testRepository

import com.couchbase.client.java.document.JsonDocument; //导入依赖的package包/类
@Test
public void testRepository() throws Exception {
	Developer developer = new Developer();
       DeveloperInfo developerInfo = new DeveloperInfo();
	developer.setId("alovelace");
       developerInfo.setFirstName("Ada");
       developerInfo.setLastName("Lovelace");
	developerInfo.setUsername("alovelace");
       developer.setDeveloperInfo(developerInfo);
	developerRepository.save(developer);

	JsonDocument doc = bucket.get("alovelace");
	Assert.assertNotNull(doc);
}
 
开发者ID:couchbaselabs,项目名称:GitTalent,代码行数:15,代码来源:GittalentBackendApplicationTests.java

示例15: upsert

import com.couchbase.client.java.document.JsonDocument; //导入依赖的package包/类
@Override
public Tt upsert(Tt tt) {
    JsonObject content = JsonObject.fromJson(gson.toJson(tt));
    content.put(DOCTYPE_KEY, DOCTYPE_TT);
    Document<?> document = JsonDocument.create(tt.getId().toString(), content);
    bucket.upsert(document);
    return tt;
}
 
开发者ID:maxcleme,项目名称:f4f-tts,代码行数:9,代码来源:CouchbaseTtsDao.java


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