List of usage examples for com.mongodb Mongo Mongo
Mongo(final MongoClientURI mongoURI, @Nullable final MongoDriverInformation mongoDriverInformation)
From source file:com.logger.mongo.MongoDBManager.java
public static MongoDBManager getInstance(String uri, String db, MongoOptions poolOption) { if (mongoDBManager == null) { synchronized (objLock) { if (mongoDBManager == null) { try { mongoDBManager = new MongoDBManager(); mongoDBManager.mongo = new Mongo(uri, poolOption); mongoDBManager.db = mongoDBManager.mongo.getDB(db); } catch (UnknownHostException ex) { Logger.getLogger(MongoDBManager.class.getName()).log(Level.SEVERE, null, ex); }/*from w w w .ja v a2 s. c om*/ } } } return mongoDBManager; }
From source file:com.lowereast.guiceymongo.logging.MongoDbAppender.java
License:Open Source License
/** * @see org.apache.log4j.AppenderSkeleton#activateOptions() *//*from ww w . jav a 2s. co m*/ @Override public void activateOptions() { try { Mongo mongo = new Mongo(hostname, port); DB database = mongo.getDB(databaseName); if (userName != null && userName.trim().length() > 0) { if (!database.authenticate(userName, password)) { throw new RuntimeException("Unable to authenticate with MongoDB server."); } // Allow password to be GCed password = null; } setCollection(database.getCollection(collectionName)); } catch (Exception e) { errorHandler.error("Unexpected exception while initialising MongoDbAppender.", e, ErrorCode.GENERIC_FAILURE); } }
From source file:com.machinelinking.storage.mongodb.MongoJSONStorage.java
License:Apache License
public MongoJSONStorage(MongoJSONStorageConfiguration config, DocumentConverter<MongoDocument> converter) throws UnknownHostException { this.configuration = config; this.mongo = new Mongo(config.getHost(), config.getPort()); this.db = mongo.getDB(config.getDB()); this.converter = converter; }
From source file:com.mebigfatguy.mongobrowser.actions.ConnectAction.java
License:Apache License
@Override public void actionPerformed(ActionEvent e) { try {//from ww w .ja v a 2 s .c o m ConnectionDialog cd = new ConnectionDialog(); cd.setLocationRelativeTo(null); cd.setModal(true); cd.setVisible(true); if (cd.isOK()) { String host = cd.getHost(); int port = cd.getPort(); context.setServer(new Mongo(host, port)); } } catch (UnknownHostException uhe) { JOptionPane.showMessageDialog(null, uhe.getMessage()); } }
From source file:com.mebigfatguy.mongobrowser.dialogs.MongoBrowserFrame.java
License:Apache License
public void startupConnection(final String host, final int port) throws UnknownHostException, MongoException { try {//ww w . ja v a 2 s.co m mediator.setServer(new Mongo(host, port)); } catch (Exception e) { connectItem.setEnabled(true); disconnectItem.setEnabled(false); ctrlPanel.term(); dataPanel.term(); if (e instanceof UnknownHostException) throw (UnknownHostException) e; else if (e instanceof MongoException) throw (MongoException) e; } }
From source file:com.mingo.executor.QueryExecutorFactory.java
License:Apache License
/** * Creates query executor./*from w w w . java2 s. c o m*/ * * @param host database host * @param port database port * @param context mingo context {@link Context} * @return query executor {@link QueryExecutor} */ public static QueryExecutor create(String host, int port, Context context) { QueryExecutor queryExecutor = null; try { queryExecutor = create(new Mongo(host, port), context); } catch (UnknownHostException e) { LOGGER.error(ExceptionUtils.getMessage(e)); } return queryExecutor; }
From source file:com.mk.mongo.EmbeddedMongoMojo.java
License:Apache License
public void execute() throws MojoExecutionException { try {//from w ww . j av a 2 s .c om MongodStarter runtime = MongodStarter.getDefaultInstance(); mongodExe = runtime.prepare(new MongodConfig(Version.V2_0_5, null, MONGO_PORT, Network.localhostIsIPv6(), MONGO_DATA_PATH, null, 0)); mongodExe.start(); mongo = new Mongo(MONGO_HOST, MONGO_PORT); db = mongo.getDB(MONGO_DB); db.doEval(getScriptContent(), new Object[0]); getLog().info("--In memory mongo db setup successful--"); } catch (UnknownHostException e) { getLog().error(e.getMessage()); } catch (IOException e) { getLog().error(e.getMessage()); } }
From source file:com.mulesoft.quartz.mongo.MongoDBJobStore.java
License:Open Source License
public void initialize(ClassLoadHelper loadHelper, SchedulerSignaler signaler) throws SchedulerConfigException { this.loadHelper = loadHelper; this.signaler = signaler; if (addresses == null || addresses.length == 0) { throw new SchedulerConfigException("At least one MongoDB address must be specified."); }//from www .ja v a2s .c o m MongoOptions options = new MongoOptions(); options.safe = true; // need to do this to ensure we get DuplicateKey exceptions try { ArrayList<ServerAddress> serverAddresses = new ArrayList<ServerAddress>(); for (String a : addresses) { serverAddresses.add(new ServerAddress(a)); } mongo = new Mongo(serverAddresses, options); } catch (UnknownHostException e) { throw new SchedulerConfigException("Could not connect to MongoDB.", e); } catch (MongoException e) { throw new SchedulerConfigException("Could not connect to MongoDB.", e); } DB db = mongo.getDB(dbName); if (username != null) { db.authenticate(username, password.toCharArray()); } jobCollection = db.getCollection(collectionPrefix + "jobs"); triggerCollection = db.getCollection(collectionPrefix + "triggers"); calendarCollection = db.getCollection(collectionPrefix + "calendars"); locksCollection = db.getCollection(collectionPrefix + "locks"); BasicDBObject keys = new BasicDBObject(); keys.put(JOB_KEY_NAME, 1); keys.put(JOB_KEY_GROUP, 1); jobCollection.ensureIndex(keys, null, true); keys = new BasicDBObject(); keys.put(TRIGGER_KEY_NAME, 1); keys.put(TRIGGER_KEY_GROUP, 1); triggerCollection.ensureIndex(keys, null, true); keys = new BasicDBObject(); keys.put(LOCK_KEY_NAME, 1); keys.put(LOCK_KEY_GROUP, 1); locksCollection.ensureIndex(keys, null, true); // remove all locks for this instance on startup locksCollection.remove(new BasicDBObject(LOCK_INSTANCE_ID, instanceId)); keys = new BasicDBObject(); keys.put(CALENDAR_NAME, 1); calendarCollection.ensureIndex(keys, null, true); }
From source file:com.mycompany.Farmerama.changeProfileImage.java
public changeProfileImage() { Mongo mongo = new Mongo("localhost", 27017); db = mongo.getDB("accounts"); account = db.getCollection("account"); }
From source file:com.mycompany.Farmerama.contactWithOther.java
public contactWithOther() { Mongo mongo = new Mongo("localhost", 27017); db = mongo.getDB("PrivateMessages"); }