summaryrefslogtreecommitdiff
path: root/db
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2009-01-02 16:41:13 -0500
committerEliot Horowitz <eliot@10gen.com>2009-01-02 16:41:13 -0500
commitce95083dc263d4588cbf4ebe5fdd9f3b651aa42b (patch)
tree499911f8e082b888349c09d76c6442cb6ed82895 /db
parent7dde0887210b36e1690157e7028c95aa1c81b5cc (diff)
downloadmongo-ce95083dc263d4588cbf4ebe5fdd9f3b651aa42b.tar.gz
moving DBDirectClient to instance.* b/c it only make sense there and cleans linking
Diffstat (limited to 'db')
-rw-r--r--db/dbwebserver.cpp1
-rw-r--r--db/instance.cpp31
-rw-r--r--db/instance.h17
3 files changed, 49 insertions, 0 deletions
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<DBClientCursor> DBDirectClient::query(const char *ns, BSONObj query, int nToReturn , int nToSkip ,
+ BSONObj *fieldsToReturn , int queryOptions ){
+
+ auto_ptr<DBClientCursor> 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<DBClientCursor> 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<DBClientCursor> 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 );
+};