Package com.mongodb

Examples of com.mongodb.Mongo


  private static MongodForTestsFactory factory;

  @BeforeClass
  public static void setUp() throws IOException {
    factory = MongodForTestsFactory.with(Version.Main.V2_2);
    Mongo mongo = factory.newMongo();
    db = mongo.getDB("test");

    userService = new DefaultUserService(new MongoUserRepository(db));
    userReadService = new MongoUserReadService(db);
  }
View Full Code Here


  public void beforeEach() throws Exception {

    MongodStarter runtime = MongodStarter.getDefaultInstance();
    mongodExecutable = runtime.prepare(new MongodConfig(Version.V2_2_1, 12345, Network.localhostIsIPv6()));
    mongodProcess = mongodExecutable.start();
    Mongo mongo = new Mongo("localhost", 12345);
    db = mongo.getDB(DATABASE_NAME);

    // Create collections
    db.createCollection("soilData", new BasicDBObject());

  }
View Full Code Here

        final DBAddress address = new DBAddress(host, port, db);
        final MongoOptions options = new MongoOptions();
       
        options.connectionsPerHost = PropertiesUtil.toInteger(props.get(PROP_NUM_CONNECTIONS), DEFAULT_NUMCONNECTIONS);
        options.threadsAllowedToBlockForConnectionMultiplier = PropertiesUtil.toInteger(props.get(PROP_THREAD_MULTIPLIER), DEFAULT_THREAD_MULTIPLIER);
        final Mongo m = new Mongo(address, options);

        final DB database = m.getDB( db );
        logger.info("Connected to database {}", database);

        this.context = new MongoDBContext(database,
                roots[0],
                PropertiesUtil.toStringArray(props.get(PROP_FILTER_COLLECTIONS)),
View Full Code Here

  }

  @Override
  public void run(HelloWorldConfiguration config, Environment environment) throws UnknownHostException
  {
    Mongo mongo = new Mongo(config.mongohost, config.mongoport);
    MongoManaged mongoManaged = new MongoManaged(mongo);
    environment.manage(mongoManaged);
    environment.addHealthCheck(new MongoHealthCheck(mongo));
    DB db = mongo.getDB(config.mongodb);
    JacksonDBCollection<World, String> worlds = JacksonDBCollection.wrap(db.getCollection("world"), World.class, String.class);
    environment.addResource(new WorldResource(worlds));
    environment.addResource(new JsonResource());
  }
View Full Code Here

                httpServer.stop();
            }
        });

        MongoURI mongolabUri = new MongoURI(System.getenv("MONGOLAB_URI") != null ? System.getenv("MONGOLAB_URI") : "mongodb://127.0.0.1:27017/hello");
        Mongo m = new Mongo(mongolabUri);
        mongoDB = m.getDB(mongolabUri.getDatabase());
        if ((mongolabUri.getUsername() != null) && (mongolabUri.getPassword() != null)) {
            mongoDB.authenticate(mongolabUri.getUsername(), mongolabUri.getPassword());
        }

        contentUrl = System.getenv("CONTENT_URL") != null ? System.getenv("CONTENT_URL") : CONTENT_PATH;
View Full Code Here

     * @param userName the optional user name to use;
     * @param password the optional password to use.
     * @return <code>true</code> if the connection was succesful, <code>false</code> otherwise.
     */
    public boolean connect(String userName, String password) {
        Mongo newMongo = new Mongo(m_servers);

        Mongo oldMongo;
        do {
            oldMongo = m_mongoRef.get();
        } while (!m_mongoRef.compareAndSet(oldMongo, newMongo));
       
        DB db = newMongo.getDB(m_dbName);
View Full Code Here

     *
     * @return the {@link DBCollection}, never <code>null</code>.
     * @throws MongoException in case no connection to Mongo exists.
     */
    public DBCollection getCollection() {
        Mongo mongo = m_mongoRef.get();
        if (mongo == null) {
            throw new MongoException("Not connected to MongoDB!");
        }
        DB db = mongo.getDB(m_dbName);
        return db.getCollection(m_collectionName);
    }
View Full Code Here

    /**
     * Disconnects from the MongoDB.
     */
    public void disconnect() {
        Mongo mongo = m_mongoRef.get();
        if (mongo != null) {
            try {
                mongo.close();
            } finally {
                m_mongoRef.compareAndSet(mongo, null);
            }
        }
    }
View Full Code Here

        ManagedService service = (ManagedService) context.getService(serviceRef);
        try
        {
            service.updated(null);

            Mongo mongo = new Mongo();
            DB db = mongo.getDB("ua_repo");
            DBCollection collection = db.getCollection("useradmin");
            // we always get a collection back, regardless if there is an actual MongoDB listening, hence we should do
            // some actual calls that cause a connection to MongoDB to be created...
            collection.remove(new BasicDBObject(), WriteConcern.SAFE);
View Full Code Here

    }

    @Provides
    Mongo create(final Application application) {
        try {
            return new Mongo(new MongoURI(application.configuration().getString("mongodb.uri")));
        } catch (UnknownHostException e) {
            addError(e);
            return null;
        }
    }
View Full Code Here

TOP

Related Classes of com.mongodb.Mongo

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.