public class MongoClientFactory extends Object implements org.springframework.beans.factory.FactoryBean<com.mongodb.MongoClient>, org.springframework.beans.factory.DisposableBean
MongoClient instances.
The client will be closed by the factory Client code should retrieve the
DB instance and keep hold of it. The DB instance will be closed by this factory when the Spring context
shuts down.
It is really simple to create mongo instances and we need control over the location of usernames/password
combinations i.e. in most circumstances we don't want to put sensitive information in the URL. The
ability to fetch a database by name is therefore not an option.
The use of the Spring FactoryBean means that we can use an instance of this to inject DB instances
into the DAO layers directly.| Constructor and Description |
|---|
MongoClientFactory(com.mongodb.MongoClientURI mongoClientURI,
String username,
String password)
Create an instance of the factory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroy() |
com.mongodb.MongoClient |
getObject()
Get the Mongo client that this instance holds
|
Class<?> |
getObjectType() |
boolean |
isSingleton() |
static String |
toStringSafe(com.mongodb.MongoClientURI mongoClientURI)
Create a string that masks the username password from the uri
|
public MongoClientFactory(com.mongodb.MongoClientURI mongoClientURI,
String username,
String password)
mongoClientURI - the client URI, which must not reference a database, username or passwordusername - the username to use when connecting (null allowed and empty string is ignored)password - the user password for the database (null allowed and empty string is ignored)IllegalArgumentException - if the arguments are null when not allowed or contain invalid informationpublic static String toStringSafe(com.mongodb.MongoClientURI mongoClientURI)
mongoClientURI - a mongo client URIpublic com.mongodb.MongoClient getObject()
getObject in interface org.springframework.beans.factory.FactoryBean<com.mongodb.MongoClient>public Class<?> getObjectType()
getObjectType in interface org.springframework.beans.factory.FactoryBean<com.mongodb.MongoClient>public boolean isSingleton()
isSingleton in interface org.springframework.beans.factory.FactoryBean<com.mongodb.MongoClient>public void destroy()
destroy in interface org.springframework.beans.factory.DisposableBeanCopyright © 2005–2018 Alfresco Software. All rights reserved.