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()
MongoDatabase
getName
in interface MongoDatabase
public CodecRegistry getCodecRegistry()
MongoDatabase
getCodecRegistry
in interface MongoDatabase
CodecRegistry
public ReadPreference getReadPreference()
MongoDatabase
getReadPreference
in interface MongoDatabase
ReadPreference
public WriteConcern getWriteConcern()
MongoDatabase
getWriteConcern
in interface MongoDatabase
WriteConcern
public ReadConcern getReadConcern()
MongoDatabase
getReadConcern
in interface MongoDatabase
ReadConcern
public MongoDatabase withCodecRegistry(CodecRegistry codecRegistry)
MongoDatabase
withCodecRegistry
in interface MongoDatabase
codecRegistry
- the new CodecRegistry
for the databasepublic MongoDatabase withReadPreference(ReadPreference readPreference)
MongoDatabase
withReadPreference
in interface MongoDatabase
readPreference
- the new ReadPreference
for the databasepublic MongoDatabase withWriteConcern(WriteConcern writeConcern)
MongoDatabase
withWriteConcern
in interface MongoDatabase
writeConcern
- the new WriteConcern
for the databasepublic MongoDatabase withReadConcern(ReadConcern readConcern)
MongoDatabase
withReadConcern
in interface MongoDatabase
readConcern
- the new ReadConcern
for the databasepublic MongoCollection<Document> getCollection(java.lang.String collectionName)
MongoDatabase
getCollection
in interface MongoDatabase
collectionName
- the name of the collection to returnMongoNamespace.checkCollectionNameValidity(String)
public <TDocument> MongoCollection<TDocument> getCollection(java.lang.String collectionName, java.lang.Class<TDocument> documentClass)
MongoDatabase
getCollection
in interface MongoDatabase
TDocument
- 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)
MongoDatabase
ReadPreference.primary()
.runCommand
in interface MongoDatabase
command
- the command to be runpublic Document runCommand(Bson command, ReadPreference readPreference)
MongoDatabase
runCommand
in interface MongoDatabase
command
- the command to be runreadPreference
- the ReadPreference
to be used when executing the commandpublic <TResult> TResult runCommand(Bson command, java.lang.Class<TResult> resultClass)
MongoDatabase
ReadPreference.primary()
.runCommand
in interface MongoDatabase
TResult
- 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)
MongoDatabase
runCommand
in interface MongoDatabase
TResult
- 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)
MongoDatabase
ReadPreference.primary()
.runCommand
in interface MongoDatabase
clientSession
- the client session with which to associate this operationcommand
- the command to be runpublic Document runCommand(ClientSession clientSession, Bson command, ReadPreference readPreference)
MongoDatabase
runCommand
in interface MongoDatabase
clientSession
- 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)
MongoDatabase
ReadPreference.primary()
.runCommand
in interface MongoDatabase
TResult
- 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)
MongoDatabase
runCommand
in interface MongoDatabase
TResult
- 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()
MongoDatabase
drop
in interface MongoDatabase
public void drop(ClientSession clientSession)
MongoDatabase
drop
in interface MongoDatabase
clientSession
- the client session with which to associate this operationprivate void executeDrop(ClientSession clientSession)
public MongoIterable<java.lang.String> listCollectionNames()
MongoDatabase
listCollectionNames
in interface MongoDatabase
public MongoIterable<java.lang.String> listCollectionNames(ClientSession clientSession)
MongoDatabase
listCollectionNames
in interface MongoDatabase
clientSession
- the client session with which to associate this operationprivate MongoIterable<java.lang.String> createListCollectionNamesIterable(ClientSession clientSession)
public ListCollectionsIterable<Document> listCollections()
MongoDatabase
listCollections
in interface MongoDatabase
public <TResult> ListCollectionsIterable<TResult> listCollections(java.lang.Class<TResult> resultClass)
MongoDatabase
listCollections
in interface MongoDatabase
TResult
- the target document type of the iterable.resultClass
- the class to decode each document intopublic ListCollectionsIterable<Document> listCollections(ClientSession clientSession)
MongoDatabase
listCollections
in interface MongoDatabase
clientSession
- the client session with which to associate this operationpublic <TResult> ListCollectionsIterable<TResult> listCollections(ClientSession clientSession, java.lang.Class<TResult> resultClass)
MongoDatabase
listCollections
in interface MongoDatabase
TResult
- 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)
MongoDatabase
createCollection
in interface MongoDatabase
collectionName
- the name for the new collection to createpublic void createCollection(java.lang.String collectionName, CreateCollectionOptions createCollectionOptions)
MongoDatabase
createCollection
in interface MongoDatabase
collectionName
- the name for the new collection to createcreateCollectionOptions
- various options for creating the collectionpublic void createCollection(ClientSession clientSession, java.lang.String collectionName)
MongoDatabase
createCollection
in interface MongoDatabase
clientSession
- 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)
MongoDatabase
createCollection
in interface MongoDatabase
clientSession
- 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)
MongoDatabase
createView
in interface MongoDatabase
viewName
- 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)
MongoDatabase
createView
in interface MongoDatabase
viewName
- 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)
MongoDatabase
createView
in interface MongoDatabase
clientSession
- 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)
MongoDatabase
createView
in interface MongoDatabase
clientSession
- 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)