Example usage for org.springframework.data.mongodb MongoDbFactory getDb

List of usage examples for org.springframework.data.mongodb MongoDbFactory getDb

Introduction

In this page you can find the example usage for org.springframework.data.mongodb MongoDbFactory getDb.

Prototype

MongoDatabase getDb() throws DataAccessException;

Source Link

Document

Creates a default MongoDatabase instance.

Usage

From source file:com.gopivotal.cloudfoundry.test.core.MongoDbUtils.java

public String getUrl(MongoDbFactory mongoDbFactory) {
    DB mongoDb = mongoDbFactory.getDb();

    if (mongoDb != null) {

        StringBuilder builder = new StringBuilder();
        List<ServerAddress> serverAddresses = mongoDb.getMongo().getAllAddress();
        builder.append(getServerString(mongoDb, serverAddresses.get(0)));

        for (int i = 1; i < serverAddresses.size(); i++) {
            builder.append(", " + getServerString(mongoDb, serverAddresses.get(i)));
        }//from   ww w.j a  v a 2  s .c  o m

        return builder.toString();
    }

    return "mongodb://fake.connection";
}

From source file:com.gopivotal.cloudfoundry.test.core.MongoDbUtils.java

public String checkAccess(MongoDbFactory mongoDbFactory) {
    try {//from   www  .jav  a2  s.co m
        DB db = mongoDbFactory.getDb();
        db.getMongo();
        return "ok";
    } catch (Exception e) {
        return "failed with " + e.getMessage();
    }
}

From source file:se.inera.axel.shs.broker.messagestore.internal.MongoMessageStoreService.java

@Autowired(required = true)
public MongoMessageStoreService(MongoDbFactory mongoDbFactory) {
    gridFs = new GridFS(mongoDbFactory.getDb());

    this.shsMessageMarshaller = new ShsMessageMarshaller();
}

From source file:com.seajas.search.contender.service.storage.StorageService.java

/**
 * Default constructor.//from w  w  w  .j a v  a  2s. c o  m
 *
 * @param dbFactory
 */
@Autowired
public StorageService(final MongoDbFactory dbFactory) {
    this.gridFs = new GridFS(dbFactory.getDb());
}

From source file:com.seajas.search.profiler.service.repository.RepositoryService.java

/**
 * Default constructor.//from  w  w w .j  a v  a 2 s. co m
 *
 * @param dbFactory
 */
@Autowired
public RepositoryService(final MongoDbFactory dbFactory, final MongoTemplate mongoTemplate) {
    this.gridFs = new GridFS(dbFactory.getDb());

    // Initialize the indexes only if there aren't too many documents in the store yet

    Long currentCount = mongoTemplate.count(new Query(), CompositeEntry.class);

    // Determine whether the given indexes have been created, and initialize them if necessary

    if (currentCount <= MAX_INDEX_CREATION_COUNT)
        for (String index : INDEXES)
            mongoTemplate.indexOps(CompositeEntry.class).ensureIndex(new Index().on(index, Order.ASCENDING));

    this.mongoTemplate = mongoTemplate;
}