Skip to content

Commit cee670f

Browse files
Rename preciseCount -> exactCount and reduce method visibility.
1 parent 1f39426 commit cee670f

File tree

7 files changed

+30
-30
lines changed

7 files changed

+30
-30
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoOperations.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,8 +1181,8 @@ <S, T> T findAndReplace(Query query, S replacement, FindAndReplaceOptions option
11811181
* @return the count of matching documents.
11821182
* @since 3.4
11831183
*/
1184-
default long preciseCount(Query query, Class<?> entityClass) {
1185-
return preciseCount(query, entityClass, getCollectionName(entityClass));
1184+
default long exactCount(Query query, Class<?> entityClass) {
1185+
return exactCount(query, entityClass, getCollectionName(entityClass));
11861186
}
11871187

11881188
/**
@@ -1206,8 +1206,8 @@ default long preciseCount(Query query, Class<?> entityClass) {
12061206
* @see #count(Query, Class, String)
12071207
* @since 3.4
12081208
*/
1209-
default long preciseCount(Query query, String collectionName) {
1210-
return preciseCount(query, null, collectionName);
1209+
default long exactCount(Query query, String collectionName) {
1210+
return exactCount(query, null, collectionName);
12111211
}
12121212

12131213
/**
@@ -1231,7 +1231,7 @@ default long preciseCount(Query query, String collectionName) {
12311231
* @return the count of matching documents.
12321232
* @since 3.4
12331233
*/
1234-
long preciseCount(Query query, @Nullable Class<?> entityClass, String collectionName);
1234+
long exactCount(Query query, @Nullable Class<?> entityClass, String collectionName);
12351235

12361236
/**
12371237
* Returns the number of documents for the given {@link Query} by querying the collection of the given entity class.

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware,
188188

189189
private SessionSynchronization sessionSynchronization = SessionSynchronization.ON_ACTUAL_TRANSACTION;
190190

191-
private CountExecution countExecution = this::doPreciseCount;
191+
private CountExecution countExecution = this::doExactCount;
192192

193193
/**
194194
* Constructor used for a basic template configuration.
@@ -366,14 +366,14 @@ public void useEstimatedCount(boolean enabled) {
366366
* @param estimationFilter the {@link BiPredicate filter}.
367367
* @since 3.4
368368
*/
369-
public void useEstimatedCount(boolean enabled, BiPredicate<Document, CountOptions> estimationFilter) {
369+
private void useEstimatedCount(boolean enabled, BiPredicate<Document, CountOptions> estimationFilter) {
370370

371371
if (enabled) {
372372

373373
this.countExecution = (collectionName, filter, options) -> {
374374

375375
if (!estimationFilter.test(filter, options)) {
376-
return doPreciseCount(collectionName, filter, options);
376+
return doExactCount(collectionName, filter, options);
377377
}
378378

379379
EstimatedDocumentCountOptions estimatedDocumentCountOptions = new EstimatedDocumentCountOptions();
@@ -384,7 +384,7 @@ public void useEstimatedCount(boolean enabled, BiPredicate<Document, CountOption
384384
return doEstimatedCount(collectionName, estimatedDocumentCountOptions);
385385
};
386386
} else {
387-
this.countExecution = this::doPreciseCount;
387+
this.countExecution = this::doExactCount;
388388
}
389389
}
390390

@@ -1150,14 +1150,14 @@ public long count(Query query, String collectionName) {
11501150
}
11511151

11521152
@Override
1153-
public long preciseCount(Query query, @Nullable Class<?> entityClass, String collectionName) {
1153+
public long exactCount(Query query, @Nullable Class<?> entityClass, String collectionName) {
11541154

11551155
CountContext countContext = queryOperations.countQueryContext(query);
11561156

11571157
CountOptions options = countContext.getCountOptions(entityClass);
11581158
Document mappedQuery = countContext.getMappedQuery(entityClass, mappingContext::getPersistentEntity);
11591159

1160-
return doPreciseCount(collectionName, mappedQuery, options);
1160+
return doExactCount(collectionName, mappedQuery, options);
11611161
}
11621162

11631163
/*
@@ -1188,7 +1188,7 @@ protected long doCount(String collectionName, Document filter, CountOptions opti
11881188
return countExecution.countDocuments(collectionName, filter, options);
11891189
}
11901190

1191-
protected long doPreciseCount(String collectionName, Document filter, CountOptions options) {
1191+
protected long doExactCount(String collectionName, Document filter, CountOptions options) {
11921192
return execute(collectionName,
11931193
collection -> collection.countDocuments(CountQuery.of(filter).toQueryDocument(), options));
11941194
}

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoOperations.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -953,8 +953,8 @@ <S, T> Mono<T> findAndReplace(Query query, S replacement, FindAndReplaceOptions
953953
* @return the count of matching documents.
954954
* @since 3.4
955955
*/
956-
default Mono<Long> preciseCount(Query query, Class<?> entityClass) {
957-
return preciseCount(query, entityClass, getCollectionName(entityClass));
956+
default Mono<Long> exactCount(Query query, Class<?> entityClass) {
957+
return exactCount(query, entityClass, getCollectionName(entityClass));
958958
}
959959

960960
/**
@@ -978,8 +978,8 @@ default Mono<Long> preciseCount(Query query, Class<?> entityClass) {
978978
* @see #count(Query, Class, String)
979979
* @since 3.4
980980
*/
981-
default Mono<Long> preciseCount(Query query, String collectionName) {
982-
return preciseCount(query, null, collectionName);
981+
default Mono<Long> exactCount(Query query, String collectionName) {
982+
return exactCount(query, null, collectionName);
983983
}
984984

985985
/**
@@ -1003,7 +1003,7 @@ default Mono<Long> preciseCount(Query query, String collectionName) {
10031003
* @return the count of matching documents.
10041004
* @since 3.4
10051005
*/
1006-
Mono<Long> preciseCount(Query query, @Nullable Class<?> entityClass, String collectionName);
1006+
Mono<Long> exactCount(Query query, @Nullable Class<?> entityClass, String collectionName);
10071007

10081008
/**
10091009
* Returns the number of documents for the given {@link Query} by querying the collection of the given entity class.

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/ReactiveMongoTemplate.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public class ReactiveMongoTemplate implements ReactiveMongoOperations, Applicati
191191

192192
private SessionSynchronization sessionSynchronization = SessionSynchronization.ON_ACTUAL_TRANSACTION;
193193

194-
private CountExecution countExecution = this::doPreciseCount;
194+
private CountExecution countExecution = this::doExactCount;
195195

196196
/**
197197
* Constructor used for a basic template configuration.
@@ -384,22 +384,22 @@ public void useEstimatedCount(boolean enabled) {
384384
}
385385

386386
/**
387-
* En-/Disable usage of estimated count based on the given {@link BiPredicate estimationFilter}.
387+
* En-/Disable usage of estimated count based on the given {@link BiFunction estimationFilter}.
388388
*
389389
* @param enabled if {@literal true} {@link com.mongodb.client.MongoCollection#estimatedDocumentCount()} will we used for {@link Document
390-
* filter queries} that pass the given {@link BiPredicate estimationFilter}.
391-
* @param estimationFilter the {@link BiPredicate filter}.
390+
* filter queries} that pass the given {@link BiFunction estimationFilter}.
391+
* @param estimationFilter the {@link BiFunction filter}.
392392
* @since 3.4
393393
*/
394-
public void useEstimatedCount(boolean enabled, BiFunction<Document, CountOptions, Mono<Boolean>> estimationFilter) {
394+
private void useEstimatedCount(boolean enabled, BiFunction<Document, CountOptions, Mono<Boolean>> estimationFilter) {
395395

396396
if (enabled) {
397397

398398
this.countExecution = (collectionName, filter, options) -> {
399399

400400
return estimationFilter.apply(filter, options).flatMap(canEstimate -> {
401401
if (!canEstimate) {
402-
return doPreciseCount(collectionName, filter, options);
402+
return doExactCount(collectionName, filter, options);
403403
}
404404

405405
EstimatedDocumentCountOptions estimatedDocumentCountOptions = new EstimatedDocumentCountOptions();
@@ -411,7 +411,7 @@ public void useEstimatedCount(boolean enabled, BiFunction<Document, CountOptions
411411
});
412412
};
413413
} else {
414-
this.countExecution = this::doPreciseCount;
414+
this.countExecution = this::doExactCount;
415415
}
416416
}
417417

@@ -1236,14 +1236,14 @@ public <T> Mono<T> findAndRemove(Query query, Class<T> entityClass, String colle
12361236
}
12371237

12381238
@Override
1239-
public Mono<Long> preciseCount(Query query, @Nullable Class<?> entityClass, String collectionName) {
1239+
public Mono<Long> exactCount(Query query, @Nullable Class<?> entityClass, String collectionName) {
12401240

12411241
CountContext countContext = queryOperations.countQueryContext(query);
12421242

12431243
CountOptions options = countContext.getCountOptions(entityClass);
12441244
Document mappedQuery = countContext.getMappedQuery(entityClass, mappingContext::getPersistentEntity);
12451245

1246-
return doPreciseCount(collectionName, mappedQuery, options);
1246+
return doExactCount(collectionName, mappedQuery, options);
12471247
}
12481248

12491249
/*
@@ -1317,7 +1317,7 @@ protected Mono<Long> doCount(String collectionName, Document filter, CountOption
13171317
return countExecution.countDocuments(collectionName, filter, options);
13181318
}
13191319

1320-
protected Mono<Long> doPreciseCount(String collectionName, Document filter, CountOptions options) {
1320+
protected Mono<Long> doExactCount(String collectionName, Document filter, CountOptions options) {
13211321

13221322
return createMono(collectionName,
13231323
collection -> collection.countDocuments(CountQuery.of(filter).toQueryDocument(), options));

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/ReactiveSessionBoundMongoTemplateUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public void countShouldUseProxiedCollection() {
229229
}
230230

231231
@Test // GH-3522
232-
public void countShouldDelegateToPreciseCountNoMatterWhat() {
232+
public void countShouldDelegateToExactCountNoMatterWhat() {
233233

234234
template.useEstimatedCount(true);
235235
template.count(new Query(), Person.class).subscribe();

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/SessionBoundMongoTemplateUnitTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public void countShouldUseProxiedCollection() {
229229
}
230230

231231
@Test // DATAMONGO-1880, GH-3522
232-
public void countShouldDelegateToPreciseCountNoMatterWhat() {
232+
public void countShouldDelegateToExactCountNoMatterWhat() {
233233

234234
template.useEstimatedCount(true);
235235
template.count(new Query(), Person.class);

src/main/asciidoc/reference/mongodb.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2161,7 +2161,7 @@ If the application is fine with the limitations of working upon collection stati
21612161
[TIP]
21622162
====
21632163
By setting `MongoTemplate#useEstimatedCount(...)` to `true` _MongoTemplate#count(...)_ operations, that use an empty filter query, will be delegated to `estimatedCount`, as long as there is no transaction active and the template is not bound to a <<mongo.sessions,session>>.
2164-
It will still be possible to obtain exact numbers via `MongoTemplate#preciseCount`, but may speed up things.
2164+
It will still be possible to obtain exact numbers via `MongoTemplate#exactCount`, but may speed up things.
21652165
====
21662166

21672167
[NOTE]

0 commit comments

Comments
 (0)