C - Client type.public abstract class MongoDatabaseFactorySupport<C> extends Object implements MongoDatabaseFactory
MongoClients defining common properties such as
database name and exception translator.
SimpleMongoClientDatabaseFactory| Modifier | Constructor and Description |
|---|---|
protected |
MongoDatabaseFactorySupport(C mongoClient,
String databaseName,
boolean mongoInstanceCreated,
PersistenceExceptionTranslator exceptionTranslator)
Create a new
MongoDatabaseFactorySupport 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. |
protected String |
getDefaultDatabaseName() |
PersistenceExceptionTranslator |
getExceptionTranslator()
Exposes a shared
MongoExceptionTranslator. |
protected C |
getMongoClient() |
com.mongodb.client.MongoDatabase |
getMongoDatabase()
Obtain a
MongoDatabase from the underlying factory. |
com.mongodb.client.MongoDatabase |
getMongoDatabase(String dbName)
Obtain a
MongoDatabase instance to access the database with the given name. |
void |
setWriteConcern(com.mongodb.WriteConcern writeConcern)
Configures the
WriteConcern to be used on the MongoDatabase instance being created. |
MongoDatabaseFactory |
withSession(com.mongodb.client.ClientSession session)
Obtain a
ClientSession bound instance of MongoDatabaseFactory returning MongoDatabase
instances that are aware and bound to the given session. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetCodecRegistry, getSession, isTransactionActive, withSessiongetCodecFor, hasCodecForprotected MongoDatabaseFactorySupport(C mongoClient, String databaseName, boolean mongoInstanceCreated, PersistenceExceptionTranslator exceptionTranslator)
MongoDatabaseFactorySupport 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
MongoDatabaseFactorySupport 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 getMongoDatabase()
throws DataAccessException
MongoDatabaseFactoryMongoDatabase from the underlying factory.getMongoDatabase in interface MongoDatabaseFactoryDataAccessExceptionpublic com.mongodb.client.MongoDatabase getMongoDatabase(String dbName) throws DataAccessException
MongoDatabaseFactoryMongoDatabase instance to access the database with the given name.getMongoDatabase in interface MongoDatabaseFactorydbName - must not be null.DataAccessExceptionprotected abstract com.mongodb.client.MongoDatabase doGetMongoDatabase(String dbName)
MongoDatabase from the client.dbName - must not be null or empty.public PersistenceExceptionTranslator getExceptionTranslator()
MongoDatabaseFactoryMongoExceptionTranslator.getExceptionTranslator in interface MongoDatabaseFactorypublic MongoDatabaseFactory withSession(com.mongodb.client.ClientSession session)
MongoDatabaseFactoryClientSession bound instance of MongoDatabaseFactory returning MongoDatabase
instances that are aware and bound to the given session.withSession in interface MongoDatabaseFactorysession - must not be null.protected abstract void closeClient()
protected C getMongoClient()
protected String getDefaultDatabaseName()
Copyright © 2011–2022 Pivotal Software, Inc.. All rights reserved.