本文整理汇总了Java中com.couchbase.client.java.document.json.JsonObject.create方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.create方法的具体用法?Java JsonObject.create怎么用?Java JsonObject.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.couchbase.client.java.document.json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.create方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: updateDocument
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
public static void updateDocument(Bucket proteusBucket, ArrayList<String> topicsList, Measurement record) {
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());
}
if (!row1d.isEmpty()) {
proteusBucket.mutateIn(record.getStringCoilID()).arrayAppend(topicsList.get(0), row1d).execute();
}
if (!row2d.isEmpty()) {
proteusBucket.mutateIn(record.getStringCoilID()).arrayAppend(topicsList.get(0), row2d).execute();
}
if (!hsm.isEmpty()) {
proteusBucket.mutateIn(record.getStringCoilID()).arrayAppend(topicsList.get(0), hsm).execute();
}
}
示例3: toJsonObject
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
/**
*
* @param obj an array of pairs of property name and value, or Map<String, Object>, or an entity with getter/setter methods.
* @return
*/
public static JsonObject toJsonObject(final Object obj) {
Map<String, Object> m = null;
if (obj instanceof Map) {
m = (Map<String, Object>) obj;
} else if (N.isEntity(obj.getClass())) {
m = Maps.entity2Map(obj);
} else if (obj instanceof Object[]) {
m = N.asProps(obj);
} else {
throw new IllegalArgumentException("The parameters must be a Map, or an entity class with getter/setter methods");
}
final JsonObject result = JsonObject.create();
for (Map.Entry<String, Object> entry : m.entrySet()) {
if (entry.getValue() == null || supportedTypes.contains(entry.getValue().getClass())) {
result.put(entry.getKey(), entry.getValue());
} else {
Type<Object> valueType = N.typeOf(entry.getValue().getClass());
if (valueType.isMap() || valueType.isEntity()) {
result.put(entry.getKey(), toJsonObject(entry.getValue()));
} else if (valueType.isObjectArray() || valueType.isCollection()) {
result.put(entry.getKey(), toJsonArray(entry.getValue()));
} else {
result.put(entry.getKey(), N.stringOf(entry.getValue()));
}
}
}
return result;
}
示例4: mapRow
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
public JsonDocument mapRow(ResultSet rs, int rowNum) throws SQLException {
String id = table.getName() + "::" + rs.getString(table.getPrimaryKey());
JsonObject obj = JsonObject.create();
for (Column col : table.getColumns()) {
Object value = getJsonTypedValue(col.type, rs.getObject(col.name), col.name);
obj.put(col.name, value);
}
return JsonDocument.create(id, obj);
}
示例5: getJsonTypedValue
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
public Object getJsonTypedValue(int type, Object value, String name) throws SQLException {
if (value == null) {
return null;
}
JDBCType current = JDBCType.valueOf(type);
switch (current) {
case TIMESTAMP:
Timestamp timestamp = (Timestamp) value;
return timestamp.getTime();
case TIMESTAMP_WITH_TIMEZONE:
Timestamp ts = (Timestamp) value;
JsonObject tsWithTz = JsonObject.create();
tsWithTz.put("timestamp", ts.getTime());
tsWithTz.put("timezone", ts.getTimezoneOffset());
return tsWithTz;
case DATE:
Date sqlDate = (Date) value;
return sqlDate.getTime();
case DECIMAL:
case NUMERIC:
BigDecimal bigDecimal = (BigDecimal) value;
return bigDecimal.doubleValue();
case ARRAY:
Array array = (Array) value;
Object[] objects = (Object[]) array.getArray();
return JsonArray.from(objects);
case BINARY:
case BLOB:
case LONGVARBINARY:
return Base64.getEncoder().encodeToString((byte[]) value);
case OTHER:
case JAVA_OBJECT:
// database specific, default to String value
return value.toString();
default:
return value;
}
}
示例6: toJsonObject
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
public JsonObject toJsonObject() {
JsonObject obj = JsonObject.create();
JsonArray jsonColumns = JsonArray.create();
for (Column col : columns) {
jsonColumns.add(col.toJsonObject());
}
obj.put("tableName", name);
obj.put("primaryKey", primaryKey);
obj.put("columns", jsonColumns);
return obj;
}
示例7: createDocumentFirstTime
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的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);
}
示例8: createNode
import com.couchbase.client.java.document.json.JsonObject; //导入方法依赖的package包/类
private JsonObject createNode(final String status, final String nodeName) {
final JsonObject node1 = JsonObject.create();
node1.put("status", status);
node1.put("hostname", nodeName);
return node1;
}