Class MongoDbAccess
java.lang.Object
fr.gouv.vitam.common.database.server.mongodb.MongoDbAccess
- All Implemented Interfaces:
DatabaseConnection
- Direct Known Subclasses:
LogbookMongoDbAccessImpl
,MongoDbAccessAdminImpl
,MongoDbAccessMetadataImpl
,SimpleMongoDBAccess
MongoDbAccess interface
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Check the connection of the databasevoid
close()
Close database accessstatic com.mongodb.client.MongoClient
createMongoClient
(DbConfiguration configuration) Create a mongoDB client according to the configuration and using the MongoClientOptions specific to the sub-systems (ex: metadata,logbook)static com.mongodb.client.MongoClient
createMongoClient
(DbConfiguration configuration, List<Class<?>> classList) getInfo()
Get information on a Databasecom.mongodb.client.MongoDatabase
com.mongodb.client.MongoClient
static com.mongodb.MongoClientSettings.Builder
getMongoClientSettingsBuilder
(Class<?>... classes) static com.mongodb.MongoClientSettings.Builder
getMongoClientSettingsBuilder
(List<Class<?>> classList) com.mongodb.client.MongoDatabase
void
setDatabase
(String dbname) Change the target databasesetMongoAdmin
(com.mongodb.client.MongoDatabase mongoAdmin) setMongoClient
(com.mongodb.client.MongoClient mongoClient) setMongoDatabase
(com.mongodb.client.MongoDatabase mongoDatabase)
-
Constructor Details
-
MongoDbAccess
- Parameters:
mongoClient
- MongoClientdbname
- MongoDB database name- Throws:
IllegalArgumentException
- if mongoClient or dbname is null
-
-
Method Details
-
checkConnection
public boolean checkConnection()Description copied from interface:DatabaseConnection
Check the connection of the database- Specified by:
checkConnection
in interfaceDatabaseConnection
- Returns:
- True if the connection is active
-
getMongoClient
public com.mongodb.client.MongoClient getMongoClient()- Returns:
- MongoClient
-
setMongoClient
- Parameters:
mongoClient
- MongoClient- Returns:
- MongoDbAccess
-
getMongoDatabase
public com.mongodb.client.MongoDatabase getMongoDatabase()- Returns:
- MongoDatabase
-
setMongoDatabase
- Parameters:
mongoDatabase
- MongoDatabase- Returns:
- MongoDbAccess
-
getMongoAdmin
public com.mongodb.client.MongoDatabase getMongoAdmin()- Returns:
- MongoDatabase
-
setMongoAdmin
- Parameters:
mongoAdmin
- MongoDatabase- Returns:
- MongoDbAccess
-
close
public void close()Close database access -
getInfo
Description copied from interface:DatabaseConnection
Get information on a Database- Specified by:
getInfo
in interfaceDatabaseConnection
- Returns:
- information on the database
-
createMongoClient
Create a mongoDB client according to the configuration and using the MongoClientOptions specific to the sub-systems (ex: metadata,logbook)- Parameters:
configuration
- the configuration of mongo client (host/port to connect)- Returns:
- the MongoClient
-
createMongoClient
public static com.mongodb.client.MongoClient createMongoClient(DbConfiguration configuration, List<Class<?>> classList) -
getMongoClientSettingsBuilder
public static com.mongodb.MongoClientSettings.Builder getMongoClientSettingsBuilder(Class<?>... classes) -
getMongoClientSettingsBuilder
-
setDatabase
Change the target database- Parameters:
dbname
- Name of the target database
-