use of com.mongodb.lang.NonNull in project books by aidanwhiteley.
the class MongoJavaServerConfig method mongoClient.
@Override
@NonNull
public MongoClient mongoClient() {
preProdWarnings.displayMongoJavaServerWarningMessage();
MongoServer server = new MongoServer(new MemoryBackend());
// bind on a random local port
InetSocketAddress serverAddress = server.bind();
return MongoClients.create("mongodb://" + serverAddress.getHostName() + ":" + serverAddress.getPort());
}
use of com.mongodb.lang.NonNull in project mongo-java-driver by mongodb.
the class SaslAuthenticator method getSubjectProvider.
@NonNull
private SubjectProvider getSubjectProvider() {
synchronized (getMongoCredentialWithCache()) {
SubjectProvider subjectProvider = getMongoCredentialWithCache().getFromCache(SUBJECT_PROVIDER_CACHE_KEY, SubjectProvider.class);
if (subjectProvider == null) {
subjectProvider = getMongoCredential().getMechanismProperty(JAVA_SUBJECT_PROVIDER_KEY, null);
if (subjectProvider == null) {
subjectProvider = getDefaultSubjectProvider();
}
getMongoCredentialWithCache().putInCache(SUBJECT_PROVIDER_CACHE_KEY, subjectProvider);
}
return subjectProvider;
}
}
use of com.mongodb.lang.NonNull in project morphia by mongodb.
the class TestBase method getOptions.
@NonNull
protected Document getOptions(Class<?> type) {
String collection = getMapper().getEntityModel(type).getCollectionName();
Document result = getDatabase().runCommand(new Document("listCollections", 1.0).append("filter", new Document("name", collection)));
Document cursor = (Document) result.get("cursor");
return (Document) cursor.getList("firstBatch", Document.class).get(0).get("options");
}
use of com.mongodb.lang.NonNull in project mongo-java-driver by mongodb.
the class AwsCredentialHelper method getHttpContents.
@NonNull
private static String getHttpContents(final String method, final String endpoint, final Map<String, String> headers) {
StringBuilder content = new StringBuilder();
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) new URL(endpoint).openConnection();
conn.setRequestMethod(method);
conn.setReadTimeout(10000);
if (headers != null) {
for (Map.Entry<String, String> kvp : headers.entrySet()) {
conn.setRequestProperty(kvp.getKey(), kvp.getValue());
}
}
int status = conn.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) {
throw new IOException(String.format("%d %s", status, conn.getResponseMessage()));
}
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) {
String inputLine;
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
}
} catch (IOException e) {
throw new MongoInternalException("Unexpected IOException", e);
} finally {
if (conn != null) {
conn.disconnect();
}
}
return content.toString();
}
use of com.mongodb.lang.NonNull 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;
}
Aggregations