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 1818
1919package com .mongodb ;
2020
21- import java .net .* ;
21+ import java .net .UnknownHostException ;
2222import 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 ;
2525
26- import org .bson .io .* ;
26+ import org .bson .io .PoolOutputBuffer ;
2727
2828/**
2929 * A database connection with internal pooling.
@@ -605,9 +605,11 @@ String _toKey( MongoURI uri ){
605605 buf .append ( uri .getUsername () );
606606 return buf .toString ();
607607 }
608+
609+ public static Holder singleton () { return _default ; }
608610
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 >();
611613
612614 }
613615
Original file line number Diff line number Diff line change 1818package com .mongodb ;
1919
2020import java .io .IOException ;
21+ import java .net .UnknownHostException ;
2122import java .nio .ByteBuffer ;
2223import java .util .*;
2324import java .util .regex .Pattern ;
@@ -785,7 +786,14 @@ public void testAllTypes(){
785786 DBObject b = c .findOne ();
786787 assertTrue (a .equals (b ));
787788 }
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" ) );
788794
795+ assertEquals ( m1 , m2 );
796+ }
789797 final Mongo _mongo ;
790798 final DB _db ;
791799
You can’t perform that action at this time.
0 commit comments