@@ -93,15 +93,6 @@ public WriteConcern( String w ){
93
93
this ( w , 0 , false , false );
94
94
}
95
95
96
- /**
97
- * Tag based Write Concern with configgable j and wtimeout=0, fsync=false
98
- * @param w Write Concern Tag
99
- * @param j whether writes should wait for a journaling group commit
100
- */
101
- public WriteConcern ( String w , boolean j ){
102
- this ( w , 0 , false , j );
103
- }
104
-
105
96
/**
106
97
* Calls {@link WriteConcern#WriteConcern(int, int, boolean)} with fsync=false
107
98
* @param w number of writes
@@ -154,36 +145,11 @@ public WriteConcern( int w , int wtimeout , boolean fsync ){
154
145
* @param fsync whether or not to fsync
155
146
* @param j whether writes should wait for a journaling group commit
156
147
*/
157
- public WriteConcern ( int w , int wtimeout , boolean fsync , boolean j ){
158
- _wValue = w ;
159
- _wtimeout = wtimeout ;
160
- _fsync = fsync ;
161
- _j = j ;
162
- _continueOnErrorInsert = false ;
163
- }
164
-
165
- /**
166
- * Creates a WriteConcern object.
167
- * <p>Specifies the number of servers to wait for on the write operation, and exception raising behavior </p>
168
- * <p> w represents the number of servers:
169
- * <ul>
170
- * <li>{@code w=-1} None, no checking is done</li>
171
- * <li>{@code w=0} None, network socket errors raised</li>
172
- * <li>{@code w=1} Checks server for errors as well as network socket errors raised</li>
173
- * <li>{@code w>1} Checks servers (w) for errors as well as network socket errors raised</li>
174
- * </ul>
175
- * </p>
176
- * @param w number of writes
177
- * @param wtimeout timeout for write operation
178
- * @param fsync whether or not to fsync
179
- * @param j whether writes should wait for a journaling group commit
180
- */
181
- public WriteConcern ( int w , int wtimeout , boolean fsync , boolean j , boolean continueInsertOnError ){
148
+ public WriteConcern ( int w , int wtimeout , boolean fsync , boolean j ){
182
149
_wValue = w ;
183
150
_wtimeout = wtimeout ;
184
151
_fsync = fsync ;
185
152
_j = j ;
186
- _continueOnErrorInsert = continueInsertOnError ;
187
153
}
188
154
189
155
/**
@@ -207,34 +173,8 @@ public WriteConcern( String w , int wtimeout , boolean fsync, boolean j ){
207
173
_wtimeout = wtimeout ;
208
174
_fsync = fsync ;
209
175
_j = j ;
210
- _continueOnErrorInsert = false ;
211
- }
212
-
213
- /**
214
- * Creates a WriteConcern object.
215
- * <p>Specifies the number of servers to wait for on the write operation, and exception raising behavior </p>
216
- * <p> w represents the number of servers:
217
- * <ul>
218
- * <li>{@code w=-1} None, no checking is done</li>
219
- * <li>{@code w=0} None, network socket errors raised</li>
220
- * <li>{@code w=1} Checks server for errors as well as network socket errors raised</li>
221
- * <li>{@code w>1} Checks servers (w) for errors as well as network socket errors raised</li>
222
- * </ul>
223
- * </p>
224
- * @param w number of writes
225
- * @param wtimeout timeout for write operation
226
- * @param fsync whether or not to fsync
227
- * @param j whether writes should wait for a journaling group commit
228
- */
229
- public WriteConcern ( String w , int wtimeout , boolean fsync , boolean j , Boolean continueInsertOnError ){
230
- _wValue = w ;
231
- _wtimeout = wtimeout ;
232
- _fsync = fsync ;
233
- _j = j ;
234
- _continueOnErrorInsert = continueInsertOnError ;
235
176
}
236
177
237
-
238
178
/**
239
179
* Gets the object representing the "getlasterror" command
240
180
* @return
@@ -258,24 +198,52 @@ public BasicDBObject getCommand(){
258
198
}
259
199
260
200
/**
261
- * Gets the number of servers to write to
262
- * if W is not a string value, returns -999.
263
- *
264
- * You should migrate to using getWValue (returns Object)
265
- * or getWString (String)
201
+ * Sets the w value (the write strategy)
202
+ * @param wValue
203
+ */
204
+ public void setWObject (Object wValue ) {
205
+ this ._wValue = wValue ;
206
+ }
207
+
208
+ /**
209
+ * Gets the w value (the write strategy)
210
+ * @return
211
+ */
212
+ public Object getWObject (){
213
+ return _wValue ;
214
+ }
215
+
216
+ /**
217
+ * Sets the w value (the write strategy)
218
+ * @param w
219
+ */
220
+ public void setW (int w ) {
221
+ _wValue = w ;
222
+ }
223
+
224
+ /**
225
+ * Gets the w parameter (the write strategy)
266
226
* @return
267
227
*/
268
228
public int getW (){
269
- if (_wValue instanceof Integer )
270
- return (Integer ) _wValue ;
271
- else
272
- return -999 ;
229
+ return (Integer ) _wValue ;
273
230
}
274
-
231
+
232
+ /**
233
+ * Gets the w parameter (the write strategy) in String format
234
+ * @return
235
+ */
275
236
public String getWString (){
276
237
return _wValue .toString ();
277
238
}
278
239
240
+ /**
241
+ * Sets the write timeout (in milliseconds)
242
+ * @param wtimeout
243
+ */
244
+ public void setWtimeout (int wtimeout ) {
245
+ this ._wtimeout = wtimeout ;
246
+ }
279
247
280
248
/**
281
249
* Gets the write timeout (in milliseconds)
@@ -286,20 +254,19 @@ public int getWtimeout(){
286
254
}
287
255
288
256
/**
289
- * Returns whether writes wait for files to be synced to disk
290
- * @return
257
+ * Sets the fsync flag (fsync to disk on the server)
258
+ * @param fsync
291
259
*/
292
- public boolean fsync () {
293
- return _fsync ;
260
+ public void setFsync ( boolean fsync ) {
261
+ _fsync = fsync ;
294
262
}
295
-
263
+
296
264
/**
297
- * Returns whether writes will await a group commit to the
298
- * journal.
299
- * @return boolean
265
+ * Gets the fsync flag (fsync to disk on the server)
266
+ * @return
300
267
*/
301
- public boolean j (){
302
- return _j ;
268
+ public boolean getFsync (){
269
+ return _fsync ;
303
270
}
304
271
305
272
/**
@@ -367,70 +334,35 @@ public boolean equals( Object o ){
367
334
}
368
335
369
336
/**
370
- * Gets the w value (either int or string)
371
- * @return
372
- */
373
- public Object getWValue (){
374
- return _wValue ;
375
- }
376
-
377
- /**
378
- * Clones this WriteConcern with a new String mode for "w" (WriteConcerns are immutable)
379
- * @param mode
380
- * @return
337
+ * Sets the j parameter (journal syncing)
338
+ * @param j
381
339
*/
382
- public WriteConcern withW ( String mode ) {
383
- return _instance ( mode , _wtimeout , _fsync , _j , _continueOnErrorInsert ) ;
340
+ public void setJ ( boolean j ) {
341
+ this . _j = j ;
384
342
}
385
343
386
344
/**
387
- * Clones this WriteConcern with a new int mode for "w" (WriteConcerns are immutable)
388
- * @param mode
389
- * @param w
390
- * @return
345
+ * Gets the j parameter (journal syncing)
346
+ * @return
391
347
*/
392
- public WriteConcern withW (int w ) {
393
- return _instance ( w , _wtimeout , _fsync , _j , _continueOnErrorInsert );
394
- }
395
-
396
- /**
397
- *
398
- * Clones this WriteConcern with a new "j" (WriteConcerns are immutable)
399
- * @param j
400
- * @return
401
- */
402
- public WriteConcern withJ (boolean j ) {
403
- return _instance ( _wValue , _wtimeout , _fsync , _j , _continueOnErrorInsert );
348
+ public boolean getJ () {
349
+ return _j ;
404
350
}
405
351
406
-
407
352
/**
408
- *
409
- * Clones this WriteConcern with a new boolean mode for "continue inserts on error" (WriteConcerns are immutable)
410
- * @param cont
411
- * @return
353
+ * Sets the "continue inserts on error" mode
354
+ * @param continueOnErrorInsert
412
355
*/
413
- public WriteConcern withContinueOnErrorForInsert (boolean cont ) {
414
- return _instance ( _wValue , _wtimeout , _fsync , _j , cont ) ;
356
+ public void setContinueOnErrorInsert (boolean continueOnErrorInsert ) {
357
+ this . _continueOnErrorInsert = continueOnErrorInsert ;
415
358
}
416
359
417
360
/**
418
- *
419
- * Clones this WriteConcern with a new boolean mode for fsync (WriteConcerns are immutable)
420
- * @param fsync
421
- * @return
361
+ * Gets the "continue inserts on error" mode
362
+ * @return
422
363
*/
423
- public WriteConcern withFsync (boolean fsync ) {
424
- return _instance ( _wValue , _wtimeout , fsync , _j , _continueOnErrorInsert );
425
- }
426
-
427
-
428
- protected WriteConcern _instance ( Object wValue , int wtimeout , boolean fsync , boolean j , boolean cont ){
429
- if (wValue instanceof Integer )
430
- return new WriteConcern ( (Integer ) wValue , wtimeout , fsync , j , cont );
431
- else if (wValue instanceof String )
432
- return new WriteConcern ( (String ) wValue , wtimeout , fsync , j , cont );
433
- else throw new IllegalArgumentException ( "W must be a String or Integer." );
364
+ public boolean getContinueOnErrorInsert () {
365
+ return _continueOnErrorInsert ;
434
366
}
435
367
436
368
/**
@@ -446,11 +378,11 @@ public static Majority majorityWriteConcern( int wtimeout, boolean fsync, boolea
446
378
}
447
379
448
380
449
- Object _wValue ;
450
- final int _wtimeout ;
451
- final boolean _fsync ;
452
- final boolean _j ;
453
- final boolean _continueOnErrorInsert ;
381
+ Object _wValue = 0 ;
382
+ int _wtimeout = 0 ;
383
+ boolean _fsync = false ;
384
+ boolean _j = false ;
385
+ boolean _continueOnErrorInsert = false ;
454
386
455
387
public static class Majority extends WriteConcern {
456
388
0 commit comments