@@ -124,27 +124,27 @@ class MyCollection extends DBCollection {
124124 public void doapply ( DBObject o ){
125125 }
126126
127- public void insert ( DBObject o )
127+ public WriteResult insert ( DBObject o )
128128 throws MongoException {
129- insert ( new DBObject []{ o } );
129+ return insert ( new DBObject []{ o } );
130130 }
131131
132- public void insert (DBObject [] arr )
132+ public WriteResult insert (DBObject [] arr )
133133 throws MongoException {
134- insert (arr , true );
134+ return insert (arr , true );
135135 }
136136
137- public void insert (List <DBObject > list )
137+ public WriteResult insert (List <DBObject > list )
138138 throws MongoException {
139- insert (list .toArray (new DBObject [list .size ()]) , true );
139+ return insert (list .toArray (new DBObject [list .size ()]) , true );
140140 }
141141
142- protected void insert (DBObject obj , boolean shouldApply )
142+ protected WriteResult insert (DBObject obj , boolean shouldApply )
143143 throws MongoException {
144- insert ( new DBObject []{ obj } , shouldApply );
144+ return insert ( new DBObject []{ obj } , shouldApply );
145145 }
146146
147- protected void insert (DBObject [] arr , boolean shouldApply )
147+ protected WriteResult insert (DBObject [] arr , boolean shouldApply )
148148 throws MongoException {
149149
150150 if ( SHOW ) {
@@ -164,6 +164,8 @@ protected void insert(DBObject[] arr, boolean shouldApply )
164164 }
165165 }
166166
167+ WriteResult last = null ;
168+
167169 int cur = 0 ;
168170 while ( cur < arr .length ){
169171 OutMessage om = OutMessage .get ( 2002 );
@@ -183,12 +185,13 @@ protected void insert(DBObject[] arr, boolean shouldApply )
183185 }
184186 }
185187
186- _connector .say ( _db , om , getWriteConcern () );
187-
188+ last = _connector .say ( _db , om , getWriteConcern () );
188189 }
190+
191+ return last ;
189192 }
190193
191- public void remove ( DBObject o )
194+ public WriteResult remove ( DBObject o )
192195 throws MongoException {
193196
194197 if ( SHOW ) System .out .println ( "remove: " + _fullNameSpace + " " + JSON .serialize ( o ) );
@@ -209,7 +212,7 @@ public void remove( DBObject o )
209212
210213 om .putObject ( o );
211214
212- _connector .say ( _db , om , getWriteConcern () );
215+ return _connector .say ( _db , om , getWriteConcern () );
213216 }
214217
215218 void _cleanCursors ()
@@ -262,17 +265,7 @@ Iterator<DBObject> __find( DBObject ref , DBObject fields , int numToSkip , int
262265
263266 _cleanCursors ();
264267
265- OutMessage query = OutMessage .get ( 2004 );
266-
267- query .writeInt ( options ); // options
268- query .writeCString ( _fullNameSpace );
269-
270- query .writeInt ( numToSkip );
271- query .writeInt ( batchSize );
272- query .putObject ( ref ); // ref
273- if ( fields != null )
274- query .putObject ( fields ); // fields to return
275-
268+ OutMessage query = OutMessage .query ( options , _fullNameSpace , numToSkip , batchSize , ref , fields );
276269
277270 Response res = _connector .call ( _db , this , query , 2 );
278271
@@ -289,7 +282,7 @@ Iterator<DBObject> __find( DBObject ref , DBObject fields , int numToSkip , int
289282 return new Result ( this , res , batchSize , options );
290283 }
291284
292- public void update ( DBObject query , DBObject o , boolean upsert , boolean multi )
285+ public WriteResult update ( DBObject query , DBObject o , boolean upsert , boolean multi )
293286 throws MongoException {
294287
295288 if ( SHOW ) System .out .println ( "update: " + _fullNameSpace + " " + JSON .serialize ( query ) );
@@ -306,7 +299,7 @@ public void update( DBObject query , DBObject o , boolean upsert , boolean multi
306299 om .putObject ( query );
307300 om .putObject ( o );
308301
309- _connector .say ( _db , om , getWriteConcern () );
302+ return _connector .say ( _db , om , getWriteConcern () );
310303 }
311304
312305 protected void createIndex ( final DBObject keys , final DBObject options )
0 commit comments