List of usage examples for com.mongodb Mongo getDatabaseNames
@Deprecated
public List<String> getDatabaseNames()
From source file:org.springframework.integration.mongodb.rules.MongoDbAvailableRule.java
License:Apache License
@Override public Statement apply(final Statement base, final FrameworkMethod method, final Object target) { return new Statement() { @Override/*www.j a va 2 s . c o m*/ public void evaluate() throws Throwable { MongoDbAvailable mongoAvailable = method.getAnnotation(MongoDbAvailable.class); if (mongoAvailable != null) { try { MongoClientOptions options = new MongoClientOptions.Builder().connectTimeout(100).build(); Mongo mongo = new MongoClient(ServerAddress.defaultHost(), options); mongo.getDatabaseNames(); } catch (Exception e) { logger.warn("MongoDb is not available. Skipping the test: " + target.getClass().getSimpleName() + "." + method.getName() + "()"); return; } } base.evaluate(); } }; }
From source file:us.polygon4.izzymongo.service.ServiceConfig.java
License:Apache License
public @Bean MongoTemplateContainer initialize() throws Exception { Map<String, MongoOperations> templateMap = new HashMap<String, MongoOperations>(); Mongo m = mongoFactoryBean.getObject(); for (String dbname : m.getDatabaseNames()) { MongoOperations mongoOps = new MongoTemplate(m, dbname); templateMap.put(dbname, mongoOps); }//from ww w.ja v a2 s. c o m log.info(templateMap.toString()); MongoTemplateContainer mtc = new MongoTemplateContainer(); mtc.setTemplateMap(templateMap); return mtc; }