class MongoDatabaseImpl extends java.lang.Object implements MongoDatabase
| Modifier and Type | Field and Description |
|---|---|
private CodecRegistry |
codecRegistry |
private OperationExecutor |
executor |
private java.lang.String |
name |
private ReadConcern |
readConcern |
private ReadPreference |
readPreference |
private boolean |
retryWrites |
private WriteConcern |
writeConcern |
| Constructor and Description |
|---|
MongoDatabaseImpl(java.lang.String name,
CodecRegistry codecRegistry,
ReadPreference readPreference,
WriteConcern writeConcern,
boolean retryWrites,
ReadConcern readConcern,
OperationExecutor executor) |
| Modifier and Type | Method and Description |
|---|---|
private java.util.List<BsonDocument> |
createBsonDocumentList(java.util.List<? extends Bson> pipeline) |
void |
createCollection(ClientSession clientSession,
java.lang.String collectionName)
Create a new collection with the given name.
|
void |
createCollection(ClientSession clientSession,
java.lang.String collectionName,
CreateCollectionOptions createCollectionOptions)
Create a new collection with the selected options
|
void |
createCollection(java.lang.String collectionName)
Create a new collection with the given name.
|
void |
createCollection(java.lang.String collectionName,
CreateCollectionOptions createCollectionOptions)
Create a new collection with the selected options
|
private MongoIterable<java.lang.String> |
createListCollectionNamesIterable(ClientSession clientSession) |
private <TResult> ListCollectionsIterable<TResult> |
createListCollectionsIterable(ClientSession clientSession,
java.lang.Class<TResult> resultClass) |
void |
createView(ClientSession clientSession,
java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline)
Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.
|
void |
createView(ClientSession clientSession,
java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline,
CreateViewOptions createViewOptions)
Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view.
|
void |
createView(java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline)
Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.
|
void |
createView(java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline,
CreateViewOptions createViewOptions)
Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view.
|
void |
drop()
Drops this database.
|
void |
drop(ClientSession clientSession)
Drops this database.
|
private <TResult> TResult |
executeCommand(ClientSession clientSession,
Bson command,
ReadPreference readPreference,
java.lang.Class<TResult> resultClass) |
private void |
executeCreateCollection(ClientSession clientSession,
java.lang.String collectionName,
CreateCollectionOptions createCollectionOptions) |
private void |
executeCreateView(ClientSession clientSession,
java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline,
CreateViewOptions createViewOptions) |
private void |
executeDrop(ClientSession clientSession) |
CodecRegistry |
getCodecRegistry()
Get the codec registry for the MongoDatabase.
|
MongoCollection<Document> |
getCollection(java.lang.String collectionName)
Gets a collection.
|
<TDocument> |
getCollection(java.lang.String collectionName,
java.lang.Class<TDocument> documentClass)
Gets a collection, with a specific default document class.
|
java.lang.String |
getName()
Gets the name of the database.
|
ReadConcern |
getReadConcern()
Get the read concern for the MongoDatabase.
|
ReadPreference |
getReadPreference()
Get the read preference for the MongoDatabase.
|
WriteConcern |
getWriteConcern()
Get the write concern for the MongoDatabase.
|
MongoIterable<java.lang.String> |
listCollectionNames()
Gets the names of all the collections in this database.
|
MongoIterable<java.lang.String> |
listCollectionNames(ClientSession clientSession)
Gets the names of all the collections in this database.
|
ListCollectionsIterable<Document> |
listCollections()
Finds all the collections in this database.
|
<TResult> ListCollectionsIterable<TResult> |
listCollections(java.lang.Class<TResult> resultClass)
Finds all the collections in this database.
|
ListCollectionsIterable<Document> |
listCollections(ClientSession clientSession)
Finds all the collections in this database.
|
<TResult> ListCollectionsIterable<TResult> |
listCollections(ClientSession clientSession,
java.lang.Class<TResult> resultClass)
Finds all the collections in this database.
|
Document |
runCommand(Bson command)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary(). |
<TResult> TResult |
runCommand(Bson command,
java.lang.Class<TResult> resultClass)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary(). |
Document |
runCommand(Bson command,
ReadPreference readPreference)
Executes the given command in the context of the current database with the given read preference.
|
<TResult> TResult |
runCommand(Bson command,
ReadPreference readPreference,
java.lang.Class<TResult> resultClass)
Executes the given command in the context of the current database with the given read preference.
|
Document |
runCommand(ClientSession clientSession,
Bson command)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary(). |
<TResult> TResult |
runCommand(ClientSession clientSession,
Bson command,
java.lang.Class<TResult> resultClass)
Executes the given command in the context of the current database with a read preference of
ReadPreference.primary(). |
Document |
runCommand(ClientSession clientSession,
Bson command,
ReadPreference readPreference)
Executes the given command in the context of the current database with the given read preference.
|
<TResult> TResult |
runCommand(ClientSession clientSession,
Bson command,
ReadPreference readPreference,
java.lang.Class<TResult> resultClass)
Executes the given command in the context of the current database with the given read preference.
|
private BsonDocument |
toBsonDocument(Bson document) |
MongoDatabase |
withCodecRegistry(CodecRegistry codecRegistry)
Create a new MongoDatabase instance with a different codec registry.
|
MongoDatabase |
withReadConcern(ReadConcern readConcern)
Create a new MongoDatabase instance with a different read concern.
|
MongoDatabase |
withReadPreference(ReadPreference readPreference)
Create a new MongoDatabase instance with a different read preference.
|
MongoDatabase |
withWriteConcern(WriteConcern writeConcern)
Create a new MongoDatabase instance with a different write concern.
|
private final java.lang.String name
private final ReadPreference readPreference
private final CodecRegistry codecRegistry
private final WriteConcern writeConcern
private final boolean retryWrites
private final ReadConcern readConcern
private final OperationExecutor executor
MongoDatabaseImpl(java.lang.String name,
CodecRegistry codecRegistry,
ReadPreference readPreference,
WriteConcern writeConcern,
boolean retryWrites,
ReadConcern readConcern,
OperationExecutor executor)
public java.lang.String getName()
MongoDatabasegetName in interface MongoDatabasepublic CodecRegistry getCodecRegistry()
MongoDatabasegetCodecRegistry in interface MongoDatabaseCodecRegistrypublic ReadPreference getReadPreference()
MongoDatabasegetReadPreference in interface MongoDatabaseReadPreferencepublic WriteConcern getWriteConcern()
MongoDatabasegetWriteConcern in interface MongoDatabaseWriteConcernpublic ReadConcern getReadConcern()
MongoDatabasegetReadConcern in interface MongoDatabaseReadConcernpublic MongoDatabase withCodecRegistry(CodecRegistry codecRegistry)
MongoDatabasewithCodecRegistry in interface MongoDatabasecodecRegistry - the new CodecRegistry for the databasepublic MongoDatabase withReadPreference(ReadPreference readPreference)
MongoDatabasewithReadPreference in interface MongoDatabasereadPreference - the new ReadPreference for the databasepublic MongoDatabase withWriteConcern(WriteConcern writeConcern)
MongoDatabasewithWriteConcern in interface MongoDatabasewriteConcern - the new WriteConcern for the databasepublic MongoDatabase withReadConcern(ReadConcern readConcern)
MongoDatabasewithReadConcern in interface MongoDatabasereadConcern - the new ReadConcern for the databasepublic MongoCollection<Document> getCollection(java.lang.String collectionName)
MongoDatabasegetCollection in interface MongoDatabasecollectionName - the name of the collection to returnMongoNamespace.checkCollectionNameValidity(String)public <TDocument> MongoCollection<TDocument> getCollection(java.lang.String collectionName, java.lang.Class<TDocument> documentClass)
MongoDatabasegetCollection in interface MongoDatabaseTDocument - the type of the class to use instead of Document.collectionName - the name of the collection to returndocumentClass - the default class to cast any documents returned from the database into.public Document runCommand(Bson command)
MongoDatabaseReadPreference.primary().runCommand in interface MongoDatabasecommand - the command to be runpublic Document runCommand(Bson command, ReadPreference readPreference)
MongoDatabaserunCommand in interface MongoDatabasecommand - the command to be runreadPreference - the ReadPreference to be used when executing the commandpublic <TResult> TResult runCommand(Bson command, java.lang.Class<TResult> resultClass)
MongoDatabaseReadPreference.primary().runCommand in interface MongoDatabaseTResult - the type of the class to use instead of Document.command - the command to be runresultClass - the class to decode each document intopublic <TResult> TResult runCommand(Bson command, ReadPreference readPreference, java.lang.Class<TResult> resultClass)
MongoDatabaserunCommand in interface MongoDatabaseTResult - the type of the class to use instead of Document.command - the command to be runreadPreference - the ReadPreference to be used when executing the commandresultClass - the class to decode each document intopublic Document runCommand(ClientSession clientSession, Bson command)
MongoDatabaseReadPreference.primary().runCommand in interface MongoDatabaseclientSession - the client session with which to associate this operationcommand - the command to be runpublic Document runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference)
MongoDatabaserunCommand in interface MongoDatabaseclientSession - the client session with which to associate this operationcommand - the command to be runreadPreference - the ReadPreference to be used when executing the commandpublic <TResult> TResult runCommand(ClientSession clientSession, Bson command, java.lang.Class<TResult> resultClass)
MongoDatabaseReadPreference.primary().runCommand in interface MongoDatabaseTResult - the type of the class to use instead of Document.clientSession - the client session with which to associate this operationcommand - the command to be runresultClass - the class to decode each document intopublic <TResult> TResult runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference, java.lang.Class<TResult> resultClass)
MongoDatabaserunCommand in interface MongoDatabaseTResult - the type of the class to use instead of Document.clientSession - the client session with which to associate this operationcommand - the command to be runreadPreference - the ReadPreference to be used when executing the commandresultClass - the class to decode each document intoprivate <TResult> TResult executeCommand(ClientSession clientSession, Bson command, ReadPreference readPreference, java.lang.Class<TResult> resultClass)
public void drop()
MongoDatabasedrop in interface MongoDatabasepublic void drop(ClientSession clientSession)
MongoDatabasedrop in interface MongoDatabaseclientSession - the client session with which to associate this operationprivate void executeDrop(ClientSession clientSession)
public MongoIterable<java.lang.String> listCollectionNames()
MongoDatabaselistCollectionNames in interface MongoDatabasepublic MongoIterable<java.lang.String> listCollectionNames(ClientSession clientSession)
MongoDatabaselistCollectionNames in interface MongoDatabaseclientSession - the client session with which to associate this operationprivate MongoIterable<java.lang.String> createListCollectionNamesIterable(ClientSession clientSession)
public ListCollectionsIterable<Document> listCollections()
MongoDatabaselistCollections in interface MongoDatabasepublic <TResult> ListCollectionsIterable<TResult> listCollections(java.lang.Class<TResult> resultClass)
MongoDatabaselistCollections in interface MongoDatabaseTResult - the target document type of the iterable.resultClass - the class to decode each document intopublic ListCollectionsIterable<Document> listCollections(ClientSession clientSession)
MongoDatabaselistCollections in interface MongoDatabaseclientSession - the client session with which to associate this operationpublic <TResult> ListCollectionsIterable<TResult> listCollections(ClientSession clientSession, java.lang.Class<TResult> resultClass)
MongoDatabaselistCollections in interface MongoDatabaseTResult - the target document type of the iterable.clientSession - the client session with which to associate this operationresultClass - the class to decode each document intoprivate <TResult> ListCollectionsIterable<TResult> createListCollectionsIterable(ClientSession clientSession, java.lang.Class<TResult> resultClass)
public void createCollection(java.lang.String collectionName)
MongoDatabasecreateCollection in interface MongoDatabasecollectionName - the name for the new collection to createpublic void createCollection(java.lang.String collectionName,
CreateCollectionOptions createCollectionOptions)
MongoDatabasecreateCollection in interface MongoDatabasecollectionName - the name for the new collection to createcreateCollectionOptions - various options for creating the collectionpublic void createCollection(ClientSession clientSession, java.lang.String collectionName)
MongoDatabasecreateCollection in interface MongoDatabaseclientSession - the client session with which to associate this operationcollectionName - the name for the new collection to createpublic void createCollection(ClientSession clientSession, java.lang.String collectionName, CreateCollectionOptions createCollectionOptions)
MongoDatabasecreateCollection in interface MongoDatabaseclientSession - the client session with which to associate this operationcollectionName - the name for the new collection to createcreateCollectionOptions - various options for creating the collectionprivate void executeCreateCollection(ClientSession clientSession, java.lang.String collectionName, CreateCollectionOptions createCollectionOptions)
public void createView(java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline)
MongoDatabasecreateView in interface MongoDatabaseviewName - the name of the view to createviewOn - the backing collection/view for the viewpipeline - the pipeline that defines the viewpublic void createView(java.lang.String viewName,
java.lang.String viewOn,
java.util.List<? extends Bson> pipeline,
CreateViewOptions createViewOptions)
MongoDatabasecreateView in interface MongoDatabaseviewName - the name of the view to createviewOn - the backing collection/view for the viewpipeline - the pipeline that defines the viewcreateViewOptions - various options for creating the viewpublic void createView(ClientSession clientSession, java.lang.String viewName, java.lang.String viewOn, java.util.List<? extends Bson> pipeline)
MongoDatabasecreateView in interface MongoDatabaseclientSession - the client session with which to associate this operationviewName - the name of the view to createviewOn - the backing collection/view for the viewpipeline - the pipeline that defines the viewpublic void createView(ClientSession clientSession, java.lang.String viewName, java.lang.String viewOn, java.util.List<? extends Bson> pipeline, CreateViewOptions createViewOptions)
MongoDatabasecreateView in interface MongoDatabaseclientSession - the client session with which to associate this operationviewName - the name of the view to createviewOn - the backing collection/view for the viewpipeline - the pipeline that defines the viewcreateViewOptions - various options for creating the viewprivate void executeCreateView(ClientSession clientSession, java.lang.String viewName, java.lang.String viewOn, java.util.List<? extends Bson> pipeline, CreateViewOptions createViewOptions)
private java.util.List<BsonDocument> createBsonDocumentList(java.util.List<? extends Bson> pipeline)
private BsonDocument toBsonDocument(Bson document)