@@ -54,7 +54,7 @@ public abstract class DBCollection {
54
54
* @dochub insert
55
55
*/
56
56
public WriteResult insert (DBObject [] arr , WriteConcern concern ) throws MongoException {
57
- return insert ( arr , concern , getDBEncoderFactory (). create () );
57
+ return insert ( arr , concern , getDBEncoder () );
58
58
}
59
59
60
60
/**
@@ -162,7 +162,7 @@ public WriteResult insert(List<DBObject> list, WriteConcern concern )
162
162
* @dochub update
163
163
*/
164
164
public WriteResult update ( DBObject q , DBObject o , boolean upsert , boolean multi , WriteConcern concern ) throws MongoException {
165
- return update ( q , o , upsert , multi , concern , getDBEncoderFactory (). create () );
165
+ return update ( q , o , upsert , multi , concern , getDBEncoder () );
166
166
}
167
167
168
168
/**
@@ -236,7 +236,7 @@ public WriteResult updateMulti( DBObject q , DBObject o ) throws MongoException
236
236
* @dochub remove
237
237
*/
238
238
public WriteResult remove ( DBObject o , WriteConcern concern ) throws MongoException {
239
- return remove ( o , concern , getDBEncoderFactory (). create () );
239
+ return remove ( o , concern , getDBEncoder () );
240
240
}
241
241
242
242
/**
@@ -433,7 +433,7 @@ public final void createIndex( final DBObject keys )
433
433
* @throws MongoException
434
434
*/
435
435
public void createIndex ( DBObject keys , DBObject options ) throws MongoException {
436
- createIndex ( keys , options , getDBEncoderFactory (). create () );
436
+ createIndex ( keys , options , getDBEncoder () );
437
437
}
438
438
439
439
/**
@@ -658,6 +658,12 @@ private DBDecoder getDecoder() {
658
658
return _decoderFactory != null ? _decoderFactory .create () : null ;
659
659
}
660
660
661
+ // Only create a new encoder if there is an encoder factory explicitly set on the collection. Otherwise return null
662
+ // to allow DB to create its own or use a cached one.
663
+ private DBEncoder getDBEncoder () {
664
+ return _encoderFactory != null ? _encoderFactory .create () : null ;
665
+ }
666
+
661
667
662
668
/**
663
669
* calls {@link DBCollection#apply(com.mongodb.DBObject, boolean)} with ensureID=true
@@ -1149,7 +1155,6 @@ protected DBCollection( DB base , String name ){
1149
1155
_name = name ;
1150
1156
_fullName = _db .getName () + "." + name ;
1151
1157
_options = new Bytes .OptionHolder ( _db ._options );
1152
- _encoderFactory = _db .getMongo ().getMongoOptions ().dbEncoderFactory ;
1153
1158
}
1154
1159
1155
1160
protected DBObject _checkObject ( DBObject o , boolean canBeNull , boolean query ){
@@ -1394,15 +1399,15 @@ public void slaveOk(){
1394
1399
* @param option
1395
1400
*/
1396
1401
public void addOption ( int option ){
1397
- _options .add ( option );
1402
+ _options .add (option );
1398
1403
}
1399
1404
1400
1405
/**
1401
1406
* sets the default query options
1402
1407
* @param options
1403
1408
*/
1404
1409
public void setOptions ( int options ){
1405
- _options .set ( options );
1410
+ _options .set (options );
1406
1411
}
1407
1412
1408
1413
/**
@@ -1442,10 +1447,7 @@ public DBDecoderFactory getDBDecoderFactory() {
1442
1447
* @param fact the factory to set.
1443
1448
*/
1444
1449
public void setDBEncoderFactory (DBEncoderFactory fact ) {
1445
- if (fact == null )
1446
- _encoderFactory = _db .getMongo ().getMongoOptions ().dbEncoderFactory ;
1447
- else
1448
- _encoderFactory = fact ;
1450
+ _encoderFactory = fact ;
1449
1451
}
1450
1452
1451
1453
/**
0 commit comments