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


Java JsonObject类代码示例

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


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

示例1: get

import com.couchbase.client.java.document.json.JsonObject; //导入依赖的package包/类
public Cart get(String cartId) {
	
	N1qlParams params = N1qlParams.build().adhoc(false).consistency(ScanConsistency.STATEMENT_PLUS);
   	JsonObject values = JsonObject.create().put("id", cartId);
   	N1qlQuery query = N1qlQuery.parameterized("select "+ cartBucketName + ".* from `" + cartBucketName + "` where docType='"+ DocTypes.CartAggregateView.name() +"' and id=$id", values, params);
   	
	List<Cart> carts = db.getBucket().async().query(query)
        .flatMap(AsyncN1qlQueryResult::rows)
        .map(result -> {
		return createObject(result.value().toString());
	  })
        .toList()
        .timeout(10, TimeUnit.SECONDS)
        .toBlocking()
        .single();
	
	if(carts.isEmpty()) {
		return null;
	} else {
		return carts.get(0);
	}
}
 
开发者ID:ERS-HCL,项目名称:cart-cqrs-demo,代码行数:23,代码来源:CartStore.java

示例2: getCartEvents

import com.couchbase.client.java.document.json.JsonObject; //导入依赖的package包/类
public List<Event> getCartEvents(String cartId, long snapshotEventSequenceNumber) {
	
	N1qlParams params = N1qlParams.build().adhoc(false).consistency(ScanConsistency.STATEMENT_PLUS);
   	JsonObject values = JsonObject.create().put("cartId", cartId)
   						.put("snapshotEventNumber", snapshotEventSequenceNumber);
   	
   	N1qlQuery query = N1qlQuery.parameterized("select "+ eventBucketName +".* from `"+ eventBucketName +"` where docType='CartEvent' and cartId=$cartId and eventNumber > $snapshotEventNumber order by eventNumber", values, params);
   	
	List<Event> events = db.getBucket().async().query(query)
        .flatMap(AsyncN1qlQueryResult::rows)
        .map(result -> {
		return createEvent(result.value().toString());
	  })
        .toList()
        .timeout(10, TimeUnit.SECONDS)
        .toBlocking()
        .single();
	 
	return events;
	
}
 
开发者ID:ERS-HCL,项目名称:cart-cqrs-demo,代码行数:22,代码来源:EventStore.java

示例3: get

import com.couchbase.client.java.document.json.JsonObject; //导入依赖的package包/类
public Cart get(String cartId) {
	
	N1qlParams params = N1qlParams.build().adhoc(false).consistency(ScanConsistency.STATEMENT_PLUS);
   	JsonObject values = JsonObject.create().put("id", cartId);
   	N1qlQuery query = N1qlQuery.parameterized("select "+ cartBucketName + ".* from `" + cartBucketName + "` where docType='" + DocTypes.CartQueryView.name()+ "' and id=$id", values, params);
   	
	List<Cart> carts = db.getBucket().async().query(query)
        .flatMap(AsyncN1qlQueryResult::rows)
        .map(result -> {
		return createObject(result.value().toString());
	  })
        .toList()
        .timeout(10, TimeUnit.SECONDS)
        .toBlocking()
        .single();
	
	if(carts.isEmpty()) {
		return null;
	} else {
		return carts.get(0);
	}
}
 
开发者ID:ERS-HCL,项目名称:cart-cqrs-demo,代码行数:23,代码来源:CartStore.java

示例4: removeContact

import com.couchbase.client.java.document.json.JsonObject; //导入依赖的package包/类
@ResponseBody
@RequestMapping(method = RequestMethod.PUT, path = "/developer/removeContact/{developerId}")
public String removeContact(final @PathVariable String developerId, final @RequestBody String json) throws Exception {
    JsonObject jsonData = JsonObject.fromJson(json);
    String contactId = jsonData.getString("contactId");

    DocumentFragment<Lookup> fragment = bucket.lookupIn(developerId).get("contacts").execute();
    JsonArray contactList = fragment.content("contacts", JsonArray.class);
    List tempList = contactList.toList();
    tempList.remove(contactId);
    contactList = JsonArray.from(tempList);
    bucket.mutateIn(developerId)
            .replace("contacts", contactList).execute();

    fragment = bucket.lookupIn(contactId).get("contacts").execute();
    contactList = fragment.content("contacts", JsonArray.class);
    tempList = contactList.toList();
    tempList.remove(developerId);
    contactList = JsonArray.from(tempList);
    bucket.mutateIn(contactId)
            .replace("contacts", contactList).execute();

    return "{}";
}
 
开发者ID:couchbaselabs,项目名称:GitTalent,代码行数:25,代码来源:IndexController.java

示例5: searchDevelopers

import com.couchbase.client.java.document.json.JsonObject; //导入依赖的package包/类
@ResponseBody
@RequestMapping("/developer/search")
public String searchDevelopers(final @RequestParam("firstname") String firstName, final @RequestParam("lastname") String lastName) throws Exception {
    String statement = "SELECT developer.* FROM `" + bucket.name() + "` AS developer WHERE developer.type = 'developer'";
    JsonObject params = JsonObject.create();
    if (!firstName.equals("")) {
        params.put("firstName", firstName.toLowerCase() + "%");
        statement += " AND lower(developer.developerInfo.firstName) LIKE $firstName";
    }
    if (!lastName.equals("")) {
        params.put("lastName", lastName.toLowerCase() + "%");
        statement += " AND lower(developer.developerInfo.lastName) LIKE $lastName";
    }
    N1qlQuery developerByEmail = N1qlQuery.parameterized(statement, params);
    return rawQueryExecutor.n1qlToRawJson(developerByEmail);
}
 
开发者ID:couchbaselabs,项目名称:GitTalent,代码行数:17,代码来源:IndexController.java

示例6: check

import com.couchbase.client.java.document.json.JsonObject; //导入依赖的package包/类
@Override
protected Result check() throws Exception {
    log.info("Running health check for couch base");
    final JsonArray nodes = couchbaseClient.getNodes();
    final List<String> healthyNodes = new ArrayList<>();
    final List<String> unhealthyNodes = new ArrayList<>();
    nodes.forEach(node -> {
        final JsonObject obj = (JsonObject) node;
        final boolean isNodeHealthy = "healthy".equals(obj.get("status"));
        if (isNodeHealthy) {
            healthyNodes.add(obj.getString("hostname"));
        } else {
            unhealthyNodes.add(obj.getString("hostname"));
        }
    });

    // isHealthy is derived to be true when 50% or more nodes are healthy.
    final boolean isHealthy = healthyNodes.size() >= (minimumHealthyNodes != null ? minimumHealthyNodes : unhealthyNodes.size());

    return isHealthy ? Result.healthy("Connected to Couchbase cluster. Healthy Nodes : " + healthyNodes)
            : Result.unhealthy("Not Connected to Couchbase cluster. Healthy Nodes: " + healthyNodes + ". Unhealthy Nodes: " + unhealthyNodes);
}
 
开发者ID:saarthakgupta,项目名称:couchbase-healthcheck,代码行数:23,代码来源:CouchBaseHealthCheck.java

示例7: appendEvents

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

示例8: findDomainEvents

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

示例9: EventEntry

import com.couchbase.client.java.document.json.JsonObject; //导入依赖的package包/类
/**
 * Constructor used to create a new event entry to store in Mongo.
 *
 * @param event The actual DomainEvent to store
 * @param serializer Serializer to use for the event to store
 */
EventEntry(DomainEventMessage<?> event, Serializer serializer) {
    this.aggregateType = event.getType();
    this.aggregateIdentifier = event.getAggregateIdentifier();
    this.sequenceNumber = event.getSequenceNumber();
    this.eventIdentifier = event.getIdentifier();
    Class<?> serializationTarget = String.class;
    if (serializer.canSerializeTo(JsonObject.class)) {
        serializationTarget = JsonObject.class;
    }
    SerializedObject<?> serializedPayloadObject = serializePayload(event, serializer, serializationTarget);
    SerializedObject<?> serializedMetaDataObject = serializeMetaData(event, serializer, serializationTarget);

    this.serializedPayload = serializedPayloadObject.getData();
    this.payloadType = serializedPayloadObject.getType().getName();
    this.payloadRevision = serializedPayloadObject.getType().getRevision();
    this.serializedMetaData = serializedMetaDataObject.getData();
    this.timeStamp = event.getTimestamp().toString();
}
 
开发者ID:haxorof,项目名称:axon-couchbase,代码行数:25,代码来源:EventEntry.java

示例10: loadJson

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

示例11: fromJSON

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

示例12: toJsonDocument

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

示例13: insereDocumento

import com.couchbase.client.java.document.json.JsonObject; //导入依赖的package包/类
private void insereDocumento(String[] linha) {
    JsonObject doc = JsonObject.empty()
            .put("date", linha[0])
            .put("time", linha[1])
            .put("s1", linha[2])
            .put("s2", linha[3])
            .put("s3", linha[4])
            .put("s4", linha[5])
            .put("s5", linha[6])
            .put("s6", linha[7])
            .put("s7", linha[8])
            .put("s8", linha[9])
            .put("s9", linha[10])
            .put("s10", linha[11])
            .put("s11", linha[12])
            .put("s12", linha[13])
            .put("s13", linha[14]);
    documentos.add(doc);
}
 
开发者ID:allexandresampaio,项目名称:inobench,代码行数:20,代码来源:CSVReaderToJSon.java

示例14: TestarInsercao

import com.couchbase.client.java.document.json.JsonObject; //导入依赖的package包/类
public void TestarInsercao() throws InterruptedException {
    int i = 0;
    for (int x = 0; x < qtdTransacoes; x++) {
        JsonObject documento = documentos.get(i);
        if (documento.containsKey("_id")) documento.removeKey("_id");
        
        try {
            fachada.insert(documento);
        } catch (Exception e) {
            Errors.getInstancia().marcaErro();
            System.out.println(e);
        }
        
        System.out.println("Thread: " + this.nome + ". Inserindo: " + x);
        //verifica se i chegou no fim da amostra
        if (i < documentos.size()-1) {
            i++;
        } else {
            i = 0;
        }
    }
}
 
开发者ID:allexandresampaio,项目名称:inobench,代码行数:23,代码来源:CouchbaseInsertThread.java

示例15: basicJSONtest

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


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