use of com.mongodb.client.ClientSession in project morphia by mongodb.
the class MorphiaQuery method iterable.
@NonNull
private <E> FindIterable<E> iterable(FindOptions findOptions, MongoCollection<E> collection) {
final Document query = toDocument();
if (LOG.isTraceEnabled()) {
LOG.trace(format("Running query(%s) : %s, options: %s,", getCollectionName(), query, findOptions));
}
if ((findOptions.getCursorType() != null && findOptions.getCursorType() != NonTailable) && (findOptions.getSort() != null)) {
LOG.warn("Sorting on tail is not allowed.");
}
ClientSession clientSession = datastore.findSession(findOptions);
MongoCollection<E> updated = findOptions.prepare(collection);
FindIterable<E> iterable = clientSession != null ? updated.find(clientSession, query) : updated.find(query);
return iterable;
}
use of com.mongodb.client.ClientSession in project morphia by mongodb.
the class MorphiaQuery method findAndDelete.
@Override
public T findAndDelete(FindAndDeleteOptions options) {
MongoCollection<T> mongoCollection = options.prepare(getCollection());
ClientSession session = datastore.findSession(options);
return session == null ? mongoCollection.findOneAndDelete(getQueryDocument(), options) : mongoCollection.findOneAndDelete(session, getQueryDocument(), options);
}
use of com.mongodb.client.ClientSession in project morphia by mongodb.
the class Modify method execute.
/**
* Performs the operation
*
* @param options the options to apply
* @return the operation result
*/
@Nullable
public T execute(ModifyOptions options) {
ClientSession session = getDatastore().findSession(options);
Document update = toDocument();
return session == null ? options.prepare(getCollection()).findOneAndUpdate(getQuery().toDocument(), update, options) : options.prepare(getCollection()).findOneAndUpdate(session, getQuery().toDocument(), update, options);
}
use of com.mongodb.client.ClientSession 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.client.ClientSession in project morphia by mongodb.
the class Update method execute.
/**
* Executes the update
*
* @param options the options to apply
* @return the results
*/
public UpdateResult execute(UpdateOptions options) {
Document updateOperations = toDocument();
final Document queryObject = getQuery().toDocument();
ClientSession session = getDatastore().findSession(options);
MongoCollection<T> mongoCollection = options.prepare(getCollection());
if (options.isMulti()) {
return session == null ? mongoCollection.updateMany(queryObject, updateOperations, options) : mongoCollection.updateMany(session, queryObject, updateOperations, options);
} else {
return session == null ? mongoCollection.updateOne(queryObject, updateOperations, options) : mongoCollection.updateOne(session, queryObject, updateOperations, options);
}
}
Aggregations