/** * Attempts to find an existing MongoClient instance matching that URI in the holder, and returns it if exists. Otherwise creates a * new Mongo instance based on this URI and adds it to the holder. * * @param uri the Mongo URI * @return the client * @throws MongoException if there's a failure * @deprecated Please use {@link #connect(MongoClientURI)} instead. */ @SuppressWarnings("deprecation") @Deprecated public Mongo connect(final MongoURI uri) { return connect(uri.toClientURI()); }
/** * Attempts to find an existing MongoClient instance matching that URI in the holder, and returns it if exists. Otherwise creates a * new Mongo instance based on this URI and adds it to the holder. * * @param uri the Mongo URI * @return the client * @throws MongoException if there's a failure */ public Mongo connect(final MongoClientURI uri) { String key = toKey(uri); Mongo client = clients.get(key); if (client == null) { Mongo newbie = new MongoClient(uri); client = clients.putIfAbsent(key, newbie); if (client == null) { client = newbie; } else { newbie.close(); } } return client; }
/** * Attempts to find an existing MongoClient instance matching that URI in the holder, and returns it if exists. Otherwise creates a * new Mongo instance based on this URI and adds it to the holder. * * @param uri the Mongo URI * @return the client * @throws MongoException if there's a failure */ public Mongo connect(final MongoClientURI uri) { String key = toKey(uri); Mongo client = clients.get(key); if (client == null) { Mongo newbie = new MongoClient(uri); client = clients.putIfAbsent(key, newbie); if (client == null) { client = newbie; } else { newbie.close(); } } return client; }
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
public static DBCollection getCollection( MongoURI uri ){ try { Mongo mongo = _mongos.connect( uri ); DB myDb = mongo.getDB(uri.getDatabase()); //if there's a username and password if(uri.getUsername() != null && uri.getPassword() != null && !myDb.isAuthenticated()) { boolean auth = myDb.authenticate(uri.getUsername(), uri.getPassword()); if(auth) { log.info("Sucessfully authenticated with collection."); } else { throw new IllegalArgumentException( "Unable to connect to collection." ); } } return uri.connectCollection(mongo); } catch ( final Exception e ) { throw new IllegalArgumentException( "Unable to connect to collection." + e.getMessage(), e ); } }
/** * Attempts to find an existing MongoClient instance matching that URI in the holder, and returns it if exists. Otherwise creates a * new Mongo instance based on this URI and adds it to the holder. * * @param uri the Mongo URI * @return the client * @throws MongoException if there's a failure * @deprecated Please use {@link #connect(MongoClientURI)} instead. */ @SuppressWarnings("deprecation") @Deprecated public Mongo connect(final MongoURI uri) { return connect(uri.toClientURI()); }