Package com.mongodb

Examples of com.mongodb.MongoURI


    @Deprecated
    @SuppressWarnings("deprecation")
    public static MongoURI getMongoURI(final Configuration conf, final String key) {
        final String raw = conf.get(key);
        if (raw != null && !raw.trim().isEmpty()) {
            return new MongoURI(raw);
        } else {
            return null;
        }
    }
View Full Code Here


    @Deprecated
    @SuppressWarnings("deprecation")
    public static MongoURI getMongoURI(final Configuration conf, final String key) {
        final String raw = conf.get(key);
        if (raw != null && !raw.trim().isEmpty()) {
            return new MongoURI(raw);
        } else {
            return null;
        }
    }
View Full Code Here

   */
  @Test
  @SuppressWarnings("deprecation")
  public void mongoUriConstructor() throws UnknownHostException {

    MongoURI mongoURI = new MongoURI("mongodb://myUsername:myPassword@localhost/myDatabase.myCollection");
    MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(mongoURI);

    assertThat(ReflectionTestUtils.getField(mongoDbFactory, "credentials"), is((Object) new UserCredentials(
        "myUsername", "myPassword")));
    assertThat(ReflectionTestUtils.getField(mongoDbFactory, "databaseName").toString(), is("myDatabase"));
View Full Code Here

public class MongoFactory implements FactoryBean<DB> {

  private MongoURI mongoUri;

  public MongoFactory(String uri) throws URISyntaxException {
    this.mongoUri = new MongoURI(uri);
  }
View Full Code Here

        try {
            if (uri == null) {
                addError("Please set a non-null MongoDB URI.");
                return;
            }
            MongoURI mongoURI = new MongoURI(uri);
            String database = mongoURI.getDatabase();
            String collection = mongoURI.getCollection();
            if (database == null || collection == null) {
                addError("Error connecting to MongoDB URI: " + uri + " must contain a database and a collection."
                        + " E.g. mongodb://localhost/database.collection");
                return;
            }
            mongo = new Mongo(mongoURI);
            DB db = mongo.getDB(database);
            String username = mongoURI.getUsername();
            char[] password = mongoURI.getPassword();
            if (username != null && password != null)
                db.authenticate(username, password);
            eventsCollection = db.getCollection(collection);
            super.start();
        } catch (Exception exception) {
View Full Code Here

    public void startup() {
        _running.set(true);
        try {
            _lock.lock();

            _mongo = new Mongo(new MongoURI(_options.getMongoUri()));

            // Init the db/collection.
            LockDao.setup(_mongo, _options);
            if (_options.getEnableHistory()) LockHistoryDao.setup(_mongo, _options);
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  protected Mongo createInstance()
    throws Exception {
    return new Mongo(new MongoURI(uri));
  }
View Full Code Here

    return getMongo(props);
  }

  public static final Mongo getMongo(Properties props)
      throws UnknownHostException, MongoException {
    MongoURI uri = new MongoURI(props.getProperty("db.uri"));
    Mongo mongo = new Mongo(uri);
    return mongo;
  }
View Full Code Here

  private ConcurrentHashMap<String, MockDB> data;

  MockMongo() {
    try {
      this.port = MockMongo.anyPort();
      this.uri = new MongoURI("mongodb://0.0.0.0:" + port);
    } catch (IOException e) {
      throw new RuntimeException("failed to find a free port", e);
    }
  }
View Full Code Here

    }
  }

  MockMongo(int port) {
    this.port = port;
    this.uri = new MongoURI("mongodb://0.0.0.0:" + port);
  }
View Full Code Here

TOP

Related Classes of com.mongodb.MongoURI

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.