Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added null checking on db

  • Loading branch information...
commit f40ed8ad47fff323d9851100f0f844ab0549f19b 1 parent 607a455
@brianfrankcooper brianfrankcooper authored
Showing with 24 additions and 7 deletions.
  1. +24 −7 db/mongodb/src/com/yahoo/ycsb/db/MongoDbClient.java
View
31 db/mongodb/src/com/yahoo/ycsb/db/MongoDbClient.java
@@ -94,8 +94,9 @@ public void init() throws DBException {
* @return Zero on success, a non-zero error code on error. See this class's description for a discussion of error codes.
*/
public int delete(String table, String key) {
+ com.mongodb.DB db=null;
try {
- com.mongodb.DB db = mongo.getDB(database);
+ db = mongo.getDB(database);
db.requestStart();
DBCollection collection = db.getCollection(table);
DBObject q = new BasicDBObject().append("_id", key);
@@ -114,7 +115,10 @@ public int delete(String table, String key) {
}
finally
{
- db.requestDone();
+ if (db!=null)
+ {
+ db.requestDone();
+ }
}
}
@@ -153,7 +157,10 @@ public int insert(String table, String key, HashMap<String, String> values) {
logger.error(e + "", e);
return 1;
} finally {
- db.requestDone();
+ if (db!=null)
+ {
+ db.requestDone();
+ }
}
}
@@ -200,7 +207,10 @@ public int read(String table, String key, Set<String> fields,
logger.error(e + "", e);
return 1;
} finally {
- db.requestDone();
+ if (db!=null)
+ {
+ db.requestDone();
+ }
}
}
@@ -249,7 +259,10 @@ public int update(String table, String key, HashMap<String, String> values) {
logger.error(e + "", e);
return 1;
} finally {
- db.requestDone();
+ if (db!=null)
+ {
+ db.requestDone();
+ }
}
}
@@ -268,8 +281,9 @@ public int update(String table, String key, HashMap<String, String> values) {
*/
public int scan(String table, String startkey, int recordcount,
Set<String> fields, Vector<HashMap<String, String>> result) {
+ com.mongodb.DB db=null;
try {
- com.mongodb.DB db = mongo.getDB(database);
+ db = mongo.getDB(database);
db.requestStart();
DBCollection collection = db.getCollection(table);
// { "_id":{"$gte":startKey, "$lte":{"appId":key+"\uFFFF"}} }
@@ -288,7 +302,10 @@ public int scan(String table, String startkey, int recordcount,
}
finally
{
- db.requestDone();
+ if (db!=null)
+ {
+ db.requestDone();
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.