Example usage for com.mongodb Mongo getDB

List of usage examples for com.mongodb Mongo getDB

Introduction

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

Prototype

@Deprecated 
public DB getDB(final String dbName) 

Source Link

Document

Gets a database object.

Usage

From source file:com.linuxbox.util.queueservice.mongodb.MongoQueueService.java

License:Open Source License

public MongoQueueService(Mongo mongo, String database, String collection) {
    this(mongo, mongo.getDB(database).getCollection(collection));
}

From source file:com.lowereast.guiceymongo.guice.spi.DBProviderModule.java

License:Apache License

private void cacheDB() throws MongoException, UnknownHostException {
    String databaseKey = ((GuiceyMongoDatabase) key.getAnnotation()).value();

    String clonedConfiguration = getInstance(_injector,
            Key.get(String.class, AnnotationUtil.clonedConfiguration(_configuration)));
    if (clonedConfiguration == null) {
        String database = _injector.getInstance(
                Key.get(String.class, AnnotationUtil.configuredDatabase(_configuration, databaseKey)));
        Mongo connection = getConnection(_configuration, databaseKey);
        _cachedDB = connection.getDB(database);
        // test connection
        _cachedDB.getCollectionNames();/*  w  ww  .  j a v a 2  s . c om*/
    } else {
        Mongo connection = getConnection(clonedConfiguration, databaseKey);
        _cachedDB = connection.getDB(UUID.randomUUID().toString());
        String clonedDatabase = _injector.getInstance(
                Key.get(String.class, AnnotationUtil.configuredDatabase(clonedConfiguration, databaseKey)));
        _cachedDB.eval("var c = connect('" + clonedDatabase
                + "'); c.system.js.find().forEach(function(x){db.system.js.save(x)}); db.system.js.ensureIndex({_id: 1});");

        Runtime.getRuntime().addShutdownHook(new RemoveTemporaryDB(_cachedDB));
    }
}

From source file:com.lowereast.guiceymongo.logging.MongoDbAppender.java

License:Open Source License

/**
 * @see org.apache.log4j.AppenderSkeleton#activateOptions()
 *//*ww w.j  a v a2 s  .  co m*/
@Override
public void activateOptions() {
    try {
        Mongo mongo = new Mongo(hostname, port);
        DB database = mongo.getDB(databaseName);

        if (userName != null && userName.trim().length() > 0) {
            if (!database.authenticate(userName, password)) {
                throw new RuntimeException("Unable to authenticate with MongoDB server.");
            }

            // Allow password to be GCed
            password = null;
        }

        setCollection(database.getCollection(collectionName));
    } catch (Exception e) {
        errorHandler.error("Unexpected exception while initialising MongoDbAppender.", e,
                ErrorCode.GENERIC_FAILURE);
    }
}

From source file:com.mattinsler.guiceymongo.guice.spi.DBProviderModule.java

License:Apache License

private void cacheDB() throws MongoException, UnknownHostException {
    String databaseKey = ((MongoDatabase) key.getAnnotation()).value();

    String clonedConfiguration = getInstance(_injector,
            Key.get(String.class, AnnotationUtil.clonedConfiguration(_configuration)));
    if (clonedConfiguration == null) {
        String database = _injector.getInstance(
                Key.get(String.class, AnnotationUtil.configuredDatabase(_configuration, databaseKey)));
        Mongo connection = getConnection(_configuration, databaseKey);
        _cachedDB = connection.getDB(database);
        // test connection
        _cachedDB.getCollectionNames();/*  ww w.  j a v a  2 s  .  c  om*/
    } else {
        Mongo connection = getConnection(clonedConfiguration, databaseKey);
        _cachedDB = connection.getDB(UUID.randomUUID().toString());
        String clonedDatabase = _injector.getInstance(
                Key.get(String.class, AnnotationUtil.configuredDatabase(clonedConfiguration, databaseKey)));
        _cachedDB.eval("var c = connect('" + clonedDatabase
                + "'); c.system.js.find().forEach(function(x){db.system.js.save(x)}); db.system.js.ensureIndex({_id: 1});");

        Runtime.getRuntime().addShutdownHook(new RemoveTemporaryDB(_cachedDB));
    }
}

From source file:com.mycompany.Farmerama.changeProfileImage.java

public changeProfileImage() {
    Mongo mongo = new Mongo("localhost", 27017);
    db = mongo.getDB("accounts");
    account = db.getCollection("account");
}

From source file:com.mycompany.Farmerama.contactWithOther.java

public contactWithOther() {
    Mongo mongo = new Mongo("localhost", 27017);
    db = mongo.getDB("PrivateMessages");
}

From source file:com.mycompany.Farmerama.contactWithOther.java

public contactWithOther(String collectionName) {
    Mongo mongo = new Mongo("localhost", 27017);
    db = mongo.getDB("PrivateMessages");
    PrivateMessages = db.getCollection(collectionName);

}

From source file:com.mycompany.Farmerama.contactWithOther.java

public contactWithOther(String thisname, String othername) {
    Mongo mongo = new Mongo("localhost", 27017);
    db = mongo.getDB("PrivateMessages");
    PrivateMessages = db.getCollection(thisname + "with" + othername);

}

From source file:com.mycompany.Farmerama.CreateOfferPage.java

public CreateOfferPage() {
    Mongo mongo = new Mongo("localhost", 27017);
    dbS = mongo.getDB("Sell");
    offerS = dbS.getCollection("offer");
    dbB = mongo.getDB("Buy");
    offerB = dbB.getCollection("offer");
}

From source file:com.mycompany.Farmerama.getAllAccounts.java

public getAllAccounts() {
    Mongo mongo = new Mongo("localhost", 27017);
    db = mongo.getDB("accounts");
    account = db.getCollection("account");

}