List of usage examples for com.mongodb DBRef getDatabaseName
@Nullable
public String getDatabaseName()
From source file:com.streamsets.pipeline.stage.common.mongodb.MongoDBUtil.java
License:Apache License
@SuppressWarnings("unchecked") private static Field jsonToField(Object object) throws IOException { if (object instanceof ObjectId) { String objectId = object.toString(); return JsonUtil.jsonToField(objectId); } else if (object instanceof Binary) { byte[] data = ((Binary) object).getData(); return JsonUtil.jsonToField(data); } else if (object instanceof BsonTimestamp) { int time = ((BsonTimestamp) object).getTime(); Date date = new Date(time * 1000L); Map<String, Object> jsonMap = new LinkedHashMap<>(); jsonMap.put(BSON_TS_TIME_T_FIELD, date); jsonMap.put(BSON_TS_ORDINAL_FIELD, ((BsonTimestamp) object).getInc()); return JsonUtil.jsonToField(jsonMap); } else if (object instanceof List) { List jsonList = (List) object; List<Field> list = new ArrayList<>(jsonList.size()); for (Object element : jsonList) { list.add(jsonToField(element)); }//from w ww. j a va 2s .co m return Field.create(list); } else if (object instanceof Map) { Map<String, Object> jsonMap = (Map<String, Object>) object; Map<String, Field> map = new LinkedHashMap<>(); for (Map.Entry<String, Object> entry : jsonMap.entrySet()) { map.put(entry.getKey(), jsonToField(entry.getValue())); } return Field.create(map); } else if (object instanceof com.mongodb.DBRef) { Map<String, Field> map = new LinkedHashMap<>(); com.mongodb.DBRef ref = (com.mongodb.DBRef) object; map.put(REF, Field.create(ref.getCollectionName())); map.put(ID, Field.create(ref.getId().toString())); if (ref.getDatabaseName() != null) { map.put(DB, Field.create(ref.getDatabaseName())); } return Field.create(map); } return JsonUtil.jsonToField(object); }
From source file:org.codinjutsu.tools.mongo.view.model.JsonTreeUtils.java
License:Apache License
private static void processDBRef(JsonTreeNode parentNode, DBRef dbRef) { parentNode/*w w w. j a v a 2 s. c o m*/ .add(new JsonTreeNode(MongoKeyValueDescriptor.createDescriptor("$ref", dbRef.getCollectionName()))); parentNode.add(new JsonTreeNode(MongoKeyValueDescriptor.createDescriptor("$id", dbRef.getId()))); parentNode.add(new JsonTreeNode(MongoKeyValueDescriptor.createDescriptor("$db", dbRef.getDatabaseName()))); }