diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 20b91431b9e..43756c38460 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -361,32 +361,3 @@ BSONObj DBClientPaired::findOne(const char *a, BSONObj b, BSONObj *c, int d) { } -auto_ptr DBDirectClient::query(const char *ns, BSONObj query, int nToReturn , int nToSkip , - BSONObj *fieldsToReturn , int queryOptions ){ - - auto_ptr c( new DBClientCursor( new DirectConnector() , ns , - query , nToReturn , nToSkip , fieldsToReturn , queryOptions )); - if ( c->init() ) - return c; - - return auto_ptr< DBClientCursor >( 0 ); -} - -BSONObj DBDirectClient::findOne(const char *ns, BSONObj query, BSONObj *fieldsToReturn , int queryOptions ){ - auto_ptr c = - this->query(ns, query, 1, 0, fieldsToReturn, queryOptions); - - if ( ! c->more() ) - return BSONObj(); - - return c->next().copy(); -} - - -bool DirectConnector::send( Message &toSend, Message &response, bool assertOk ){ - DbResponse dbResponse; - assembleResponse( toSend, dbResponse ); - assert( dbResponse.response ); - response = *dbResponse.response; - return true; -} diff --git a/client/dbclient.h b/client/dbclient.h index f98702a8cf1..780941d9630 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -263,16 +263,3 @@ public: }; -class DBDirectClient : public DBClientInterface { - public: - - virtual auto_ptr query(const char *ns, BSONObj query, int nToReturn = 0, int nToSkip = 0, - BSONObj *fieldsToReturn = 0, int queryOptions = 0); - - virtual BSONObj findOne(const char *ns, BSONObj query, BSONObj *fieldsToReturn = 0, int queryOptions = 0); -}; - - -class DirectConnector : public DBClientCursor::Connector { - virtual bool send( Message &toSend, Message &response, bool assertOk=true ); -}; diff --git a/db/dbwebserver.cpp b/db/dbwebserver.cpp index 2570494e01b..e40dbc65d28 100644 --- a/db/dbwebserver.cpp +++ b/db/dbwebserver.cpp @@ -21,6 +21,7 @@ #include "db.h" #include "repl.h" #include "replset.h" +#include "instance.h" extern int port; extern const char *replInfo; diff --git a/db/instance.cpp b/db/instance.cpp index a899f390dbe..bfb99b3c028 100644 --- a/db/instance.cpp +++ b/db/instance.cpp @@ -505,3 +505,34 @@ void dbexit(int rc, const char *why) { log() << " dbexit: really exiting now" << endl; exit(rc); } + + +auto_ptr DBDirectClient::query(const char *ns, BSONObj query, int nToReturn , int nToSkip , + BSONObj *fieldsToReturn , int queryOptions ){ + + auto_ptr c( new DBClientCursor( new DirectConnector() , ns , + query , nToReturn , nToSkip , fieldsToReturn , queryOptions )); + if ( c->init() ) + return c; + + return auto_ptr< DBClientCursor >( 0 ); +} + +BSONObj DBDirectClient::findOne(const char *ns, BSONObj query, BSONObj *fieldsToReturn , int queryOptions ){ + auto_ptr c = + this->query(ns, query, 1, 0, fieldsToReturn, queryOptions); + + if ( ! c->more() ) + return BSONObj(); + + return c->next().copy(); +} + + +bool DirectConnector::send( Message &toSend, Message &response, bool assertOk ){ + DbResponse dbResponse; + assembleResponse( toSend, dbResponse ); + assert( dbResponse.response ); + response = *dbResponse.response; + return true; +} diff --git a/db/instance.h b/db/instance.h index 7cba130f1b9..9006d6aad5d 100644 --- a/db/instance.h +++ b/db/instance.h @@ -86,3 +86,20 @@ void receivedInsert(Message& m, stringstream& ss); void receivedGetMore(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, */Message& m, stringstream& ss); void receivedQuery(DbResponse& dbresponse, /*AbstractMessagingPort& dbMsgPort, */Message& m, stringstream& ss, bool logit); void getDatabaseNames( vector< string > &names ); + + +// --- local client --- + +class DBDirectClient : public DBClientInterface { + public: + + virtual auto_ptr query(const char *ns, BSONObj query, int nToReturn = 0, int nToSkip = 0, + BSONObj *fieldsToReturn = 0, int queryOptions = 0); + + virtual BSONObj findOne(const char *ns, BSONObj query, BSONObj *fieldsToReturn = 0, int queryOptions = 0); +}; + + +class DirectConnector : public DBClientCursor::Connector { + virtual bool send( Message &toSend, Message &response, bool assertOk=true ); +};