use of com.mongodb.lang.NonNull in project morphia by mongodb.
the class LegacyQuery method iterable.
@NonNull
private <E> FindIterable<E> iterable(FindOptions options, MongoCollection<E> collection) {
final Document query = this.toDocument();
if (LOG.isTraceEnabled()) {
LOG.trace(format("Running query(%s) : %s, options: %s,", getCollectionName(), query.toJson(), options));
}
if ((options.getCursorType() != null && options.getCursorType() != NonTailable) && (options.getSort() != null)) {
LOG.warn("Sorting on tail is not allowed.");
}
ClientSession clientSession = datastore.findSession(options);
FindIterable<E> iterable = clientSession != null ? collection.find(clientSession, query) : collection.find(query);
return iterable;
}
use of com.mongodb.lang.NonNull 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;
}
Aggregations