com.couchbase.client.java.document.json.JsonObject.create()方法的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(9.6k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中com.couchbase.client.java.document.json.JsonObject.create()方法的一些代码示例,展示了JsonObject.create()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonObject.create()方法的具体详情如下:
包路径:com.couchbase.client.java.document.json.JsonObject
类名称:JsonObject
方法名:create

JsonObject.create介绍

[英]Creates a empty JsonObject.
[中]创建一个空的JsonObject。

代码示例

代码示例来源:origin: brianfrankcooper/YCSB

/**
 * Helper method to turn the map of values into a {@link JsonObject} for further use.
 *
 * @param values the values to transform.
 * @return the created json object.
 */
private static JsonObject valuesToJsonObject(final Map<String, ByteIterator> values) {
 JsonObject result = JsonObject.create();
 for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
  result.put(entry.getKey(), entry.getValue().toString());
 }
 return result;
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

/**
 * Executes a N1QL kernelTransaction with named parameters.
 *
 * @param statement       the raw kernelTransaction string to execute (containing named
 *                        placeholders: $param1, $param2, ...)
 * @param parameterNames  the placeholders' names in kernelTransaction
 * @param parameterValues the values for the named placeholders in kernelTransaction
 * @return the list of {@link JsonObject}s retrieved by this query
 * @see N1qlQuery#parameterized(Statement, JsonObject)
 */
public List<JsonObject> executeParametrizedStatement(String statement, List<String> parameterNames,
                           List<Object> parameterValues) {
  JsonObject namedParams = JsonObject.create();
  for (int param = 0; param < parameterNames.size(); param++) {
    namedParams.put(parameterNames.get(param), parameterValues.get(param));
  }
  ParameterizedN1qlQuery query = N1qlQuery.parameterized(statement, namedParams);
  return executeQuery(query);
}

代码示例来源:origin: Impetus/Kundera

/**
 * Iterate and populate json object.
 *
 * @param entity
 *            the entity
 * @param iterator
 *            the iterator
 * @return the json object
 */
private JsonObject iterateAndPopulateJsonObject(Object entity, Iterator<Attribute> iterator, String tableName)
{
  JsonObject obj = JsonObject.create();
  while (iterator.hasNext())
  {
    Attribute attribute = iterator.next();
    Field field = (Field) attribute.getJavaMember();
    Object value = PropertyAccessorHelper.getObject(entity, field);
    obj.put(((AbstractAttribute) attribute).getJPAColumnName(), value);
  }
  obj.put(CouchbaseConstants.KUNDERA_ENTITY, tableName);
  return obj;
}

代码示例来源:origin: com.couchbase.client/java-client

/**
 * Static factory method to create an empty {@link JsonObject}.
 *
 * @return an empty {@link JsonObject}.
 */
public static JsonObject jo() {
  return JsonObject.create();
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

@Test
public void testInsertAndRemoveDocument() {
  PasswordAuthenticator passwordAuthenticator = new PasswordAuthenticator(USERNAME, PASSWORD);
  try (CouchbaseConnection connection = new CouchbaseConnection(Arrays.asList("couchbase://localhost"), passwordAuthenticator, BUCKET_NAME, null, ENV);) {
    JsonDocument document = connection.upsert("test", JsonObject.create().put("test", "test").toString());
    Assert.assertEquals("test", document.content().get("test"));
    connection.remove("test");
    Assert.assertNull(connection.get("test"));
  }
}

代码示例来源:origin: org.jnosql.diana/couchbase-driver

static JsonObject convert(DocumentEntity entity) {
  requireNonNull(entity, "entity is required");
  JsonObject jsonObject = JsonObject.create();
  entity.getDocuments().stream()
      .forEach(toJsonObject(jsonObject));
  return jsonObject;
}

代码示例来源:origin: com.couchbase.client/java-client

/**
 * Exports the whole query as a {@link JsonObject}.
 *
 * @see #injectParams(JsonObject) for the part that deals with global parameters
 * @see AbstractFtsQuery#injectParamsAndBoost(JsonObject) for the part that deals with the "query" entry
 */
public JsonObject export() {
  JsonObject result = JsonObject.create();
  injectParams(result);
  JsonObject queryJson = JsonObject.create();
  queryPart.injectParamsAndBoost(queryJson);
  return result.put("query", queryJson);
}

代码示例来源:origin: com.couchbase.client/java-client

/**
 * @return the String representation of the FTS query, which is its JSON representation without global parameters.
 */
@Override
public String toString() {
  JsonObject json = JsonObject.create();
  injectParamsAndBoost(json);
  return json.toString();
}

代码示例来源:origin: com.couchbase.client/java-client

@Override
  public JsonObject query() {
    JsonObject query = JsonObject.create().put("statement", statement);
    if (this.params != null) {
      this.params.injectParams(query);
    }
    return query;
  }
}

代码示例来源:origin: org.jnosql.diana/couchbase-driver

static QueryConverterResult delete(DocumentDeleteQuery query, String bucket) {
  JsonObject params = JsonObject.create();
  List<String> ids = new ArrayList<>();
  Expression condition = getCondition(query.getCondition()
      .orElseThrow(() -> new IllegalArgumentException("Condigtion is required")), params, ids,
      query.getDocumentCollection());
  MutateLimitPath statement = null;
  if (nonNull(condition)) {
    statement = Delete.deleteFrom(bucket).where(condition);
  }
  return new QueryConverterResult(params, statement, ids);
}

代码示例来源:origin: com.couchbase.client/java-client

@Override
  protected void injectParams(JsonObject input) {
    if (childQueries.isEmpty()) {
      throw new IllegalArgumentException("Compound query has no child query");
    }

    JsonArray conjuncts = JsonArray.create();
    for (AbstractFtsQuery childQuery : childQueries) {
      JsonObject childJson = JsonObject.create();
      childQuery.injectParamsAndBoost(childJson);
      conjuncts.add(childJson);
    }
    input.put("conjuncts", conjuncts);
  }
}

代码示例来源:origin: com.couchbase.client/java-client

@Override
public byte[] exportAnalyticsDeferredResultHandle(AnalyticsDeferredResultHandle handle) {
  try {
    JsonObject jsonObject = JsonObject.create();
    jsonObject.put("v", 1);
    jsonObject.put("uri", handle.getStatusHandleUri());
    return JacksonTransformers.MAPPER.writeValueAsBytes(jsonObject);
  } catch (JsonProcessingException e) {
    throw new IllegalStateException("Cannot convert handle to Json String", e);
  }
}

代码示例来源:origin: com.couchbase.client/java-client

@Override
public void injectParams(JsonObject queryJson) {
  super.injectParams(queryJson);
  JsonArray dateRange = JsonArray.empty();
  for (Map.Entry<String, DateRange> dr : dateRanges.entrySet()) {
    JsonObject drJson = JsonObject.create();
    drJson.put("name", dr.getKey());
    if (dr.getValue().start != null) {
      drJson.put("start", dr.getValue().start);
    }
    if (dr.getValue().end != null) {
      drJson.put("end", dr.getValue().end);
    }
    dateRange.add(drJson);
  }
  queryJson.put("date_ranges", dateRange);
}

代码示例来源:origin: com.couchbase.client/java-client

@Override
  public void injectParams(JsonObject queryJson) {
    super.injectParams(queryJson);

    JsonArray numericRange = JsonArray.empty();
    for (Map.Entry<String, NumericRange> nr : numericRanges.entrySet()) {
      JsonObject nrJson = JsonObject.create();
      nrJson.put("name", nr.getKey());

      if (nr.getValue().min != null) {
        nrJson.put("min", nr.getValue().min);
      }
      if (nr.getValue().max != null) {
        nrJson.put("max", nr.getValue().max);
      }

      numericRange.add(nrJson);
    }
    queryJson.put("numeric_ranges", numericRange);
  }
}

代码示例来源:origin: spring-projects/spring-data-couchbase

private JsonObject getNamedPlaceholderValues(ParameterAccessor accessor) {
  JsonObject namedValues = JsonObject.create();
  for (Parameter parameter : this.queryMethod.getParameters().getBindableParameters()) {
    String placeholder = parameter.getPlaceholder();
    Object value = this.couchbaseConverter.convertForWriteIfNeeded(accessor.getBindableValue(parameter.getIndex()));
    if (placeholder != null && placeholder.charAt(0) == ':') {
      placeholder = placeholder.replaceFirst(":", "");
      namedValues.put(placeholder, value);
    } else {
      parameter.getName().ifPresent(name -> namedValues.put(name, value));
    }
  }
  return namedValues;
}

代码示例来源:origin: org.springframework.data/spring-data-couchbase

private JsonObject getNamedPlaceholderValues(ParameterAccessor accessor) {
  JsonObject namedValues = JsonObject.create();
  for (Parameter parameter : this.queryMethod.getParameters().getBindableParameters()) {
    String placeholder = parameter.getPlaceholder();
    Object value = this.couchbaseConverter.convertForWriteIfNeeded(accessor.getBindableValue(parameter.getIndex()));
    if (placeholder != null && placeholder.charAt(0) == ':') {
      placeholder = placeholder.replaceFirst(":", "");
      namedValues.put(placeholder, value);
    } else {
      parameter.getName().ifPresent(name -> namedValues.put(name, value));
    }
  }
  return namedValues;
}

代码示例来源:origin: com.couchbase.client/java-client

private Statement with(boolean defer, String... nodeNames) {
  JsonObject options = JsonObject.create();
  if (defer) {
    options.put("defer_build", true);
  }
  if (nodeNames != null && nodeNames.length > 0) {
    options.put("nodes", JsonArray.from(nodeNames));
  }
  element(new WithIndexOptionElement(options));
  return this;
}

代码示例来源:origin: com.couchbase.client/java-client

@Override
public JsonObject n1ql() {
  JsonObject query = JsonObject.create().put(statementType(), statementValue());
  populateParameters(query, statementParameters());
  this.queryParameters.injectParams(query);
  return query; //return json-escaped string
}

代码示例来源:origin: simonbasle/practicalRx

public JsonObject toJsonObject(){
  JsonObject jso = JsonObject.create();
  jso.put("id",id);
  jso.put("nickname",nickname);
  jso.put("displayName", displayName);
  jso.put("bio", bio);
  jso.put("avatarId", avatarId);
  jso.put("type", "user");
  return jso;
}

代码示例来源:origin: com.couchbase.client/java-client

/**
 * Exports the {@link MutationState} into a format recognized by the FTS search engine.
 *
 * @return the exported {@link JsonObject} for one FTS index.
 */
public JsonObject exportForFts() {
  JsonObject result = JsonObject.create();
  for (MutationToken token : tokens) {
    String tokenKey = token.vbucketID() + "/" + token.vbucketUUID();
    Long seqno = result.getLong(tokenKey);
    if (seqno == null || seqno < token.sequenceNumber()) {
      result.put(tokenKey, token.sequenceNumber());
    }
  }
  return result;
}

相关文章