Skip to content

Commit e68c30e

Browse files
committed
mongodb: fix sonnar issues, #TASK-7151, #TASK-7134
1 parent ea3906c commit e68c30e

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

  • commons-datastore/commons-datastore-mongodb/src/main/java/org/opencb/commons/datastore/mongodb

commons-datastore/commons-datastore-mongodb/src/main/java/org/opencb/commons/datastore/mongodb/MongoDBCollection.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ private <T> DataResult<T> endQuery(List result, long numMatches, double start) {
9797
long end = System.currentTimeMillis();
9898
int numResults = (result != null) ? result.size() : 0;
9999

100-
DataResult<T> queryResult = new DataResult((int) (end - start), Collections.emptyList(), numResults, result, numMatches, null);
101-
return queryResult;
100+
return new DataResult((int) (end - start), Collections.emptyList(), numResults, result, numMatches, null);
102101
}
103102

104103
private DataResult endWrite(long start) {
@@ -333,7 +332,7 @@ public <T> DataResult<T> aggregate(List<? extends Bson> operations, ComplexTypeC
333332
long start = startQuery();
334333
DataResult<T> queryResult;
335334
List<T> list = new LinkedList<>();
336-
if (operations != null && operations.size() > 0) {
335+
if (operations != null && !operations.isEmpty()) {
337336
MongoDBIterator<T> iterator = mongoDBNativeQuery.aggregate(operations, converter, options);
338337
if (queryResultWriter != null) {
339338
try {
@@ -347,7 +346,7 @@ public <T> DataResult<T> aggregate(List<? extends Bson> operations, ComplexTypeC
347346
}
348347
} else {
349348
while (iterator.hasNext()) {
350-
list.add((T) iterator.next());
349+
list.add(iterator.next());
351350
}
352351
}
353352
}
@@ -429,7 +428,7 @@ public DataResult update(ClientSession clientSession, List<? extends Bson> queri
429428

430429
return endWrite(
431430
wr.getMatchedCount(),
432-
wr.getInsertedCount() + wr.getUpserts().size(),
431+
(long) wr.getInsertedCount() + wr.getUpserts().size(),
433432
wr.getModifiedCount(),
434433
wr.getDeletedCount(),
435434
0,
@@ -547,8 +546,7 @@ public DataResult createIndex(Bson keys, ObjectMap options) {
547546
}
548547

549548
mongoDBNativeQuery.createIndex(keys, i);
550-
DataResult dataResult = endQuery(Collections.emptyList(), start);
551-
return dataResult;
549+
return endQuery(Collections.emptyList(), start);
552550
}
553551

554552
public void dropIndexes() {
@@ -558,15 +556,13 @@ public void dropIndexes() {
558556
public DataResult dropIndex(Bson keys) {
559557
long start = startQuery();
560558
mongoDBNativeQuery.dropIndex(keys);
561-
DataResult dataResult = endQuery(Collections.emptyList(), start);
562-
return dataResult;
559+
return endQuery(Collections.emptyList(), start);
563560
}
564561

565562
public DataResult<Document> getIndex() {
566563
long start = startQuery();
567564
List<Document> index = mongoDBNativeQuery.getIndex();
568-
DataResult<Document> queryResult = endQuery(index, start);
569-
return queryResult;
565+
return endQuery(index, start);
570566
}
571567

572568

0 commit comments

Comments
 (0)