use of com.mongodb.DBRef in project morphia by mongodb.
the class ReaderState method unwind.
private Object unwind(Object value) {
Object unwind = value;
if (value instanceof DBRef) {
DBRef dbRef = (DBRef) value;
Document document = new Document("$ref", dbRef.getCollectionName()).append("$id", dbRef.getId());
if (dbRef.getDatabaseName() != null) {
document.append("$db", dbRef.getDatabaseName());
}
unwind = document;
} else if (value instanceof UUID) {
unwind = new BsonBinary((UUID) value);
}
return unwind;
}
use of com.mongodb.DBRef in project morphia by mongodb.
the class ReferenceCodec method processId.
/**
* Decodes an ID value
*
* @param datastore the Datastore to use
* @param decode the value to decode
* @param decoderContext the decoder context
* @return the decoded value
*/
@NonNull
public static Object processId(Datastore datastore, Object decode, DecoderContext decoderContext) {
Object id = decode;
if (id instanceof Iterable) {
Iterable<?> iterable = (Iterable<?>) id;
List<Object> ids = new ArrayList<>();
for (Object o : iterable) {
ids.add(processId(datastore, o, decoderContext));
}
id = ids;
} else if (id instanceof Document) {
Document document = (Document) id;
if (document.containsKey("$ref")) {
id = processId(datastore, new DBRef(document.getString("$db"), document.getString("$ref"), document.get("$id")), decoderContext);
} else if (document.containsKey(datastore.getMapper().getOptions().getDiscriminatorKey())) {
try {
id = datastore.getCodecRegistry().get(datastore.getMapper().getClass(document)).decode(new DocumentReader(document), decoderContext);
} catch (CodecConfigurationException e) {
throw new MappingException(Sofia.cannotFindTypeInDocument(), e);
}
}
} else if (id instanceof DBRef) {
DBRef ref = (DBRef) id;
Object refId = ref.getId();
if (refId instanceof Document) {
refId = datastore.getCodecRegistry().get(Object.class).decode(new DocumentReader((Document) refId), decoderContext);
}
id = new DBRef(ref.getDatabaseName(), ref.getCollectionName(), refId);
}
return id;
}
use of com.mongodb.DBRef in project mongo-hadoop by mongodb.
the class PigBoxedDBRef method getObject.
@Override
public DBRef getObject() {
byte[] bytes = get();
ObjectId id = new ObjectId(Arrays.copyOfRange(bytes, bytes.length - 12, bytes.length));
String collectionName = new String(Arrays.copyOfRange(bytes, 0, bytes.length - 13));
return new DBRef(collectionName, id);
}
Aggregations