List of usage examples for com.mongodb Mongo Mongo
Mongo(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation)
From source file:org.stocker.PingVerticle.java
License:Apache License
public void start() { JsonObject appConfig = container.config(); JsonObject dbConfig = appConfig.getObject("mongo-persistor"); Yoke yoke = new Yoke(this.vertx); DB mongoDB = null;//from www. jav a 2 s . com try { Mongo mongo = new Mongo(dbConfig.getString("host"), dbConfig.getInteger("port")); mongoDB = mongo.getDB(dbConfig.getString("db_name")); } catch (UnknownHostException e) { e.printStackTrace(); } final DBCollection stockCollection = mongoDB.getCollection("stocks"); //TODO : inject these guys from a shared module which is a singleton instance // these guys -> AsyncHttpClient asyncHttpClient = new AsyncHttpClient(); ZipReader zipReader = new ZipReaderImpl(); StockDBClient stockDBClient = new StockDBClientImpl(stockCollection); StockDataClient stockDataClient = new StockDataClientImpl(asyncHttpClient, zipReader); DataAggregator dataAggregator = new DataAggregator(stockDBClient); PredictionService predictionService = new PredictionService(dataAggregator); // ^ these guys // routes GetPredictionTemplatedRoute getPredictionTemplatedRoute = new GetPredictionTemplatedRoute( predictionService); GetPredictionRoute getPredictionRoute = new GetPredictionRoute(predictionService); UpdateRecordsRoute updateRecordsRoute = new UpdateRecordsRoute(stockDataClient, stockDBClient); GetStockRoute getStockRoute = new GetStockRoute(stockDBClient); GetAggregatedDataTemplatedRoute getAggregatedDataTemplatedRoute = new GetAggregatedDataTemplatedRoute( dataAggregator); GetAggregatedDataRoute getAggregatedDataRoute = new GetAggregatedDataRoute(dataAggregator); Router router = new Router(); router.get("/healthCheck", new HealthCheck()); router.post("/update/stocks/:date", updateRecordsRoute); router.get("/stock/:stock/date/:date", getStockRoute); router.get("/prediction/stock/:stock/type/:type", getPredictionTemplatedRoute); router.get("/prediction/stock/:stock", getPredictionRoute); router.get("/data/stock/:stock/type/:type", getAggregatedDataTemplatedRoute); router.get("/data/stock/:stock", getAggregatedDataRoute); yoke.use(new com.jetdrone.vertx.yoke.middleware.Logger()).use(new BodyParser()).use(router).listen(4080); //populateDB(updateRecordsRoute); container.logger().info("PingVerticle started : 4080"); System.out.println("PingVerticle.start - "); }
From source file:org.thiesen.troy.TroyORMDAOFactory.java
License:Open Source License
private TroyORMDAOFactory(final String database, final String host, final int port, final TypeConversionMap conversionMap) throws UnknownHostException, MongoException { super();//from w w w. java 2 s . c o m final Mongo m = new Mongo(host, port); _dbConnection = m.getDB(database); _conversionMap = conversionMap; }
From source file:org.uom.fit.level2.datavis.repository.ChatServicesImpl.java
@Override public JSONArray getAll() { try {//from www .j a v a2 s . co m Mongo mongo = new Mongo("localhost", 27017); DB db = mongo.getDB("datarepo"); DBCollection collection = db.getCollection("user"); DBCursor cursor = collection.find(); JSON json = new JSON(); String dataUser = json.serialize(cursor); JSONParser parser = new JSONParser(); Object obj = parser.parse(dataUser); JSONArray jsonarray = (JSONArray) obj; return jsonarray; } catch (Exception e) { System.out.println("Exception Error getAll"); return null; } }
From source file:org.uom.fit.level2.datavis.repository.ChatServicesImpl.java
@Override public boolean saveChatData(ChatData chatData) { try {/*from ww w.j av a 2 s.com*/ Mongo mongo = new Mongo("localhost", 27017); DB db = mongo.getDB("datarepo"); DBCollection collection = db.getCollection("message"); Gson gson = new Gson(); DBObject dbObject = (DBObject) JSON.parse(gson.toJson(chatData)); WriteResult result = collection.insert(WriteConcern.SAFE, dbObject); return true; } catch (Exception e) { System.out.println("Exception Error createProect"); return false; } }
From source file:org.uom.fit.level2.datavis.repository.ChatServicesImpl.java
@Override public JSONArray getAllChatData(String message) { try {//from w w w . j a va2 s.c om Mongo mongo = new Mongo("localhost", 27017); DB db = mongo.getDB("chat"); DBCollection collection = db.getCollection("message"); BasicDBObject whereQuery = new BasicDBObject(); BasicDBObject field = new BasicDBObject(); BasicDBObject sortQuery = new BasicDBObject(); whereQuery.put("message", message); field.put("senderName", 1); field.put("message", 1); field.put("receiverName", 1); field.put("imageData", 1); field.put("discription", 1); sortQuery.put("DateTime", 1); DBCursor cursor = collection.find(whereQuery, field).sort(sortQuery); JSON json = new JSON(); String dataUser = json.serialize(cursor); JSONParser parser = new JSONParser(); Object obj = parser.parse(dataUser); JSONArray jsonarray = (JSONArray) obj; return jsonarray; } catch (Exception e) { System.out.println("Exception Error getAll"); return null; } }
From source file:org.uom.fit.level2.datavis.repository.ChatServicesImpl.java
@Override public JSONArray getAllChatDataAllMessage() { try {//w w w .java 2s . co m Mongo mongo = new Mongo("localhost", 27017); DB db = mongo.getDB("chat"); DBCollection collection = db.getCollection("message"); List<String> lst = collection.distinct("message"); String json = new Gson().toJson(lst); JSONArray jsonarray = (JSONArray) new JSONParser().parse(json); return jsonarray; } catch (Exception e) { System.out.println("Exception Error getAllChatDataAllMEssage"); return null; } }
From source file:org.vertx.java.busmods.persistor.MongoPersistor.java
License:Apache License
public void start() { super.start(); host = super.getOptionalStringConfig("host", "localhost"); port = super.getOptionalIntConfig("port", 27017); dbName = super.getMandatoryStringConfig("db_name"); try {/*from w w w . j a v a 2s . co m*/ mongo = new Mongo(host, port); db = mongo.getDB(dbName); eb.registerHandler(address, this); } catch (UnknownHostException e) { log.error("Failed to connect to mongo server", e); } }
From source file:org.vertx.mods.MongoPersistor.java
License:Apache License
public void start() { super.start(); address = getOptionalStringConfig("address", "vertx.mongopersistor"); host = getOptionalStringConfig("host", "localhost"); port = getOptionalIntConfig("port", 27017); dbName = getOptionalStringConfig("db_name", "default_db"); username = getOptionalStringConfig("username", null); password = getOptionalStringConfig("password", null); try {/*from w ww. j a v a 2 s. c o m*/ mongo = new Mongo(host, port); db = mongo.getDB(dbName); if (username != null && password != null) { db.authenticate(username, password.toCharArray()); } eb.registerHandler(address, this); } catch (UnknownHostException e) { logger.error("Failed to connect to mongo server", e); } }
From source file:org.vertx.osgi.mod.mongo.MongoPersistor.java
License:Apache License
public MongoPersistor(String host, int port, String dbName) throws UnknownHostException, MongoException { this.host = host; this.port = port; this.dbName = dbName; this.mongo = new Mongo(host, port); this.db = this.mongo.getDB(dbName); }
From source file:org.waveprotocol.wave.examples.fedone.persistence.mongodb.MongoDbProvider.java
License:Apache License
/** * Starts the {@link Mongo} instance and explicitly checks whether it is * actually alive.//from ww w . j a v a2 s .co m * * @throws PersistenceStartException if we can't make a connection to MongoDb. */ private void start() { Preconditions.checkState(!isRunning(), "Can't start after a connection has been established"); ensurePropertiesLoaded(); String host = properties.getProperty(HOST_PROPERTY); int port = Integer.parseInt(properties.getProperty(PORT_PROPERTY)); try { mongo = new Mongo(host, port); } catch (UnknownHostException e) { throw new PersistenceStartException("Unable to resolve the MongoDb hostname", e); } try { // Check to see if we are alive mongo.getDB(getDatabaseName()).command("ping"); } catch (MongoException e) { throw new PersistenceStartException("Can't ping MongoDb", e); } isRunning = true; LOG.info("Started MongoDb persistence"); }