Skip to content

Commit 857b6b5

Browse files
committed
Merge branch 'master' of github.com:mongodb/mongo-java-driver
2 parents c510cba + efb4b81 commit 857b6b5

16 files changed

Lines changed: 133 additions & 52 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ http://jira.mongodb.org/browse/JAVA
2525
* Dave Brosius dbrosius@mebigfatguy.com
2626
* Scott Hernandez scotthernandez@hotmail.com
2727
* Hans Meiser hmeiser@example.com
28-
* Benedikt Waldvogel benedikt.waldvogel@pangora.com
28+
* Benedikt Waldvogel mail@bwaldvogel.de
2929
* William Shulman william.shulman@gmail.com
3030
* Daniel Spilker mail@daniel-spilker.com
3131
* Kyle Banker kylebanker@gmail.com

src/main/com/mongodb/DB.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,15 @@ public final DBCollection createCollection( String name, DBObject o ){
8888
public DBCollection getCollectionFromString( String s ){
8989
DBCollection foo = null;
9090

91-
while ( s.contains( "." ) ){
92-
int idx = s.indexOf( "." );
91+
int idx = s.indexOf( "." );
92+
while ( idx >= 0 ){
9393
String b = s.substring( 0 , idx );
9494
s = s.substring( idx + 1 );
9595
if ( foo == null )
9696
foo = getCollection( b );
9797
else
9898
foo = foo.getCollection( b );
99+
idx = s.indexOf( "." );
99100
}
100101

101102
if ( foo != null )
@@ -184,7 +185,7 @@ public Set<String> getCollectionNames()
184185
if (namespaces == null)
185186
throw new RuntimeException("this is impossible");
186187

187-
Iterator<DBObject> i = namespaces.__find(new BasicDBObject(), null, 0, 0, 0);
188+
Iterator<DBObject> i = namespaces.__find(new BasicDBObject(), null, 0, 0, getOptions());
188189
if (i == null)
189190
return new HashSet<String>();
190191

src/main/com/mongodb/DBApiLayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ public void createIndex( final DBObject keys, final DBObject options )
325325
full.put( k , options.get( k ) );
326326
full.put( "key" , keys );
327327

328-
DBApiLayer.this.doGetCollection( "system.indexes" ).insert( new DBObject[]{ full } , false , getWriteConcern() );
328+
DBApiLayer.this.doGetCollection( "system.indexes" ).insert( new DBObject[]{ full } , false , WriteConcern.SAFE );
329329
}
330330

331331
final String _fullNameSpace;

src/main/com/mongodb/DBCollection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ Iterator<DBObject> __find( DBObject ref , DBObject fields , int numToSkip , int
215215
return __find( ref , fields , numToSkip , batchSize , getOptions() );
216216
}
217217

218-
public abstract void createIndex( DBObject keys , DBObject options ) throws MongoException ;
218+
public abstract void createIndex( DBObject keys , DBObject options ) throws MongoException;
219219

220220

221221
// ------

src/main/com/mongodb/DBCursor.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,18 @@ public DBCursor addOption( int option ){
262262
return this;
263263
}
264264

265+
public void setOptions( int options ){
266+
_options = options;
267+
}
268+
269+
public void resetOptions(){
270+
_options = 0;
271+
}
272+
273+
public int getOptions(){
274+
return _options;
275+
}
276+
265277
// ---- internal stuff ------
266278

267279
private void _check()
@@ -388,7 +400,6 @@ private DBObject _next()
388400
}
389401

390402
if ( _cursorType == CursorType.ARRAY ){
391-
_nums.add( String.valueOf( _all.size() ) );
392403
_all.add( _cur );
393404
}
394405

@@ -605,6 +616,4 @@ public DBObject getQuery(){
605616
private int _num = 0;
606617

607618
private final ArrayList<DBObject> _all = new ArrayList<DBObject>();
608-
private final List<String> _nums = new ArrayList<String>();
609-
610619
}

src/main/com/mongodb/DBPortPool.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ protected long memSize( DBPort p ){
145145
}
146146

147147
protected int pick( int iThink , boolean couldCreate ){
148-
final int id = Thread.currentThread().hashCode();
148+
final int id = System.identityHashCode(Thread.currentThread());
149149
final int s = _availSafe.size();
150150
for ( int i=0; i<s; i++ ){
151151
DBPort p = _availSafe.get(i);
@@ -173,7 +173,7 @@ public DBPort get(){
173173
if ( port == null )
174174
throw new ConnectionWaitTimeOut( _options.maxWaitTime );
175175

176-
port._lastThread = Thread.currentThread().hashCode();
176+
port._lastThread = System.identityHashCode(Thread.currentThread());
177177
return port;
178178
}
179179

@@ -217,7 +217,7 @@ public void cleanup( DBPort p ){
217217
}
218218

219219
public boolean ok( DBPort t ){
220-
return _addr.equals( t._addr );
220+
return _addr.getSocketAddress().equals( t._addr );
221221
}
222222

223223
protected DBPort createNew(){

src/main/com/mongodb/Mongo.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
* <blockquote><pre>
3535
* Mongo mongo1 = new Mongo( "127.0.0.1" );
3636
* Mongo mongo2 = new Mongo( "127.0.0.1", 27017 );
37-
* Mongo mongo3 = new Mongo( new DBAddress( "127.0.0.1:27017", "test" ) )
37+
* Mongo mongo3 = new Mongo( new DBAddress( "127.0.0.1", 27017, "test" ) );
38+
* Mongo mongo4 = new Mongo( new ServerAddress( "127.0.0.1") );
3839
* </pre></blockquote>
3940
*
4041
* Mongo instances have connection pooling built in - see the requestStart
@@ -66,6 +67,31 @@
6667
* Once the slave becomes master, the driver will begin using that connection
6768
* as the master connection and the exceptions will stop being thrown.
6869
* </p>
70+
*
71+
* <h3>Connecting to a Replica Set</h3>
72+
* <p>
73+
* You can connect to a
74+
* <a href="http://www.mongodb.org/display/DOCS/Replica+Sets">replica set</a>
75+
* using the Java driver by passing several a list if ServerAddress to the
76+
* Mongo constructor.
77+
* For example:
78+
* </p>
79+
* <blockquote><pre>
80+
* List<ServerAddress> addrs = new ArrayList<ServerAddress>();
81+
* addrs.add( new ServerAddress( "localhost" , 27017 ) );
82+
* addrs.add( new ServerAddress( "localhost" , 27018 ) );
83+
* addrs.add( new ServerAddress( "localhost" , 27019 ) );
84+
*
85+
* Mongo mongo = new Mongo( addrs );
86+
* </pre></blockquote>
87+
*
88+
* <p>
89+
* By default, all read and write operations will be made on the master.
90+
* But it's possible to read from the slave(s) by using slaveOk:
91+
* </p>
92+
* <blockquote><pre>
93+
* mongo.slaveOk();
94+
* </pre></blockquote>
6995
*/
7096
public class Mongo {
7197

src/main/com/mongodb/RawDBObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public Map toMap() {
5858
Iterator i = this.keySet().iterator();
5959
while (i.hasNext()) {
6060
Object s = i.next();
61-
m.put(s, this.get(s+""));
61+
m.put(s, this.get(String.valueOf(s)));
6262
}
6363
return m;
6464
}

src/main/com/mongodb/ReplicaSetStatus.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ synchronized void update(){
141141
Throwable root = e;
142142
if ( e.getCause() != null )
143143
root = e.getCause();
144-
_logger.log( Level.WARNING , "node down: " + _addr + " " + root );
144+
_logger.log( Level.FINE , "node down: " + _addr + " " + root );
145145
_ok = false;
146146
}
147147
catch ( Exception e ){

src/main/com/mongodb/ServerAddress.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ boolean isPaired(){
9393
*/
9494
List<ServerAddress> explode(){
9595
if ( _all == null || _all.length <= 1 )
96-
throw new RuntimeException( "not replica set mode. num addresses : " + _all.length );
96+
throw new RuntimeException( "not replica set mode. num addresses : " + ((_all == null) ? 0 : _all.length) );
9797

9898
List<ServerAddress> s = new ArrayList<ServerAddress>();
9999
for ( int i=0; i<_all.length; i++ ){

0 commit comments

Comments
 (0)