Skip to content

Commit f8f032d

Browse files
committed
use CommandResult for WriteResult
1 parent 0d03571 commit f8f032d

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

src/main/com/mongodb/DBPort.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,22 @@ private synchronized Response go( OutMessage msg , DBCollection coll )
8888
}
8989
}
9090

91-
synchronized BasicDBObject getLastError( DB db ){
91+
synchronized CommandResult getLastError( DB db ){
9292

9393
OutMessage msg = OutMessage.query( 0 , db.getName() + ".$cmd" , 0 , -1 , new BasicDBObject( "getlasterror" , 1 ) , null );
9494

9595
try {
9696
Response res = go( msg , db.getCollection( "$cmd" ) );
9797
if ( res.size() != 1 )
9898
throw new MongoInternalException( "something is wrong. size:" + res.size() );
99-
return (BasicDBObject)res.get(0);
99+
return (CommandResult)res.get(0);
100100
}
101101
catch ( IOException ioe ){
102102
throw new MongoInternalException( "getlasterror failed: " + ioe.toString() , ioe );
103103
}
104104
}
105105

106-
synchronized BasicDBObject tryGetLastError( DB db , long last ){
106+
synchronized CommandResult tryGetLastError( DB db , long last ){
107107
if ( last != _calls )
108108
return null;
109109

src/main/com/mongodb/DBTCPConnector.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ public void requestEnsureConnection(){
113113
WriteResult _checkWriteError( MyPort mp , DBPort port )
114114
throws MongoException {
115115

116-
DBObject e = _mongo.getDB( "admin" ).getLastError();
116+
CommandResult e = _mongo.getDB( "admin" ).getLastError();
117117
mp.done( port );
118118

119119
Object foo = e.get( "err" );
120120
if ( foo == null )
121-
return new WriteResult( (BasicDBObject)e );
121+
return new WriteResult( e );
122122

123123
int code = -1;
124124
if ( e.get( "code" ) instanceof Number )
@@ -150,8 +150,12 @@ public WriteResult say( DB db , OutMessage m , DB.WriteConcern concern )
150150
catch ( IOException ioe ){
151151
mp.error( ioe );
152152
_error( ioe );
153-
if ( concern == DB.WriteConcern.NONE )
154-
return new WriteResult( new BasicDBObject( "$err" , "NETWORK ERROR" ) );
153+
if ( concern == DB.WriteConcern.NONE ){
154+
CommandResult res = new CommandResult();
155+
res.put( "ok" , false );
156+
res.put( "$err" , "NETWORK ERROR" );
157+
return new WriteResult( res );
158+
}
155159
throw new MongoException.Network( "can't say something" , ioe );
156160
}
157161
catch ( MongoException me ){

src/main/com/mongodb/WriteResult.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
public class WriteResult {
3030

31-
WriteResult( BasicDBObject o ){
31+
WriteResult( CommandResult o ){
3232
_lastErrorResult = o;
3333
_lazy = false;
3434
}
@@ -40,7 +40,7 @@ public class WriteResult {
4040
_lazy = true;
4141
}
4242

43-
public synchronized BasicDBObject getLastError(){
43+
public synchronized CommandResult getLastError(){
4444
if ( _lastErrorResult != null )
4545
return _lastErrorResult;
4646

@@ -84,7 +84,7 @@ public String toString(){
8484
DBPort _port;
8585
long _lastCall;
8686

87-
BasicDBObject _lastErrorResult;
87+
CommandResult _lastErrorResult;
8888

8989
final boolean _lazy;
9090
}

0 commit comments

Comments
 (0)