Package com.mongodb

Examples of com.mongodb.Mongo$Holder


    @Before
    public void setup() throws Exception {
        Logger.getRootLogger().setLevel(Level.OFF);

        final Mongo m = new Mongo();
        try {
            m.dropDatabase("mydb");
        } catch (final Exception e) {
            assumeThat(true, is(false));// ie ignore test because we've had an
                                        // exception
            return;
        }

        testDb = m.getDB("mydb");

        final BasicDBObject object = new BasicDBObject();
        object.put("_id", "1023");
        object.put("_type", "org.xxx.Class");
        object.put("name", "Fred Smith");
View Full Code Here


        return null;
    }

    @Override
    public void open() {
        Mongo m;
        try {
            m = new Mongo(host, port);
            db = m.getDB(dbName);
            LOG.info("opened database (" + dbName + "): " + db);
        } catch (final UnknownHostException e) {
            throw new NoSqlStoreException(e);
        } catch (final MongoException e) {
            throw new NoSqlStoreException(e);
View Full Code Here

public class DemoMongo {
    // @Test
    public void installed() throws Exception {

        final Mongo m = new Mongo();

        for (final String s : m.getDatabaseNames()) {
            System.out.println(s);
        }

        /*
         * Mongo m = new Mongo( "localhost" ); Mongo m = new Mongo( "localhost"
         * , 27017 );
         */
        m.dropDatabase("mydb");

        System.out.println("\n...");
        for (final String s : m.getDatabaseNames()) {
            System.out.println(s);
        }

        final DB db = m.getDB("mydb");
        /*
         * DBCollection coll = db.getCollection("testCollection1"); coll =
         * db.getCollection("testCollection2");
         */

 
View Full Code Here

    public void setup() throws Exception {
        Logger.getRootLogger().setLevel(Level.OFF);

        try {

            final Mongo m = new Mongo();
            m.dropDatabase("mydb");
            testDb = m.getDB("mydb");
        } catch (final Exception e) {
            assumeThat(true, is(false)); // ie no exceptions
            return;
        }
View Full Code Here

    public void setup() throws Exception {
        Logger.getRootLogger().setLevel(Level.OFF);
        testObjects = new TrialObjects();

        try {
            final Mongo m = new Mongo();
            m.dropDatabase("testdb");
            testDb = m.getDB("testdb");
        } catch (final Exception e) {
            assumeThat(true, is(false)); // ignore if no MongoDB instance to
                                         // connect to
            return;
        }
View Full Code Here

    @Resource(name = "messageDBDatastore")
    protected Datastore messageDBDatastore;

    @After
    public void tearDown() throws Exception {
        Mongo mongo = businessDBDatastore.getMongo();
        mongo.dropDatabase("TEST_nodeabledb");
        mongo.dropDatabase("TEST_nodeablemsgdb");
    }
View Full Code Here

    long start = System.currentTimeMillis();
    logger.info("MongoDB:");
    createService(VCAP_MONGO_SERVICE, "mongodb", "1.8");
    int tunnelPort = LOCAL_PORT + 2;
    createTunnelServer(VCAP_MONGO_SERVICE, tunnelPort);
    Mongo mongo = new Mongo(LOCAL_HOST, tunnelPort);
    MongoDbFactory mdbf = new SimpleMongoDbFactory(mongo, svc_dbname, new UserCredentials(svc_username, svc_passwd));
    MongoTemplate mongoTemplate = new MongoTemplate(mdbf);
    // Test data
    ObjectMapper objectMapper = new ObjectMapper();
    Map<String,Object> dataMap = null;
    try {
      dataMap = objectMapper.readValue(new File("data/load.json"), Map.class);
    } catch (IOException e) {
      e.printStackTrace();
    }
    List<Map<String, Object>> l = (List<Map<String, Object>>) dataMap.get("records");
    for (Map<String, Object> m : l) {
      Map<String, Object> rec = (Map<String, Object>) m.get("record");
      final BasicDBObject dbo = new BasicDBObject();
      dbo.putAll(rec);
      mongoTemplate.execute("records", new CollectionCallback<Object>() {
        public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
          collection.insert(dbo);
          return null;
        }
      });
    }
    List records = mongoTemplate.findAll(BasicDBObject.class, "records");
    Assert.assertEquals("Did not load the data correctly", 200, records.size());
    mongo.close();

    stopTunnelServer();
    removeService(VCAP_MONGO_SERVICE);
    logger.info("Time elapsed: " + (System.currentTimeMillis() - start) / 1000.0d + " sec");
  }
View Full Code Here

        }
    }

    @After
    public void tearDown() throws Exception {
        Mongo mongo = applicationManager.getMessageDBDatastore().getMongo();
        mongo.dropDatabase("TEST_nodeabledb");
        mongo.dropDatabase("TEST_nodeablemsgdb");
    }
View Full Code Here

    }

    @Override
    protected Mongo createInstance() throws Exception {
        if (StringUtils.hasText(this.hostname )) {
            return new Mongo(new ServerAddress(hostname,port), getMongoOptions());
        } else {
            return new Mongo();
        }
    }
View Full Code Here

  @Override
  public void onStart(play.Application arg0) {
    super.beforeStart(arg0);
    Logger.debug("** onStart **");
    try {
      MorphiaObject.mongo = new Mongo("127.0.0.1", 27017);
    } catch (UnknownHostException e) {
      e.printStackTrace();
    }
    MorphiaObject.morphia = new Morphia();
    MorphiaObject.datastore = MorphiaObject.morphia.createDatastore(MorphiaObject.mongo, "test");
View Full Code Here

TOP

Related Classes of com.mongodb.Mongo$Holder

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.