Skip to content

Commit 3355a43

Browse files
odrotbohmchristophstrobl
authored andcommitted
DATAMONGO-1467 - Polishing.
Original pull request: #431.
1 parent 9a02419 commit 3355a43

File tree

5 files changed

+24
-16
lines changed

5 files changed

+24
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
*/
4848
public class DefaultIndexOperations implements IndexOperations {
4949

50-
public static final String PARTIAL_FILTER_EXPRESSION_KEY = "partialFilterExpression";
50+
private static final String PARTIAL_FILTER_EXPRESSION_KEY = "partialFilterExpression";
5151

5252
private final MongoDbFactory mongoDbFactory;
5353
private final String collectionName;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016. the original author or authors.
2+
* Copyright 2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.springframework.util.Assert;
2929
import org.springframework.util.ObjectUtils;
3030

31+
import com.mongodb.DBObject;
32+
3133
/**
3234
* @author Mark Pollack
3335
* @author Oliver Gierke
@@ -76,10 +78,13 @@ public static IndexInfo indexInfoOf(Document sourceDocument) {
7678
Object value = keyDbObject.get(key);
7779

7880
if (TWO_D_IDENTIFIERS.contains(value)) {
81+
7982
indexFields.add(IndexField.geo(key));
83+
8084
} else if ("text".equals(value)) {
8185

8286
Document weights = (Document) sourceDocument.get("weights");
87+
8388
for (String fieldName : weights.keySet()) {
8489
indexFields.add(IndexField.text(fieldName, Float.valueOf(weights.get(fieldName).toString())));
8590
}

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
package org.springframework.data.mongodb.core.index;
1717

1818
import org.bson.Document;
19+
20+
import lombok.AccessLevel;
21+
import lombok.NonNull;
22+
import lombok.RequiredArgsConstructor;
23+
1924
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
20-
import org.springframework.util.Assert;
2125

2226
import com.mongodb.DBObject;
2327

@@ -28,23 +32,18 @@
2832
* @author Christoph Strobl
2933
* @since 1.10
3034
*/
35+
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
3136
public class PartialIndexFilter implements IndexFilter {
3237

33-
private final Object filterExpression;
34-
35-
private PartialIndexFilter(Object filterExpression) {
36-
37-
Assert.notNull(filterExpression, "FilterExpression must not be null!");
38-
this.filterExpression = filterExpression;
39-
}
38+
private final @NonNull Object filterExpression;
4039

4140
/**
4241
* Create new {@link PartialIndexFilter} for given {@link DBObject filter expression}.
4342
*
4443
* @param where must not be {@literal null}.
4544
* @return
4645
*/
47-
public static PartialIndexFilter filter(Document where) {
46+
public static PartialIndexFilter of(Document where) {
4847
return new PartialIndexFilter(where);
4948
}
5049

@@ -54,10 +53,14 @@ public static PartialIndexFilter filter(Document where) {
5453
* @param where must not be {@literal null}.
5554
* @return
5655
*/
57-
public static PartialIndexFilter filter(CriteriaDefinition where) {
56+
public static PartialIndexFilter of(CriteriaDefinition where) {
5857
return new PartialIndexFilter(where);
5958
}
6059

60+
/*
61+
* (non-Javadoc)
62+
* @see org.springframework.data.mongodb.core.index.IndexFilter#getFilterObject()
63+
*/
6164
public Document getFilterObject() {
6265

6366
if (filterExpression instanceof Document) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void shouldApplyPartialFilterCorrectly() {
100100
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
101101

102102
IndexDefinition id = new Index().named("partial-with-criteria").on("k3y", Direction.ASC)
103-
.partial(filter(where("q-t-y").gte(10)));
103+
.partial(of(where("q-t-y").gte(10)));
104104

105105
indexOps.ensureIndex(id);
106106

@@ -117,7 +117,7 @@ public void shouldApplyPartialFilterWithMappedPropertyCorrectly() {
117117
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
118118

119119
IndexDefinition id = new Index().named("partial-with-mapped-criteria").on("k3y", Direction.ASC)
120-
.partial(filter(where("quantity").gte(10)));
120+
.partial(of(where("quantity").gte(10)));
121121

122122
indexOps.ensureIndex(id);
123123

@@ -134,7 +134,7 @@ public void shouldApplyPartialDBOFilterCorrectly() {
134134
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
135135

136136
IndexDefinition id = new Index().named("partial-with-dbo").on("k3y", Direction.ASC)
137-
.partial(filter(new org.bson.Document("qty", new org.bson.Document("$gte", 10))));
137+
.partial(of(new org.bson.Document("qty", new org.bson.Document("$gte", 10))));
138138

139139
indexOps.ensureIndex(id);
140140

@@ -151,7 +151,7 @@ public void shouldFavorExplicitMappingHintViaClass() {
151151
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
152152

153153
IndexDefinition id = new Index().named("partial-with-inheritance").on("k3y", Direction.ASC)
154-
.partial(filter(where("age").gte(10)));
154+
.partial(of(where("age").gte(10)));
155155

156156
indexOps = new DefaultIndexOperations(template.getMongoDbFactory(),
157157
this.template.getCollectionName(DefaultIndexOperationsIntegrationTestsSample.class),

0 commit comments

Comments
 (0)