C
- Client type.public abstract class MongoDbFactorySupport<C> extends Object implements MongoDbFactory
MongoClients
and MongoClient
defining common properties such as database name and exception translator.
Not intended to be used directly.SimpleMongoDbFactory
,
SimpleMongoClientDbFactory
Modifier | Constructor and Description |
---|---|
protected |
MongoDbFactorySupport(C mongoClient,
String databaseName,
boolean mongoInstanceCreated,
PersistenceExceptionTranslator exceptionTranslator)
Create a new
MongoDbFactorySupport object given mongoClient , databaseName ,
mongoInstanceCreated and PersistenceExceptionTranslator . |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
closeClient()
Close the client instance.
|
void |
destroy() |
protected abstract com.mongodb.client.MongoDatabase |
doGetMongoDatabase(String dbName)
Get the actual
MongoDatabase from the client. |
com.mongodb.client.MongoDatabase |
getDb()
Creates a default
MongoDatabase instance. |
com.mongodb.client.MongoDatabase |
getDb(String dbName)
Creates a
DB instance to access the database with the given name. |
protected String |
getDefaultDatabaseName() |
PersistenceExceptionTranslator |
getExceptionTranslator()
Exposes a shared
MongoExceptionTranslator . |
protected C |
getMongoClient() |
void |
setWriteConcern(com.mongodb.WriteConcern writeConcern)
Configures the
WriteConcern to be used on the MongoDatabase instance being created. |
MongoDbFactory |
withSession(com.mongodb.client.ClientSession session)
Obtain a
ClientSession bound instance of MongoDbFactory returning MongoDatabase instances
that are aware and bound to the given session. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCodecRegistry, getLegacyDb, getSession, withSession
getCodecFor, hasCodecFor
protected MongoDbFactorySupport(C mongoClient, String databaseName, boolean mongoInstanceCreated, PersistenceExceptionTranslator exceptionTranslator)
MongoDbFactorySupport
object given mongoClient
, databaseName
,
mongoInstanceCreated
and PersistenceExceptionTranslator
.mongoClient
- must not be null.databaseName
- must not be null or empty.mongoInstanceCreated
- true if the client instance was created by a subclass of
MongoDbFactorySupport
to close the client on destroy()
.exceptionTranslator
- must not be null.public void setWriteConcern(com.mongodb.WriteConcern writeConcern)
WriteConcern
to be used on the MongoDatabase
instance being created.writeConcern
- the writeConcern to setpublic com.mongodb.client.MongoDatabase getDb() throws DataAccessException
MongoDbFactory
MongoDatabase
instance.getDb
in interface MongoDbFactory
DataAccessException
public com.mongodb.client.MongoDatabase getDb(String dbName) throws DataAccessException
MongoDbFactory
DB
instance to access the database with the given name.getDb
in interface MongoDbFactory
dbName
- must not be null or empty.DataAccessException
protected abstract com.mongodb.client.MongoDatabase doGetMongoDatabase(String dbName)
MongoDatabase
from the client.dbName
- must not be null or empty.public PersistenceExceptionTranslator getExceptionTranslator()
MongoDbFactory
MongoExceptionTranslator
.getExceptionTranslator
in interface MongoDbFactory
public MongoDbFactory withSession(com.mongodb.client.ClientSession session)
MongoDbFactory
ClientSession
bound instance of MongoDbFactory
returning MongoDatabase
instances
that are aware and bound to the given session.withSession
in interface MongoDbFactory
session
- must not be null.protected abstract void closeClient()
protected C getMongoClient()
protected String getDefaultDatabaseName()
Copyright © 2011–2018 Pivotal Software, Inc.. All rights reserved.