Package com.mongodb

Examples of com.mongodb.MongoClientURI


  public String getMongoClientDatabase() {
    if (this.database != null) {
      return this.database;
    }
    return new MongoClientURI(this.uri).getDatabase();
  }
View Full Code Here


        }
        return new MongoClient(Arrays.asList(new ServerAddress(this.host,
            this.port)), credentials, options);
      }
      // The options and credentials are in the URI
      return new MongoClient(new MongoClientURI(this.uri, builder(options)));
    }
    finally {
      clearPassword();
    }
  }
View Full Code Here

    protected void init() throws Exception {
        if (beanType == null) {
            throw SupportMessages.MESSAGES.invalidReaderWriterProperty(null, null, "beanType");
        }
        if (mongoClientLookup == null) {
            final MongoClientURI clientURI;
            if (uri != null) {
                clientURI = new MongoClientURI(uri);
                if (database == null) {
                    database = clientURI.getDatabase();
                }
                if (collection == null) {
                    collection = clientURI.getCollection();
                }
            } else {
                clientURI = MongoClientObjectFactory.createMongoClientURI(host, database, collection, options, user, password);
            }
            mongoClient = (MongoClient) Mongo.Holder.singleton().connect(clientURI);
View Full Code Here

     * @param uri the MongoDB URI
     * @throws UnknownHostException
     */
    public MongoConnection(String uri) throws UnknownHostException  {
        MongoClientOptions.Builder builder = MongoConnection.getDefaultBuilder();
        MongoClientURI mongoURI = new MongoClientURI(uri, builder);
        mongo = new MongoClient(mongoURI);
        db = mongo.getDB(mongoURI.getDatabase());
    }
View Full Code Here

        int cacheSize = PropertiesUtil.toInteger(prop(PROP_CACHE), DEFAULT_CACHE);
        boolean useMK = PropertiesUtil.toBoolean(context.getProperties().get(PROP_USE_MK), false);


        MongoClientOptions.Builder builder = MongoConnection.getDefaultBuilder();
        MongoClientURI mongoURI = new MongoClientURI(uri, builder);

        if (log.isInfoEnabled()) {
            // Take care around not logging the uri directly as it
            // might contain passwords
            String type = useMK ? "MK" : "NodeStore";
            log.info("Starting Document{} with host={}, db={}, cache size (MB)={}, Off Heap Cache size (MB)={}",
                    type, mongoURI.getHosts(), db, cacheSize, offHeapCache);
            log.info("Mongo Connection details {}", MongoConnection.toString(mongoURI.getOptions()));
        }

        MongoClient client = new MongoClient(mongoURI);
        DB mongoDB = client.getDB(db);
View Full Code Here

    public static synchronized MongoClientURI getMongoClientURI() {
        if (mongoClientURI == null) {
            String mongoURIProperty = System.getProperty(MONGODB_URI_SYSTEM_PROPERTY_NAME);
            String mongoURIString = mongoURIProperty == null || mongoURIProperty.length() == 0? DEFAULT_URI : mongoURIProperty;
            mongoClientURI = new MongoClientURI(mongoURIString);
        }
        return mongoClientURI;
    }
View Full Code Here

    public static final int NUM_DOCUMENTS = 10000;
    public static final int NUM_THREADS = 100;

    public static void main(String[] args) throws UnknownHostException {
        MongoClientURI uri = args.length > 0
                             ? new MongoClientURI(args[0])
                             : new MongoClientURI("mongodb://localhost");
        MongoClient mongoClient = new MongoClient(uri);

        DB db = mongoClient.getDB(uri.getDatabase() != null
                                  ? uri.getDatabase()
                                  : "test");

        final DBCollection collection = db.getCollection("test");
        collection.drop();
View Full Code Here

    @SuppressWarnings("deprecation")
    private static Mongo getMongo()
        throws Exception {
        if ( _mongo == null )  {
            _mongo = new MongoClient(new MongoClientURI(uri));
        }
        return _mongo;
    }
View Full Code Here

        try {
            String rwModeUri = readWriteMode;
            if(!readWriteMode.startsWith("mongodb://")){
                rwModeUri = String.format("mongodb://localhost/?%s", readWriteMode);
            }
            MongoClientURI uri = new MongoClientURI(rwModeUri);
            ReadPreference readPref = uri.getOptions().getReadPreference();

            if (!readPref.equals(nodes.getReadPreference())) {
                nodes.setReadPreference(readPref);
                LOG.info("Using ReadPreference {} ",readPref);
            }

            WriteConcern writeConcern = uri.getOptions().getWriteConcern();
            if (!writeConcern.equals(nodes.getWriteConcern())) {
                nodes.setWriteConcern(writeConcern);
                LOG.info("Using WriteConcern " + writeConcern);
            }
        } catch (Exception e) {
View Full Code Here

        int cacheSize = PropertiesUtil.toInteger(prop(config, PROP_CACHE), DEFAULT_CACHE);
        boolean useMK = PropertiesUtil.toBoolean(config.get(PROP_USE_MK), false);


        MongoClientOptions.Builder builder = MongoConnection.getDefaultBuilder();
        MongoClientURI mongoURI = new MongoClientURI(uri, builder);

        if (logger.isInfoEnabled()){
            // Take care around not logging the uri directly as it
            // might contain passwords
            String type = useMK ? "MK" : "NodeStore";
            logger.info("Starting Document{} with host={}, db={}, cache size (MB)={}, Off Heap Cache size (MB)={}",
                    new Object[] {type, mongoURI.getHosts(), db, cacheSize, offHeapCache});
            logger.info("Mongo Connection details {}", MongoConnection.toString(mongoURI.getOptions()));
        }

        MongoClient client = new MongoClient(mongoURI);
        DB mongoDB = client.getDB(db);
View Full Code Here

TOP

Related Classes of com.mongodb.MongoClientURI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.