List of usage examples for com.mongodb Mongo getDB
@Deprecated public DB getDB(final String dbName)
From source file:com.ebay.cloud.cms.metadata.mongo.MongoMetadataServiceImpl.java
License:Apache License
public MongoMetadataServiceImpl(Mongo mongo, int maxCacheSize, int cacheExpiredTime, int collectionCountCacheSize, int collectionCountCacheExpiredTime, Repository repo, ICMSLock metadataLock) {//from ww w . j a v a 2s . c o m CheckConditions.checkNotNull(mongo, "mongo can not be null"); CheckConditions.checkNotNull(repo, "repository can not be null"); CheckConditions.checkArgument(maxCacheSize > 0, "maximumSize can not be negtive value"); CheckConditions.checkArgument(cacheExpiredTime > 0, "expireAfterSeconds can not be negtive value"); CheckConditions.checkArgument(collectionCountCacheSize > 0, "collectionCountCacheSize can not be negtive value"); CheckConditions.checkArgument(collectionCountCacheExpiredTime > 0, "collectionCountCacheExpiredTime can not be negtive value"); CheckConditions.checkArgument(metadataLock != null, "metadataLock should not be null"); this.metadataLock = metadataLock; this.maxCacheSize = maxCacheSize; this.cacheExpiredTime = cacheExpiredTime; this.mongo = mongo; this.repo = repo; this.cacheManager = new MongoMetaCacheManager(maxCacheSize, cacheExpiredTime, collectionCountCacheSize, collectionCountCacheExpiredTime); String collectionName = CMSConsts.METACLASS_COLL; collection = mongo.getDB(repo.getRepositoryName()).getCollection(collectionName); // read from primary only collection.setReadPreference(ReadPreference.primary()); collection.setWriteConcern(WriteConcern.SAFE); sequence = new MongoSequence(mongo, CMSConsts.SYS_DB, CMSConsts.SEQUENCE_COLL, CMSConsts.NEXT_FIELD_NAME_SEQ); this.getMetaClasses(new MetadataContext(true, true)); }
From source file:com.ebay.cloud.cms.metadata.mongo.MongoRepositoryServiceImpl.java
License:Apache License
public static void prepareSystemDB(Mongo mongo) { DBCollection repoCollection = mongo.getDB(CMSConsts.SYS_DB).getCollection(CMSConsts.REPOSITORY_COLL); MongoUtils.ensureIndex(repoCollection, Repository.REPOSITORY_FIELD_NAME, true, false); repoCollection.setWriteConcern(WriteConcern.SAFE); }
From source file:com.ebay.cloud.cms.metadata.sequence.MongoSequence.java
License:Apache License
public MongoSequence(Mongo mongo, String dbName, String collName, String key) { super();/*from w ww.ja v a 2 s .co m*/ this.coll = mongo.getDB(dbName).getCollection(collName); this.key = key; this.coll.setWriteConcern(WriteConcern.SAFE); }
From source file:com.ebay.cloud.cms.web.RunTestServer.java
License:Apache License
private static boolean isMongoRunning(MongoDataSource ds) { try {//from w w w. jav a2 s . co m Mongo mongo = ds.getMongoInstance(); mongo.getDB("test").getCollection("test").count(); return true; } catch (Exception e) { return false; } }
From source file:com.ebay.jetstream.config.mongo.MongoConnection.java
License:MIT License
public MongoConnection(MongoConfiguration mongoConfiguration) { List<ServerAddress> hosts = new ArrayList<ServerAddress>(); for (String host : mongoConfiguration.getHosts()) { try {//from w w w.j ava 2 s. c o m hosts.add(new ServerAddress(host, Integer.valueOf(mongoConfiguration.getPort()))); } catch (UnknownHostException e) { } } Mongo mongo = null; mongo = new Mongo(hosts); db = mongo.getDB(mongoConfiguration.getDb()); authenticate(mongoConfiguration); }
From source file:com.ebay.jetstream.config.mongo.MongoConnection.java
License:MIT License
public MongoConnection(List<String> hostStrings, String port, String database) { List<ServerAddress> hosts = new ArrayList<ServerAddress>(); for (String host : hostStrings) { try {// w ww . j ava2 s. c o m hosts.add(new ServerAddress(host, Integer.valueOf(port))); } catch (UnknownHostException e) { } } Mongo mongo = null; mongo = new Mongo(hosts); db = mongo.getDB(database); }
From source file:com.eharmony.matching.seeking.executor.mongodb.MongoQueryExecutor.java
License:Apache License
public MongoQueryExecutor(Mongo mongo, String database, WriteConcern writeConcern, MongoQueryTranslator queryTranslator, EntityResolver entityResolver) { this(mongo.getDB(database), writeConcern, queryTranslator, entityResolver); }
From source file:com.eharmony.matching.seeking.executor.mongodb.MongoQueryExecutor.java
License:Apache License
public MongoQueryExecutor(Mongo mongo, String database, WriteConcern writeConcern, MongoQueryTranslator queryTranslator, EntityResolver entityResolver, final int batchSize) { this(mongo.getDB(database), writeConcern, queryTranslator, entityResolver, batchSize); }
From source file:com.englishtown.integration.java.IntegrationTestHelper.java
License:Open Source License
public static GridFS getGridFS(JsonObject config, String bucket) { Mongo mongo; try {// ww w. ja va 2 s .c o m mongo = new MongoClient(config.getString("host", "localhost"), config.getInteger("port", 27017)); } catch (UnknownHostException e) { fail(); return null; } String dbName = config.getString("db_name", "default_db"); DB db = mongo.getDB(dbName); if (bucket == null) { return new GridFS(db); } else { return new GridFS(db, bucket); } }
From source file:com.fuction.MongoDB.java
public static void input(ArrayList<String> lsResult) { try {//from ww w . ja v a 2 s .c o m Mongo mongo = new Mongo(HOST, PORT); DB db = mongo.getDB(DB); DBCollection collection = db.getCollection("Data"); for (String s : lsResult) { DBObject dbObject = (DBObject) JSON.parse(s); collection.insert(dbObject); } } catch (Exception e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); } }