use of com.mongodb.MongoQueryException in project mongo-java-driver by mongodb.
the class FindOperation method exceptionTransformingCallback.
private static <T> SingleResultCallback<T> exceptionTransformingCallback(final SingleResultCallback<T> callback) {
return new SingleResultCallback<T>() {
@Override
public void onResult(final T result, final Throwable t) {
if (t != null) {
if (t instanceof MongoCommandException) {
MongoCommandException commandException = (MongoCommandException) t;
callback.onResult(result, new MongoQueryException(commandException.getServerAddress(), commandException.getErrorCode(), commandException.getErrorMessage()));
} else {
callback.onResult(result, t);
}
} else {
callback.onResult(result, null);
}
}
};
}
use of com.mongodb.MongoQueryException in project jackrabbit-oak by apache.
the class MongoStatus method isMajorityReadConcernEnabled.
/**
* Check if the majority read concern is enabled and can be used for queries.
*
* @return true if the majority read concern is enabled
*/
public boolean isMajorityReadConcernEnabled() {
if (majorityReadConcernEnabled == null) {
// Mongo API doesn't seem to provide an option to check whether the
// majority read concern has been enabled, so we have to try to use
// it and optionally catch the exception.
DBCollection emptyCollection = db.getCollection("emptyCollection-" + System.currentTimeMillis());
DBCursor cursor = emptyCollection.find(new BasicDBObject(), new DBCollectionFindOptions().readConcern(ReadConcern.MAJORITY));
try {
cursor.hasNext();
majorityReadConcernEnabled = true;
} catch (MongoQueryException | IllegalArgumentException e) {
majorityReadConcernEnabled = false;
} finally {
cursor.close();
}
}
return majorityReadConcernEnabled;
}
Aggregations