@@ -274,16 +274,13 @@ public Iterator<DBObject> find( DBObject ref , DBObject fields , int numToSkip ,
274274 query .putObject ( fields ); // fields to return
275275
276276
277- Response raw = _connector .call ( _db , this , query , 2 );
278- SingleResult res = new SingleResult ( _fullNameSpace , options , raw );
277+ Response res = _connector .call ( _db , this , query , 2 );
279278
280- if ( res ._lst .size () != raw ._num )
281- throw new RuntimeException ( "something is wrong have:" + res ._lst .size () + " should have:" + raw ._num );
282- if ( res ._lst .size () == 0 )
279+ if ( res .size () == 0 )
283280 return null ;
284281
285- if ( res ._lst . size () == 1 ){
286- BSONObject foo = res ._lst . get (0 );
282+ if ( res .size () == 1 ){
283+ BSONObject foo = res .get (0 );
287284 Object err = foo .get ( "$err" );
288285 if ( err != null )
289286 throw new MongoException ( foo );
@@ -326,83 +323,27 @@ protected void createIndex( final DBObject keys, final DBObject options )
326323 final String _fullNameSpace ;
327324 }
328325
329- class SingleResult {
330-
331- SingleResult ( String fullNameSpace , int options , Response res ){
332- _res = res ;
333- _fullNameSpace = fullNameSpace ;
334- _options = options ;
335-
336- if ( res ._num == 0 )
337- _lst = EMPTY ;
338- else if ( res ._num < 3 )
339- _lst = new LinkedList <DBObject >();
340- else
341- _lst = new ArrayList <DBObject >( res ._num );
342-
343- while ( res .more () ){
344- _lst .add ( res .next () );
345- }
346- }
347-
348- boolean hasGetMore (){
349- if ( _res ._cursor <= 0 )
350- return false ;
351-
352- if ( _res ._num > 0 )
353- return true ;
354-
355- if ( ( _options & Bytes .QUERYOPTION_TAILABLE ) == 0 )
356- return false ;
357-
358- // have a tailable cursor
359- if ( ( _res ._flags & Bytes .RESULTFLAG_AWAITCAPABLE ) > 0 )
360- return true ;
361-
362- try {
363- System .out .println ( "sleep" );
364- Thread .sleep ( 1000 );
365- }
366- catch ( Exception e ){}
367-
368- return true ;
369- }
370-
371- long cursor (){
372- return _res ._cursor ;
373- }
374-
375- public String toString (){
376- return _res .toString ();
377- }
378-
379- final String _fullNameSpace ;
380- final Response _res ;
381- final int _options ;
382- final List <DBObject > _lst ;
383- }
384-
385326 class Result implements Iterator <DBObject > {
386327
387- Result ( MyCollection coll , SingleResult res , int numToReturn , int options ){
328+ Result ( MyCollection coll , Response res , int numToReturn , int options ){
388329 init ( res );
389330 _collection = coll ;
390331 _numToReturn = numToReturn ;
391332 _options = options ;
392333 }
393334
394- private void init ( SingleResult res ){
395- _totalBytes += res ._res . _len ;
335+ private void init ( Response res ){
336+ _totalBytes += res ._len ;
396337 _curResult = res ;
397- _cur = res ._lst . iterator ();
398- _sizes .add ( res ._lst . size () );
338+ _cur = res .iterator ();
339+ _sizes .add ( res .size () );
399340 }
400341
401342 public DBObject next (){
402343 if ( _cur .hasNext () )
403344 return _cur .next ();
404345
405- if ( ! _curResult .hasGetMore () )
346+ if ( ! _curResult .hasGetMore ( _options ) )
406347 throw new RuntimeException ( "no more" );
407348
408349 _advance ();
@@ -413,7 +354,7 @@ public boolean hasNext(){
413354 if ( _cur .hasNext () )
414355 return true ;
415356
416- if ( ! _curResult .hasGetMore () )
357+ if ( ! _curResult .hasGetMore ( _options ) )
417358 return false ;
418359
419360 _advance ();
@@ -428,20 +369,14 @@ private void _advance(){
428369 OutMessage m = OutMessage .get ( 2005 );
429370
430371 m .writeInt ( 0 );
431- m .writeCString ( _curResult ._fullNameSpace );
372+ m .writeCString ( _collection ._fullNameSpace );
432373 m .writeInt ( _numToReturn ); // num to return
433374 m .writeLong ( _curResult .cursor () );
434375
435376 try {
436- Response raw = _connector .call ( DBApiLayer .this , _collection , m );
377+ Response res = _connector .call ( DBApiLayer .this , _collection , m );
437378 _numGetMores ++;
438-
439- SingleResult res = new SingleResult ( _curResult ._fullNameSpace , _options , raw );
440379 init ( res );
441-
442- if ( raw .more () || raw .bytesLeft () > 0 ){
443- throw new RuntimeException ( "uh oh" );
444- }
445380 }
446381 catch ( MongoException me ){
447382 throw new MongoInternalException ( "can't do getmore" , me );
@@ -474,7 +409,7 @@ List<Integer> getSizes(){
474409 return Collections .unmodifiableList ( _sizes );
475410 }
476411
477- SingleResult _curResult ;
412+ Response _curResult ;
478413 Iterator <DBObject > _cur ;
479414 final MyCollection _collection ;
480415 final int _numToReturn ;
0 commit comments