Spring Data Document

org.springframework.data.mongodb.core
Class SimpleMongoDbFactory

java.lang.Object
  extended by org.springframework.data.mongodb.core.SimpleMongoDbFactory
All Implemented Interfaces:
DisposableBean, MongoDbFactory

public class SimpleMongoDbFactory
extends Object
implements DisposableBean, MongoDbFactory

Factory to create DB instances from a Mongo instance.

Author:
Mark Pollack, Oliver Gierke

Constructor Summary
SimpleMongoDbFactory(Mongo mongo, String databaseName)
          Create an instance of SimpleMongoDbFactory given the Mongo instance and database name.
SimpleMongoDbFactory(Mongo mongo, String databaseName, org.springframework.data.authentication.UserCredentials credentials)
          Create an instance of SimpleMongoDbFactory given the Mongo instance, database name, and username/password
SimpleMongoDbFactory(MongoURI uri)
          Creates a new SimpleMongoDbFactory instance from the given MongoURI.
 
Method Summary
 void destroy()
          Clean up the Mongo instance if it was created by the factory itself.
 DB getDb()
          Creates a default DB instance.
 DB getDb(String dbName)
          Creates a DB instance to access the database with the given name.
 void setWriteConcern(WriteConcern writeConcern)
          Configures the WriteConcern to be used on the DB instance being created.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleMongoDbFactory

public SimpleMongoDbFactory(Mongo mongo,
                            String databaseName)
Create an instance of SimpleMongoDbFactory given the Mongo instance and database name.

Parameters:
mongo - Mongo instance, must not be null.
databaseName - database name, not be null.

SimpleMongoDbFactory

public SimpleMongoDbFactory(Mongo mongo,
                            String databaseName,
                            org.springframework.data.authentication.UserCredentials credentials)
Create an instance of SimpleMongoDbFactory given the Mongo instance, database name, and username/password

Parameters:
mongo - Mongo instance, must not be null.
databaseName - Database name, must not be null.
credentials - username and password.

SimpleMongoDbFactory

public SimpleMongoDbFactory(MongoURI uri)
                     throws MongoException,
                            UnknownHostException
Creates a new SimpleMongoDbFactory instance from the given MongoURI.

Parameters:
uri - must not be null.
Throws:
MongoException
UnknownHostException
See Also:
MongoURI
Method Detail

setWriteConcern

public void setWriteConcern(WriteConcern writeConcern)
Configures the WriteConcern to be used on the DB instance being created.

Parameters:
writeConcern - the writeConcern to set

getDb

public DB getDb()
         throws DataAccessException
Description copied from interface: MongoDbFactory
Creates a default DB instance.

Specified by:
getDb in interface MongoDbFactory
Returns:
Throws:
DataAccessException

getDb

public DB getDb(String dbName)
         throws DataAccessException
Description copied from interface: MongoDbFactory
Creates a DB instance to access the database with the given name.

Specified by:
getDb in interface MongoDbFactory
Parameters:
dbName - must not be null or empty.
Returns:
Throws:
DataAccessException

destroy

public void destroy()
             throws Exception
Clean up the Mongo instance if it was created by the factory itself.

Specified by:
destroy in interface DisposableBean
Throws:
Exception
See Also:
DisposableBean.destroy()

Spring Data Document

Copyright © 2012. All Rights Reserved.