public class MongoDatabaseImpl extends Object implements MongoDatabase
MongoDatabase
interface.Modifier and Type | Field and Description |
---|---|
static Document |
EMPTY_QUERY
An empty query document.
|
protected Client |
myClient
The client for interacting with MongoDB.
|
ADMIN_NAME, CONFIG_NAME, LOCAL_NAME, TEST_NAME
Constructor and Description |
---|
MongoDatabaseImpl(MongoClient mongoClient,
Client client,
String name)
Create a new MongoDatabaseClient.
|
Modifier and Type | Method and Description |
---|---|
protected void |
addOptions(String command,
DocumentAssignable options,
DocumentBuilder builder)
Adds the options to the document builder.
|
boolean |
createCappedCollection(String name,
long size)
Creates the capped collection with the specified name and size on the
server.
|
boolean |
createCollection(String name,
DocumentAssignable options)
Creates the collection with the specified name on the server.
|
boolean |
drop()
Drops the database.
|
boolean |
exists()
Returns true if this database already exists on the server.
|
MongoCollection |
getCollection(String name)
Returns the MongoCollection with the specified name.
|
Durability |
getDurability()
Returns the durability for write operations sent to the server from this
MongoDatabase instance. |
protected LockType |
getLockType()
Returns the type of lock to use.
|
String |
getName()
Returns the name of the database.
|
ProfilingStatus |
getProfilingStatus()
Retrieves the profiling level for the database.
|
ReadPreference |
getReadPreference()
Returns the read preference for queries from this
MongoDatabase
instance. |
List<String> |
listCollectionNames()
Returns the list of the collections contained within the database.
|
List<String> |
listCollections()
Deprecated.
|
Document |
runAdminCommand(String command)
Runs an administrative command against the 'admin' database.
|
Document |
runAdminCommand(String command,
DocumentAssignable options)
Runs an administrative command against the 'admin' database.
|
Document |
runAdminCommand(String commandName,
String commandValue,
DocumentAssignable options)
Runs an administrative command against the 'admin' database.
|
Document |
runCommand(DocumentAssignable command)
Runs a command against the database.
|
Document |
runCommand(String command)
Runs a command against the database.
|
Document |
runCommand(String command,
DocumentAssignable options)
Runs a command against the database.
|
Document |
runCommand(String commandName,
int commandValue,
DocumentAssignable options)
Runs a command against the database.
|
Document |
runCommand(String commandName,
String commandValue,
DocumentAssignable options)
Runs a command against the database.
|
void |
runCommandAsync(Callback<Document> reply,
DocumentAssignable command)
Runs a command against the database.
|
void |
runCommandAsync(Callback<Document> reply,
DocumentAssignable command,
Version requireServerVersion)
Runs a command against the database.
|
void |
runCommandAsync(Callback<Document> reply,
String command)
Runs a command against the database.
|
void |
runCommandAsync(Callback<Document> reply,
String command,
DocumentAssignable options)
Runs a command against the database.
|
void |
runCommandAsync(Callback<Document> reply,
String commandName,
int commandValue,
DocumentAssignable options)
Runs a command against the database.
|
void |
runCommandAsync(Callback<Document> reply,
String commandName,
String commandValue,
DocumentAssignable options)
Runs a command against the database.
|
ListenableFuture<Document> |
runCommandAsync(DocumentAssignable command)
Runs a command against the database.
|
void |
runCommandAsync(LambdaCallback<Document> reply,
DocumentAssignable command)
Runs a command against the database.
|
void |
runCommandAsync(LambdaCallback<Document> reply,
DocumentAssignable command,
Version requiredServerVersion)
Runs a command against the database.
|
void |
runCommandAsync(LambdaCallback<Document> reply,
String command)
Runs a command against the database.
|
void |
runCommandAsync(LambdaCallback<Document> reply,
String command,
DocumentAssignable options)
Runs a command against the database.
|
void |
runCommandAsync(LambdaCallback<Document> reply,
String commandName,
int commandValue,
DocumentAssignable options)
Runs a command against the database.
|
void |
runCommandAsync(LambdaCallback<Document> reply,
String commandName,
String commandValue,
DocumentAssignable options)
Runs a command against the database.
|
ListenableFuture<Document> |
runCommandAsync(String command)
Runs a command against the database.
|
ListenableFuture<Document> |
runCommandAsync(String command,
DocumentAssignable options)
Runs a command against the database.
|
ListenableFuture<Document> |
runCommandAsync(String commandName,
int commandValue,
DocumentAssignable options)
Runs a command against the database.
|
ListenableFuture<Document> |
runCommandAsync(String commandName,
String commandValue,
DocumentAssignable options)
Runs a command against the database.
|
void |
setDurability(Durability durability)
Sets the durability for write operations from this
MongoDatabase
instance. |
boolean |
setProfilingStatus(ProfilingStatus profileLevel)
Sets the profiling level for the database.
|
void |
setReadPreference(ReadPreference readPreference)
Sets the value of the read preference for a queries from this
MongoDatabase instance. |
Document |
stats()
Returns the statistics for the database.
|
public static final Document EMPTY_QUERY
protected final Client myClient
public MongoDatabaseImpl(MongoClient mongoClient, Client client, String name)
mongoClient
- The MongoClient
.client
- The client for interacting with MongoDB.name
- The name of the database we interact with.public boolean createCappedCollection(String name, long size) throws MongoDbException
Issues a command to create the collection with the specified name and options.
createCappedCollection
in interface MongoDatabase
name
- The name of the collection.size
- The size of the collection in bytes.MongoDbException
- On a failure to create the collection.public boolean createCollection(String name, DocumentAssignable options) throws MongoDbException
Issues a command to create the collection with the specified name and options.
createCollection
in interface MongoDatabase
name
- The name of the collection.options
- The options for the collection being created.MongoDbException
- On a failure to create the collection.public boolean drop()
Overridden to issue a "dropDatabase" command.
drop
in interface MongoDatabase
MongoDatabase.drop()
public boolean exists()
This method is simply a helper name to check if this database's name
appears in the parent client's
list of databases.
exists
in interface MongoDatabase
public MongoCollection getCollection(String name)
Overridden to create a new SynchronousMongoCollectionImpl
.
getCollection
in interface MongoDatabase
name
- The name of the collection.MongoCollection
.MongoDatabase.getCollection(String)
public Durability getDurability()
MongoDatabase
instance.
Defaults to the Durability
from the Mongo
's
configuration.
getDurability
in interface MongoDatabase
MongoClientConfiguration.getDefaultDurability()
public String getName()
getName
in interface MongoDatabase
public ProfilingStatus getProfilingStatus() throws MongoDbException
Overridden to query the system.namespace collection for the names of all of the collections.
getProfilingStatus
in interface MongoDatabase
MongoDbException
- On a failure to create the collection.MongoDatabase.getProfilingStatus()
public ReadPreference getReadPreference()
MongoDatabase
instance.
Defaults to ReadPreference
from the Mongo
's
configuration.
getReadPreference
in interface MongoDatabase
MongoClientConfiguration.getDefaultReadPreference()
public List<String> listCollectionNames()
Overridden to query the system.namespace collection for the names of all of the collections.
listCollectionNames
in interface MongoDatabase
MongoDatabase.listCollectionNames()
@Deprecated public List<String> listCollections()
Overridden to query the system.namespace collection for the names of all of the collections.
listCollections
in interface MongoDatabase
MongoDatabase.listCollectionNames()
public Document runAdminCommand(String command) throws MongoDbException
Overridden to call runCommand(String)
on the 'admin' database.
runAdminCommand
in interface MongoDatabase
command
- The name of the command to run.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(String, DocumentAssignable)
public Document runAdminCommand(String command, DocumentAssignable options) throws MongoDbException
Overridden to call the
runCommandAsync(String, DocumentAssignable)
method.
runAdminCommand
in interface MongoDatabase
command
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(String, DocumentAssignable)
public Document runAdminCommand(String commandName, String commandValue, DocumentAssignable options) throws MongoDbException
Overridden to call the
runCommandAsync(String, String, DocumentAssignable)
method.
runAdminCommand
in interface MongoDatabase
commandName
- The name of the command to run.commandValue
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(String, String, DocumentAssignable)
public Document runCommand(DocumentAssignable command) throws MongoDbException
Overridden to call the runCommandAsync(DocumentAssignable)
method.
runCommand
in interface MongoDatabase
command
- The command document to run.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(DocumentAssignable)
public Document runCommand(String command) throws MongoDbException
Overridden to call the
runCommandAsync(String, DocumentAssignable)
method with
null
options.
runCommand
in interface MongoDatabase
command
- The name of the command to run.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(String, DocumentAssignable)
public Document runCommand(String command, DocumentAssignable options) throws MongoDbException
Overridden to call the
runCommandAsync(String, DocumentAssignable)
method.
runCommand
in interface MongoDatabase
command
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(String, DocumentAssignable)
public Document runCommand(String commandName, int commandValue, DocumentAssignable options) throws MongoDbException
Overridden to call the
runCommandAsync(String, int, DocumentAssignable)
method.
runCommand
in interface MongoDatabase
commandName
- The name of the command to run.commandValue
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(String, int, DocumentAssignable)
public Document runCommand(String commandName, String commandValue, DocumentAssignable options) throws MongoDbException
Overridden to call the
runCommandAsync(String, String, DocumentAssignable)
method.
runCommand
in interface MongoDatabase
commandName
- The name of the command to run.commandValue
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(String, String, DocumentAssignable)
public void runCommandAsync(Callback<Document> reply, DocumentAssignable command) throws MongoDbException
Overridden to call the
runCommandAsync(Callback, DocumentAssignable, Version)
method
with null
as the version.
runCommandAsync
in interface MongoDatabase
reply
- Callback
that will be notified of the command results.command
- The command document to run.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(Callback, DocumentAssignable, Version)
public void runCommandAsync(Callback<Document> reply, DocumentAssignable command, Version requireServerVersion) throws MongoDbException
Overridden to build a Command
message and send it to the server.
runCommandAsync
in interface MongoDatabase
reply
- Callback
that will be notified of the command results.command
- The command document to run.requireServerVersion
- The minimum required server version to support the command.MongoDbException
- On an error issuing the command or in running the commandpublic void runCommandAsync(Callback<Document> reply, String command) throws MongoDbException
Overridden to call the
runCommandAsync(Callback, String, DocumentAssignable)
method
with null
for the options.
runCommandAsync
in interface MongoDatabase
reply
- Callback
that will be notified of the command results.command
- The name of the command to run.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(Callback, String, DocumentAssignable)
public void runCommandAsync(Callback<Document> reply, String command, DocumentAssignable options) throws MongoDbException
Overridden to build the command document and call
runCommandAsync(Callback, DocumentAssignable)
.
runCommandAsync
in interface MongoDatabase
reply
- Callback
that will be notified of the command results.command
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandpublic void runCommandAsync(Callback<Document> reply, String commandName, int commandValue, DocumentAssignable options) throws MongoDbException
Overridden to build the command document and call
runCommandAsync(Callback, DocumentAssignable)
.
runCommandAsync
in interface MongoDatabase
reply
- Callback
that will be notified of the command results.commandName
- The name of the command to run.commandValue
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandpublic void runCommandAsync(Callback<Document> reply, String commandName, String commandValue, DocumentAssignable options) throws MongoDbException
Overridden to build the command document and call
runCommandAsync(Callback, DocumentAssignable)
.
runCommandAsync
in interface MongoDatabase
reply
- Callback
that will be notified of the command results.commandName
- The name of the command to run.commandValue
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandpublic ListenableFuture<Document> runCommandAsync(DocumentAssignable command) throws MongoDbException
Overridden to call the
runCommandAsync(Callback, DocumentAssignable)
method.
runCommandAsync
in interface MongoDatabase
command
- The command document to run.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(Callback, DocumentAssignable)
public void runCommandAsync(LambdaCallback<Document> reply, DocumentAssignable command) throws MongoDbException
Overridden to call runCommandAsync(Callback, DocumentAssignable)
with an adapter for the LambdaCallback
.
runCommandAsync
in interface MongoDatabase
reply
- LambdaCallback
that will be notified of the command
results.command
- The command document to run.MongoDbException
- On an error issuing the command or in running the commandpublic void runCommandAsync(LambdaCallback<Document> reply, DocumentAssignable command, Version requiredServerVersion) throws MongoDbException
Overridden to call
runCommandAsync(Callback, DocumentAssignable, Version)
with an
adapter for the LambdaCallback
.
runCommandAsync
in interface MongoDatabase
reply
- LambdaCallback
that will be notified of the command
results.command
- The command document to run.requiredServerVersion
- The minimum required server version to support the command.MongoDbException
- On an error issuing the command or in running the commandpublic void runCommandAsync(LambdaCallback<Document> reply, String command) throws MongoDbException
Overridden to call runCommandAsync(Callback, String)
with an
adapter for the LambdaCallback
.
runCommandAsync
in interface MongoDatabase
reply
- LambdaCallback
that will be notified of the command
results.command
- The name of the command to run.MongoDbException
- On an error issuing the command or in running the commandpublic void runCommandAsync(LambdaCallback<Document> reply, String command, DocumentAssignable options) throws MongoDbException
Overridden to call
runCommandAsync(Callback, String, DocumentAssignable)
with an
adapter for the LambdaCallback
.
runCommandAsync
in interface MongoDatabase
reply
- LambdaCallback
that will be notified of the command
results.command
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandpublic void runCommandAsync(LambdaCallback<Document> reply, String commandName, int commandValue, DocumentAssignable options) throws MongoDbException
Overridden to call
runCommandAsync(Callback, String, int, DocumentAssignable)
with
an adapter for the LambdaCallback
.
runCommandAsync
in interface MongoDatabase
reply
- LambdaCallback
that will be notified of the command
results.commandName
- The name of the command to run.commandValue
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandpublic void runCommandAsync(LambdaCallback<Document> reply, String commandName, String commandValue, DocumentAssignable options) throws MongoDbException
Overridden to call
runCommandAsync(Callback, String, String, DocumentAssignable)
with an adapter for the LambdaCallback
.
runCommandAsync
in interface MongoDatabase
reply
- LambdaCallback
that will be notified of the command
results.commandName
- The name of the command to run.commandValue
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandpublic ListenableFuture<Document> runCommandAsync(String command) throws MongoDbException
Overridden to call the
runCommandAsync(Callback, String, DocumentAssignable)
method
with null
options.
runCommandAsync
in interface MongoDatabase
command
- The name of the command to run.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(Callback, String, DocumentAssignable)
public ListenableFuture<Document> runCommandAsync(String command, DocumentAssignable options) throws MongoDbException
Overridden to call the
runCommandAsync(Callback, String, DocumentAssignable)
method.
runCommandAsync
in interface MongoDatabase
command
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(Callback, String, DocumentAssignable)
public ListenableFuture<Document> runCommandAsync(String commandName, int commandValue, DocumentAssignable options) throws MongoDbException
Overridden to call the
runCommandAsync(Callback, String, int, DocumentAssignable)
method.
runCommandAsync
in interface MongoDatabase
commandName
- The name of the command to run.commandValue
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(Callback, String, int, DocumentAssignable)
public ListenableFuture<Document> runCommandAsync(String commandName, String commandValue, DocumentAssignable options) throws MongoDbException
Overridden to call the
runCommandAsync(Callback, String, String, DocumentAssignable)
method.
runCommandAsync
in interface MongoDatabase
commandName
- The name of the command to run.commandValue
- The name of the command to run.options
- Optional (may be null) options for the command.MongoDbException
- On an error issuing the command or in running the commandrunCommandAsync(Callback, String, String, DocumentAssignable)
public void setDurability(Durability durability)
MongoDatabase
instance.
Defaults to the Durability
from the Mongo
's configuration
if set to null
.
setDurability
in interface MongoDatabase
durability
- The durability for write operations on the server.MongoClientConfiguration.getDefaultDurability()
public boolean setProfilingStatus(ProfilingStatus profileLevel) throws MongoDbException
Overridden to update the databases profile level.
setProfilingStatus
in interface MongoDatabase
profileLevel
- The desired profiling levelfalse
.MongoDbException
- On a failure to create the collection.MongoDatabase.setProfilingStatus(com.allanbank.mongodb.ProfilingStatus)
public void setReadPreference(ReadPreference readPreference)
MongoDatabase
instance.
Defaults to the ReadPreference
from the Mongo
's
configuration if set to null
.
setReadPreference
in interface MongoDatabase
readPreference
- The read preference for a query.MongoClientConfiguration.getDefaultReadPreference()
public Document stats() throws MongoDbException
Overridden to send a dbStats
command to the MongoDB server.
stats
in interface MongoDatabase
MongoDbException
- On an error collecting the database statistics.MongoDatabase.stats()
protected void addOptions(String command, DocumentAssignable options, DocumentBuilder builder)
command
- The command to make sure is removed from the options.options
- The options to be added. May be null
.builder
- The builder to add the options to.protected LockType getLockType()
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.