Search in sources :

Example 1 with NonNull

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());
}
Also used : MemoryBackend(de.bwaldvogel.mongo.backend.memory.MemoryBackend) InetSocketAddress(java.net.InetSocketAddress) MongoServer(de.bwaldvogel.mongo.MongoServer) NonNull(com.mongodb.lang.NonNull)

Example 2 with NonNull

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;
    }
}
Also used : SubjectProvider(com.mongodb.SubjectProvider) NonNull(com.mongodb.lang.NonNull)

Example 3 with NonNull

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");
}
Also used : Document(org.bson.Document) NonNull(com.mongodb.lang.NonNull)

Example 4 with NonNull

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();
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap) URL(java.net.URL) MongoInternalException(com.mongodb.MongoInternalException) NonNull(com.mongodb.lang.NonNull)

Example 5 with NonNull

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;
}
Also used : ClientSession(com.mongodb.client.ClientSession) Document(org.bson.Document) NonNull(com.mongodb.lang.NonNull)

Aggregations

NonNull (com.mongodb.lang.NonNull)7 Document (org.bson.Document)4 ClientSession (com.mongodb.client.ClientSession)2 DBRef (com.mongodb.DBRef)1 MongoInternalException (com.mongodb.MongoInternalException)1 SubjectProvider (com.mongodb.SubjectProvider)1 MongoServer (de.bwaldvogel.mongo.MongoServer)1 MemoryBackend (de.bwaldvogel.mongo.backend.memory.MemoryBackend)1 MappingException (dev.morphia.mapping.MappingException)1 DocumentReader (dev.morphia.mapping.codec.reader.DocumentReader)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 HttpURLConnection (java.net.HttpURLConnection)1 InetSocketAddress (java.net.InetSocketAddress)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CodecConfigurationException (org.bson.codecs.configuration.CodecConfigurationException)1