List of usage examples for com.mongodb Mongo Mongo
Mongo(final MongoClientURI mongoURI)
From source file:com.uquetignywebapp.connection.ConnectionMongoDB.java
public ConnectionMongoDB() throws UnknownHostException { Mongo mongoClient = new Mongo("localhost"); db = mongoClient.getDB("uqb2"); //boolean auth = db.authenticate(myUserName, myPassword); }
From source file:de.belaso.mongolyn.ui.MongolynUtils.java
License:Open Source License
public static DB openNewDB(final TaskRepository repository) throws CoreException { try {//from ww w . j ava 2s. c om MongoURI mongoURI = new MongoURI(repository.getRepositoryUrl()); DB db = new Mongo(mongoURI).getDB(mongoURI.getDatabase()); AuthenticationCredentials credentials = repository.getCredentials(AuthenticationType.REPOSITORY); if (credentials != null) { db.authenticate(credentials.getUserName(), credentials.getPassword().toCharArray()); } return db; } catch (UnknownHostException unknownHostException) { throw new CoreException(Activator.INSTANCE.getErrorStatus(unknownHostException)); } }
From source file:de.fhg.igd.mongomvcc.impl.MongoDBVDatabase.java
License:Open Source License
@Override public void connect(String name, String host, int port) throws VException { Mongo mongo;//from w w w.j a v a 2 s. co m try { mongo = new Mongo(new ServerAddress(host, port)); } catch (UnknownHostException e) { throw new VException("Unknown host", e); } connectInternal(name, mongo); }
From source file:de.fhg.igd.mongomvcc.impl.MongoDBVDatabase.java
License:Open Source License
@Override public void connectToReplicaSet(String name, Map<String, Integer> hostsWithPort, boolean slaveOk) throws VException { Mongo mongo = null;// www .ja v a2 s . c o m try { List<ServerAddress> addrs = new ArrayList<ServerAddress>(); for (Map.Entry<String, Integer> e : hostsWithPort.entrySet()) { addrs.add(new ServerAddress(e.getKey(), e.getValue())); } mongo = new Mongo(addrs); if (slaveOk && mongo != null) { mongo.slaveOk(); // mongo.setReadPreference(ReadPreference.SECONDARY); needed with version 2.2 } } catch (UnknownHostException e) { throw new VException("Unknown host", e); } connectInternal(name, mongo); }
From source file:de.flapdoodle.embed.mongo.tests.MongosForTestsFactory.java
License:Apache License
/** * Creates a new Mongo connection.//from ww w.j a v a2 s . c om * * @throws MongoException * @throws UnknownHostException */ public Mongo newMongo() throws UnknownHostException, MongoException { return new Mongo(new ServerAddress(mongosProcess.getConfig().net().getServerAddress(), mongosProcess.getConfig().net().getPort())); }
From source file:de.flapdoodle.embed.mongo.tests.MongosSystemForTestFactory.java
License:Apache License
public Mongo getMongo() throws UnknownHostException, MongoException { return new Mongo(new ServerAddress(mongosProcess.getConfig().net().getServerAddress(), mongosProcess.getConfig().net().getPort())); }
From source file:de.ifgi.fmt.mongo.MongoDB.java
License:Open Source License
/** * /*from www . j a va 2s . co m*/ */ protected MongoDB() { try { MorphiaLoggerFactory.registerLogger(SLF4JLogrImplFactory.class); InputStream is = getClass().getResourceAsStream(PROPERTIES_FILE); Properties p = new Properties(); if (is != null) { try { p.load(is); } finally { IOUtils.closeQuietly(is); } } String host = p.getProperty(HOST_PROPERTY); host = (host == null || host.trim().isEmpty()) ? "localhost" : host; String port = p.getProperty(PORT_PROPERTY); port = (port == null || port.trim().isEmpty()) ? "27017" : port; this.mongo = new Mongo(new ServerAddress(host, Integer.valueOf(port))); this.morphia = new Morphia(); DefaultConverters dc = this.morphia.getMapper().getConverters(); Set<Class<? extends TypeConverter>> classes = Implementations.getSubclasses(TypeConverter.class); if (log.isDebugEnabled()) { log.debug("{} Mongo converter classes found:\n{}", classes.size(), Utils.join(new Stringifier() { public String toString(Object t) { return " " + t.toString(); } }, "\n", classes)); } for (Class<? extends TypeConverter> c : classes) { dc.addConverter(c); } new MorphiaValidation().applyTo(this.morphia); String auth = p.getProperty(AUTH_PROPERTY); auth = (auth == null || auth.trim().isEmpty()) ? "false" : auth; String dbna = p.getProperty(DATABASE_PROPERTY); this.database = (auth == null || dbna.trim().isEmpty()) ? DEFAULT_DATABASE : dbna; if (Boolean.valueOf(auth)) { this.datastore = this.morphia.createDatastore(this.mongo, this.database, p.getProperty(USER_PROPERTY, "mongo"), p.getProperty(PASS_PROPERTY, "mongo").toCharArray()); } else { this.datastore = this.morphia.createDatastore(this.mongo, this.database); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:edu.rice.rubbos.servlets.RubbosHttpServlet.java
License:Open Source License
private void initMongoDb() throws UnknownHostException { m = new Mongo(properties.getProperty("host")); db = m.getDB(properties.getProperty("db")); dbClient = new MongoDb(m, db); }
From source file:edu.sjsu.carbonated.mongodbaccessors.MongoDBAlbum.java
License:Apache License
public MongoDBAlbum() { try {//from w w w .j a va 2s .com m = new Mongo(sHost); DB db = m.getDB(sDB); albumColl = db.getCollection(albumCollection); photoColl = db.getCollection(photoCollection); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MongoException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:edu.sjsu.carbonated.mongodbaccessors.MongoDBBlog.java
License:Apache License
public MongoDBBlog() { try {/*from w ww . ja va2 s .c o m*/ m = new Mongo(sHost); DB db = m.getDB(sDB); collection = db.getCollection(sCollection); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MongoException e) { // TODO Auto-generated catch block e.printStackTrace(); } }