Example usage for com.mongodb Mongo getDatabaseNames

List of usage examples for com.mongodb Mongo getDatabaseNames

Introduction

In this page you can find the example usage for com.mongodb Mongo getDatabaseNames.

Prototype

@Deprecated
public List<String> getDatabaseNames() 

Source Link

Document

Gets a list of the names of all databases on the connected server.

Usage

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;
}