diff options
author | Aaron <aaron@10gen.com> | 2009-03-10 16:49:17 -0400 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-03-10 16:49:17 -0400 |
commit | d4fad81da14cf89587592f0188ca0cdfb5d4d38c (patch) | |
tree | 964164193fda07afb3d25de0e7d57a3b561c99a0 /client | |
parent | 7d842995d98c06a289d3ceda87f7eef2658bdd12 (diff) | |
download | mongo-d4fad81da14cf89587592f0188ca0cdfb5d4d38c.tar.gz |
Add explicit getMore to client interface
Diffstat (limited to 'client')
-rw-r--r-- | client/dbclient.cpp | 21 | ||||
-rw-r--r-- | client/dbclient.h | 28 |
2 files changed, 45 insertions, 4 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp index 97631996bd2..57425730f2e 100644 --- a/client/dbclient.cpp +++ b/client/dbclient.cpp @@ -446,6 +446,13 @@ namespace mongo { return auto_ptr< DBClientCursor >( 0 ); } + auto_ptr<DBClientCursor> DBClientBase::getMore( const char *ns, long long cursorId, int nToReturn, int options ) { + auto_ptr<DBClientCursor> c( new DBClientCursor( this, ns, cursorId, nToReturn, options ) ); + if ( c->init() ) + return c; + return auto_ptr< DBClientCursor >( 0 ); + } + void DBClientBase::insert( const char * ns , BSONObj obj ) { Message toSend; @@ -630,10 +637,18 @@ namespace mongo { bool DBClientCursor::init() { Message toSend; - assembleRequest( ns, query, nToReturn, nToSkip, fieldsToReturn, opts, toSend ); + if ( !cursorId ) { + assembleRequest( ns, query, nToReturn, nToSkip, fieldsToReturn, opts, toSend ); + } else { + BufBuilder b; + b.append( opts ); + b.append( ns.c_str() ); + b.append( nToReturn ); + b.append( cursorId ); + toSend.setData( dbGetMore, b.buf(), b.len() ); + } if ( !connector->call( toSend, *m, false ) ) return false; - dataReceived(); return true; } @@ -698,7 +713,7 @@ namespace mongo { } DBClientCursor::~DBClientCursor() { - if ( cursorId ) { + if ( cursorId && ownCursor_ ) { BufBuilder b; b.append( (int)0 ); // reserved b.append( (int)1 ); // number diff --git a/client/dbclient.h b/client/dbclient.h index f4d27667f8c..fe0bba12a0c 100644 --- a/client/dbclient.h +++ b/client/dbclient.h @@ -192,11 +192,28 @@ namespace mongo { cursorId(), nReturned(), pos(), - data() { + data(), + ownCursor_( true ) { } + + DBClientCursor( DBConnector *_connector, const char *_ns, long long _cursorId, int _nToReturn, int options ) : + connector(_connector), + ns(_ns), + nToReturn( _nToReturn ), + opts( options ), + m(new Message()), + cursorId( _cursorId ), + nReturned(), + pos(), + data(), + ownCursor_( true ) { + } virtual ~DBClientCursor(); + long long getCursorId() const { return cursorId; } + void decouple() { ownCursor_ = false; } + private: DBConnector *connector; string ns; @@ -213,6 +230,7 @@ namespace mongo { const char *data; void dataReceived(); void requestMore(); + bool ownCursor_; }; @@ -224,6 +242,8 @@ namespace mongo { virtual auto_ptr<DBClientCursor> query(const char *ns, Query query, int nToReturn = 0, int nToSkip = 0, BSONObj *fieldsToReturn = 0, int queryOptions = 0) = 0; + virtual auto_ptr<DBClientCursor> getMore( const char *ns, long long cursorId, int nToReturn = 0, int options = 0 ) = 0; + virtual BSONObj findOne(const char *ns, Query query, BSONObj *fieldsToReturn = 0, int queryOptions = 0) = 0; virtual void insert( const char * ns, BSONObj obj ) = 0; @@ -478,6 +498,12 @@ namespace mongo { virtual auto_ptr<DBClientCursor> query(const char *ns, Query query, int nToReturn = 0, int nToSkip = 0, BSONObj *fieldsToReturn = 0, int queryOptions = 0); + /** @param cursorId id of cursor to retrieve + @return an handle to a previously allocated cursor + @throws AssertionException + */ + virtual auto_ptr<DBClientCursor> getMore( const char *ns, long long cursorId, int nToReturn = 0, int options = 0 ); + /** @return a single object that matches the query. if none do, then the object is empty @throws AssertionException |