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, waitgetCodecRegistry, getLegacyDb, getSession, isTransactionActive, withSessiongetCodecFor, hasCodecForprotected 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
MongoDbFactoryMongoDatabase instance.getDb in interface MongoDbFactoryDataAccessExceptionpublic com.mongodb.client.MongoDatabase getDb(String dbName) throws DataAccessException
MongoDbFactoryDB instance to access the database with the given name.getDb in interface MongoDbFactorydbName - must not be null or empty.DataAccessExceptionprotected abstract com.mongodb.client.MongoDatabase doGetMongoDatabase(String dbName)
MongoDatabase from the client.dbName - must not be null or empty.public PersistenceExceptionTranslator getExceptionTranslator()
MongoDbFactoryMongoExceptionTranslator.getExceptionTranslator in interface MongoDbFactorypublic MongoDbFactory withSession(com.mongodb.client.ClientSession session)
MongoDbFactoryClientSession bound instance of MongoDbFactory returning MongoDatabase instances
that are aware and bound to the given session.withSession in interface MongoDbFactorysession - must not be null.protected abstract void closeClient()
protected C getMongoClient()
protected String getDefaultDatabaseName()
Copyright © 2011–2019 Pivotal Software, Inc.. All rights reserved.