diff --git a/commons-datastore/commons-datastore-mongodb/src/main/java/org/opencb/commons/datastore/mongodb/MongoDBCollection.java b/commons-datastore/commons-datastore-mongodb/src/main/java/org/opencb/commons/datastore/mongodb/MongoDBCollection.java index c4a42f36..8b26c9eb 100644 --- a/commons-datastore/commons-datastore-mongodb/src/main/java/org/opencb/commons/datastore/mongodb/MongoDBCollection.java +++ b/commons-datastore/commons-datastore-mongodb/src/main/java/org/opencb/commons/datastore/mongodb/MongoDBCollection.java @@ -97,8 +97,7 @@ private DataResult endQuery(List result, long numMatches, double start) { long end = System.currentTimeMillis(); int numResults = (result != null) ? result.size() : 0; - DataResult queryResult = new DataResult((int) (end - start), Collections.emptyList(), numResults, result, numMatches, null); - return queryResult; + return new DataResult((int) (end - start), Collections.emptyList(), numResults, result, numMatches, null); } private DataResult endWrite(long start) { @@ -333,7 +332,7 @@ public DataResult aggregate(List operations, ComplexTypeC long start = startQuery(); DataResult queryResult; List list = new LinkedList<>(); - if (operations != null && operations.size() > 0) { + if (operations != null && !operations.isEmpty()) { MongoDBIterator iterator = mongoDBNativeQuery.aggregate(operations, converter, options); if (queryResultWriter != null) { try { @@ -347,7 +346,7 @@ public DataResult aggregate(List operations, ComplexTypeC } } else { while (iterator.hasNext()) { - list.add((T) iterator.next()); + list.add(iterator.next()); } } } @@ -429,7 +428,7 @@ public DataResult update(ClientSession clientSession, List queri return endWrite( wr.getMatchedCount(), - wr.getInsertedCount() + wr.getUpserts().size(), + (long) wr.getInsertedCount() + wr.getUpserts().size(), wr.getModifiedCount(), wr.getDeletedCount(), 0, @@ -547,8 +546,7 @@ public DataResult createIndex(Bson keys, ObjectMap options) { } mongoDBNativeQuery.createIndex(keys, i); - DataResult dataResult = endQuery(Collections.emptyList(), start); - return dataResult; + return endQuery(Collections.emptyList(), start); } public void dropIndexes() { @@ -558,15 +556,13 @@ public void dropIndexes() { public DataResult dropIndex(Bson keys) { long start = startQuery(); mongoDBNativeQuery.dropIndex(keys); - DataResult dataResult = endQuery(Collections.emptyList(), start); - return dataResult; + return endQuery(Collections.emptyList(), start); } public DataResult getIndex() { long start = startQuery(); List index = mongoDBNativeQuery.getIndex(); - DataResult queryResult = endQuery(index, start); - return queryResult; + return endQuery(index, start); }