@@ -124,27 +124,27 @@ class MyCollection extends DBCollection {
124
124
public void doapply ( DBObject o ){
125
125
}
126
126
127
- public void insert ( DBObject o )
127
+ public WriteResult insert ( DBObject o )
128
128
throws MongoException {
129
- insert ( new DBObject []{ o } );
129
+ return insert ( new DBObject []{ o } );
130
130
}
131
131
132
- public void insert (DBObject [] arr )
132
+ public WriteResult insert (DBObject [] arr )
133
133
throws MongoException {
134
- insert (arr , true );
134
+ return insert (arr , true );
135
135
}
136
136
137
- public void insert (List <DBObject > list )
137
+ public WriteResult insert (List <DBObject > list )
138
138
throws MongoException {
139
- insert (list .toArray (new DBObject [list .size ()]) , true );
139
+ return insert (list .toArray (new DBObject [list .size ()]) , true );
140
140
}
141
141
142
- protected void insert (DBObject obj , boolean shouldApply )
142
+ protected WriteResult insert (DBObject obj , boolean shouldApply )
143
143
throws MongoException {
144
- insert ( new DBObject []{ obj } , shouldApply );
144
+ return insert ( new DBObject []{ obj } , shouldApply );
145
145
}
146
146
147
- protected void insert (DBObject [] arr , boolean shouldApply )
147
+ protected WriteResult insert (DBObject [] arr , boolean shouldApply )
148
148
throws MongoException {
149
149
150
150
if ( SHOW ) {
@@ -164,6 +164,8 @@ protected void insert(DBObject[] arr, boolean shouldApply )
164
164
}
165
165
}
166
166
167
+ WriteResult last = null ;
168
+
167
169
int cur = 0 ;
168
170
while ( cur < arr .length ){
169
171
OutMessage om = OutMessage .get ( 2002 );
@@ -183,12 +185,13 @@ protected void insert(DBObject[] arr, boolean shouldApply )
183
185
}
184
186
}
185
187
186
- _connector .say ( _db , om , getWriteConcern () );
187
-
188
+ last = _connector .say ( _db , om , getWriteConcern () );
188
189
}
190
+
191
+ return last ;
189
192
}
190
193
191
- public void remove ( DBObject o )
194
+ public WriteResult remove ( DBObject o )
192
195
throws MongoException {
193
196
194
197
if ( SHOW ) System .out .println ( "remove: " + _fullNameSpace + " " + JSON .serialize ( o ) );
@@ -209,7 +212,7 @@ public void remove( DBObject o )
209
212
210
213
om .putObject ( o );
211
214
212
- _connector .say ( _db , om , getWriteConcern () );
215
+ return _connector .say ( _db , om , getWriteConcern () );
213
216
}
214
217
215
218
void _cleanCursors ()
@@ -262,17 +265,7 @@ Iterator<DBObject> __find( DBObject ref , DBObject fields , int numToSkip , int
262
265
263
266
_cleanCursors ();
264
267
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 );
276
269
277
270
Response res = _connector .call ( _db , this , query , 2 );
278
271
@@ -289,7 +282,7 @@ Iterator<DBObject> __find( DBObject ref , DBObject fields , int numToSkip , int
289
282
return new Result ( this , res , batchSize , options );
290
283
}
291
284
292
- public void update ( DBObject query , DBObject o , boolean upsert , boolean multi )
285
+ public WriteResult update ( DBObject query , DBObject o , boolean upsert , boolean multi )
293
286
throws MongoException {
294
287
295
288
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
306
299
om .putObject ( query );
307
300
om .putObject ( o );
308
301
309
- _connector .say ( _db , om , getWriteConcern () );
302
+ return _connector .say ( _db , om , getWriteConcern () );
310
303
}
311
304
312
305
protected void createIndex ( final DBObject keys , final DBObject options )
0 commit comments