|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.mongodb.DB
public abstract class DB
an abstract class that represents a logical database on a server
Field Summary | |
---|---|
protected boolean |
_readOnly
|
Constructor Summary | |
---|---|
DB(Mongo mongo,
String name)
|
Method Summary | |
---|---|
void |
addOption(int option)
Adds the give option |
WriteResult |
addUser(String username,
char[] passwd)
Adds a new user for this db |
WriteResult |
addUser(String username,
char[] passwd,
boolean readOnly)
Adds a new user for this db |
boolean |
authenticate(String username,
char[] password)
Authenticates to db with the given credentials. |
CommandResult |
authenticateCommand(String username,
char[] password)
Authenticates to db with the given credentials. |
abstract void |
cleanCursors(boolean force)
|
boolean |
collectionExists(String collectionName)
Checks to see if a collection by name %lt;name> exists. |
CommandResult |
command(DBObject cmd)
Executes a database command. |
CommandResult |
command(DBObject cmd,
DBEncoder encoder)
Executes a database command. |
CommandResult |
command(DBObject cmd,
int options)
Executes a database command. |
CommandResult |
command(DBObject cmd,
int options,
DBEncoder encoder)
Executes a database command. |
CommandResult |
command(DBObject cmd,
int options,
ReadPreference readPrefs)
Executes a database command. |
CommandResult |
command(DBObject cmd,
int options,
ReadPreference readPrefs,
DBEncoder encoder)
Executes a database command. |
CommandResult |
command(String cmd)
Executes a database command. |
CommandResult |
command(String cmd,
int options)
Executes a database command. |
DBCollection |
createCollection(String name,
DBObject options)
Creates a collection with a given name and options. |
CommandResult |
doEval(String code,
Object... args)
evaluates a function on the database. |
protected abstract DBCollection |
doGetCollection(String name)
Returns the collection represented by the string <dbName>.<collectionName>. |
void |
dropDatabase()
Drops this database. |
Object |
eval(String code,
Object... args)
calls doEval(java.lang.String, java.lang.Object[]) . |
void |
forceError()
For testing purposes only - this method forces an error to help test error handling |
DBCollection |
getCollection(String name)
Gets a collection with a given name. |
DBCollection |
getCollectionFromString(String s)
Returns a collection matching a given string. |
Set<String> |
getCollectionNames()
Returns a set containing the names of all collections in this database. |
CommandResult |
getLastError()
Gets the the error (if there is one) from the previous operation on this connection. |
CommandResult |
getLastError(int w,
int wtimeout,
boolean fsync)
|
CommandResult |
getLastError(WriteConcern concern)
|
Mongo |
getMongo()
Gets the Mongo instance |
String |
getName()
Returns the name of this database. |
int |
getOptions()
Gets the query options |
CommandResult |
getPreviousError()
Returns the last error that occurred since start of database or a call to resetError()
The return object will look like |
ReadPreference |
getReadPreference()
Gets the default read preference |
DB |
getSisterDB(String name)
Gets another database on same server |
CommandResult |
getStats()
Returns the result of "dbstats" command |
WriteConcern |
getWriteConcern()
Gets the write concern for this database. |
boolean |
isAuthenticated()
Returns true if a user has been authenticated |
WriteResult |
removeUser(String username)
Removes a user for this db |
abstract void |
requestDone()
ends the current "consistent request" |
abstract void |
requestEnsureConnection()
ensure that a connection is assigned to the current "consistent request" (from primary pool, if connected to a replica set) |
abstract void |
requestStart()
starts a new "consistent request". |
void |
resetError()
Resets the error memory for this database. |
void |
resetOptions()
Resets the query options |
void |
setOptions(int options)
Sets the query options |
void |
setReadOnly(Boolean b)
Makes this database read-only. |
void |
setReadPreference(ReadPreference preference)
Sets the read preference for this database. |
void |
setWriteConcern(WriteConcern concern)
Sets the write concern for this database. |
void |
slaveOk()
Deprecated. Replaced with ReadPreference.secondaryPreferred() |
String |
toString()
Returns the name of this database. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected boolean _readOnly
Constructor Detail |
---|
public DB(Mongo mongo, String name)
mongo
- the mongo instancename
- the database nameMethod Detail |
---|
public abstract void requestStart()
public abstract void requestDone()
public abstract void requestEnsureConnection()
protected abstract DBCollection doGetCollection(String name)
name
- the name of the collection
public DBCollection getCollection(String name)
name
- the name of the collection to return
public DBCollection createCollection(String name, DBObject options)
name
- the name of the collection to returnoptions
- options
MongoException
public DBCollection getCollectionFromString(String s)
s
- the name of the collection
public CommandResult command(DBObject cmd)
command(com.mongodb.DBObject, int)
with 0 as query option.
cmd
- dbobject representing the command to execute
MongoException
public CommandResult command(DBObject cmd, DBEncoder encoder)
command(com.mongodb.DBObject, int, com.mongodb.DBEncoder)
with 0 as query option.
cmd
- dbobject representing the command to executeencoder
-
MongoException
public CommandResult command(DBObject cmd, int options, DBEncoder encoder)
command(com.mongodb.DBObject, int, com.mongodb.ReadPreference, com.mongodb.DBEncoder)
with a null readPrefs.
cmd
- dbobject representing the command to executeoptions
- query options to useencoder
-
MongoException
public CommandResult command(DBObject cmd, int options, ReadPreference readPrefs)
command(com.mongodb.DBObject, int, com.mongodb.ReadPreference, com.mongodb.DBEncoder)
with a default encoder.
cmd
- dbobject representing the command to executeoptions
- query options to usereadPrefs
- ReadPreferences for this command (nodes selection is the biggest part of this)
MongoException
public CommandResult command(DBObject cmd, int options, ReadPreference readPrefs, DBEncoder encoder)
cmd
- dbobject representing the command to executeoptions
- query options to usereadPrefs
- ReadPreferences for this command (nodes selection is the biggest part of this)encoder
-
MongoException
public CommandResult command(DBObject cmd, int options)
cmd
- dbobject representing the command to executeoptions
- query options to use
MongoException
public CommandResult command(String cmd)
command(com.mongodb.DBObject)
cmd
- command to execute
MongoException
public CommandResult command(String cmd, int options)
command(com.mongodb.DBObject, int)
cmd
- command to executeoptions
- query options to use
MongoException
public CommandResult doEval(String code, Object... args)
code
- the function in javascript codeargs
- arguments to be passed to the function
MongoException
public Object eval(String code, Object... args)
doEval(java.lang.String, java.lang.Object[])
.
If the command is successful, the "retval" field is extracted and returned.
Otherwise an exception is thrown.
code
- the function in javascript codeargs
- arguments to be passed to the function
MongoException
public CommandResult getStats()
MongoException
public String getName()
public void setReadOnly(Boolean b)
b
- if the database should be read-onlypublic Set<String> getCollectionNames()
MongoException
public boolean collectionExists(String collectionName)
collectionName
- The collection to test for existence
MongoException
public String toString()
toString
in class Object
public CommandResult getLastError()
{ "err" : errorMessage , "ok" : 1.0 }The value for errorMessage will be null if no error occurred, or a description otherwise. Important note: when calling this method directly, it is undefined which connection "getLastError" is called on. You may need to explicitly use a "consistent Request", see
requestStart()
For most purposes it is better not to call this method directly but instead use WriteConcern
MongoException
public CommandResult getLastError(WriteConcern concern)
concern
- the concern associated with "getLastError" call
MongoException
DB#getLastError() }
public CommandResult getLastError(int w, int wtimeout, boolean fsync)
w
- wtimeout
- fsync
-
MongoException
DB#getLastError(com.mongodb.WriteConcern) }
public void setWriteConcern(WriteConcern concern)
WriteConcern
for more information.
concern
- write concern to usepublic WriteConcern getWriteConcern()
public void setReadPreference(ReadPreference preference)
ReadPreference
for more information.
preference
- Read Preference to usepublic ReadPreference getReadPreference()
public void dropDatabase()
MongoException
public boolean isAuthenticated()
public boolean authenticate(String username, char[] password)
authenticateCommand
has already been
called with the same credentials and the authentication test succeeded, this method will return true. If this method
has already been called with different credentials and the authentication test succeeded,
this method will throw an IllegalStateException
. If this method has already been called with any credentials
and the authentication test failed, this method will re-try the authentication test with the
given credentials.
username
- name of user for this databasepassword
- password of user for this database
MongoException
- if authentication failed due to invalid user/pass, or other exceptions like I/O
IllegalStateException
- if authentiation test has already succeeded with different credentialsauthenticateCommand(String, char[])
public CommandResult authenticateCommand(String username, char[] password)
authenticate
has already been
called with the same credentials and the authentication test succeeded, this method will return true. If this method
has already been called with different credentials and the authentication test succeeded,
this method will throw an IllegalStateException
. If this method has already been called with any credentials
and the authentication test failed, this method will re-try the authentication test with the
given credentials.
username
- name of user for this databasepassword
- password of user for this database
MongoException
- if authentication failed due to invalid user/pass, or other exceptions like I/O
IllegalStateException
- if authentiation test has already succeeded with different credentialsauthenticate(String, char[])
public WriteResult addUser(String username, char[] passwd)
username
- passwd
-
MongoException
public WriteResult addUser(String username, char[] passwd, boolean readOnly)
username
- passwd
- readOnly
- if true, user will only be able to read
MongoException
public WriteResult removeUser(String username)
username
-
MongoException
public CommandResult getPreviousError()
resetError()
The return object will look like
{ err : errorMessage, nPrev : countOpsBack, ok : 1 }The value for errorMessage will be null of no error has occurred, otherwise the error message. The value of countOpsBack will be the number of operations since the error occurred. Care must be taken to ensure that calls to getPreviousError go to the same connection as that of the previous operation. See
requestStart()
for more information.
MongoException
public void resetError()
getPreviousError()
will return no error.
MongoException
public void forceError()
MongoException
public Mongo getMongo()
public DB getSisterDB(String name)
name
- name of the database
@Deprecated public void slaveOk()
ReadPreference.secondaryPreferred()
ReadPreference.secondaryPreferred()
public void addOption(int option)
option
- public void setOptions(int options)
options
- public void resetOptions()
public int getOptions()
public abstract void cleanCursors(boolean force)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |