File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change 18
18
19
19
package com .mongodb ;
20
20
21
- import java .net .* ;
21
+ import java .net .UnknownHostException ;
22
22
import java .util .*;
23
- import java .util .Map . Entry ;
24
- import java .util .concurrent .* ;
23
+ import java .util .concurrent . ConcurrentHashMap ;
24
+ import java .util .concurrent .ConcurrentMap ;
25
25
26
- import org .bson .io .* ;
26
+ import org .bson .io .PoolOutputBuffer ;
27
27
28
28
/**
29
29
* A database connection with internal pooling.
@@ -605,9 +605,11 @@ String _toKey( MongoURI uri ){
605
605
buf .append ( uri .getUsername () );
606
606
return buf .toString ();
607
607
}
608
+
609
+ public static Holder singleton () { return _default ; }
608
610
609
-
610
- private static final ConcurrentMap <String ,Mongo > _mongos = new ConcurrentHashMap <String ,Mongo >();
611
+ private static Holder _default = new Holder ();
612
+ private final ConcurrentMap <String ,Mongo > _mongos = new ConcurrentHashMap <String ,Mongo >();
611
613
612
614
}
613
615
Original file line number Diff line number Diff line change 18
18
package com .mongodb ;
19
19
20
20
import java .io .IOException ;
21
+ import java .net .UnknownHostException ;
21
22
import java .nio .ByteBuffer ;
22
23
import java .util .*;
23
24
import java .util .regex .Pattern ;
@@ -785,7 +786,14 @@ public void testAllTypes(){
785
786
DBObject b = c .findOne ();
786
787
assertTrue (a .equals (b ));
787
788
}
789
+
790
+ @ Test
791
+ public void testMongoHolder () throws MongoException , UnknownHostException {
792
+ Mongo m1 = Mongo .Holder .singleton ().connect ( new MongoURI ( "mongodb://localhost" ) );
793
+ Mongo m2 = Mongo .Holder .singleton ().connect ( new MongoURI ( "mongodb://localhost" ) );
788
794
795
+ assertEquals ( m1 , m2 );
796
+ }
789
797
final Mongo _mongo ;
790
798
final DB _db ;
791
799
You can’t perform that action at this time.
0 commit comments