Skip to content

Commit 7914e8a

Browse files
committed
DATAMONGO-1467 - Polishing.
Original pull request: #431.
1 parent dc4a30a commit 7914e8a

File tree

5 files changed

+26
-18
lines changed

5 files changed

+26
-18
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
*/
4141
public class DefaultIndexOperations implements IndexOperations {
4242

43-
public static final String PARTIAL_FILTER_EXPRESSION_KEY = "partialFilterExpression";
43+
private static final String PARTIAL_FILTER_EXPRESSION_KEY = "partialFilterExpression";
44+
4445
private final MongoOperations mongoOperations;
4546
private final String collectionName;
4647
private final QueryMapper mapper;
@@ -166,7 +167,9 @@ public Void doInCollection(DBCollection collection) throws MongoException, DataA
166167
public List<IndexInfo> getIndexInfo() {
167168

168169
return mongoOperations.execute(collectionName, new CollectionCallback<List<IndexInfo>>() {
170+
169171
public List<IndexInfo> doInCollection(DBCollection collection) throws MongoException, DataAccessException {
172+
170173
List<DBObject> dbObjectList = collection.getIndexInfo();
171174
return getIndexData(dbObjectList);
172175
}

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

Lines changed: 1 addition & 2 deletions
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.
@@ -32,5 +32,4 @@ public interface IndexFilter {
3232
* @return
3333
*/
3434
DBObject getFilterObject();
35-
3635
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,11 @@
2323
import java.util.Collections;
2424
import java.util.List;
2525

26-
import com.mongodb.DBObject;
2726
import org.springframework.util.Assert;
2827
import org.springframework.util.ObjectUtils;
2928

29+
import com.mongodb.DBObject;
30+
3031
/**
3132
* @author Mark Pollack
3233
* @author Oliver Gierke
@@ -90,10 +91,13 @@ public static IndexInfo indexInfoOf(DBObject sourceDocument) {
9091
Object value = keyDbObject.get(key);
9192

9293
if (TWO_D_IDENTIFIERS.contains(value)) {
94+
9395
indexFields.add(IndexField.geo(key));
96+
9497
} else if ("text".equals(value)) {
9598

9699
DBObject weights = (DBObject) sourceDocument.get("weights");
100+
97101
for (String fieldName : weights.keySet()) {
98102
indexFields.add(IndexField.text(fieldName, Float.valueOf(weights.get(fieldName).toString())));
99103
}

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

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

18+
import lombok.AccessLevel;
19+
import lombok.NonNull;
20+
import lombok.RequiredArgsConstructor;
21+
1822
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
19-
import org.springframework.util.Assert;
2023

2124
import com.mongodb.DBObject;
2225

@@ -27,23 +30,18 @@
2730
* @author Christoph Strobl
2831
* @since 1.10
2932
*/
33+
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
3034
public class PartialIndexFilter implements IndexFilter {
3135

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

4038
/**
4139
* Create new {@link PartialIndexFilter} for given {@link DBObject filter expression}.
4240
*
4341
* @param where must not be {@literal null}.
4442
* @return
4543
*/
46-
public static PartialIndexFilter filter(DBObject where) {
44+
public static PartialIndexFilter of(DBObject where) {
4745
return new PartialIndexFilter(where);
4846
}
4947

@@ -53,10 +51,14 @@ public static PartialIndexFilter filter(DBObject where) {
5351
* @param where must not be {@literal null}.
5452
* @return
5553
*/
56-
public static PartialIndexFilter filter(CriteriaDefinition where) {
54+
public static PartialIndexFilter of(CriteriaDefinition where) {
5755
return new PartialIndexFilter(where);
5856
}
5957

58+
/*
59+
* (non-Javadoc)
60+
* @see org.springframework.data.mongodb.core.index.IndexFilter#getFilterObject()
61+
*/
6062
public DBObject getFilterObject() {
6163

6264
if (filterExpression instanceof DBObject) {

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
@@ -102,7 +102,7 @@ public void shouldApplyPartialFilterCorrectly() {
102102
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
103103

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

107107
indexOps.ensureIndex(id);
108108

@@ -119,7 +119,7 @@ public void shouldApplyPartialFilterWithMappedPropertyCorrectly() {
119119
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
120120

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

124124
indexOps.ensureIndex(id);
125125

@@ -136,7 +136,7 @@ public void shouldApplyPartialDBOFilterCorrectly() {
136136
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
137137

138138
IndexDefinition id = new Index().named("partial-with-dbo").on("k3y", Direction.ASC)
139-
.partial(filter(new BasicDBObject("qty", new BasicDBObject("$gte", 10))));
139+
.partial(of(new BasicDBObject("qty", new BasicDBObject("$gte", 10))));
140140

141141
indexOps.ensureIndex(id);
142142

@@ -153,7 +153,7 @@ public void shouldFavorExplicitMappingHintViaClass() {
153153
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
154154

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

158158
indexOps = new DefaultIndexOperations(template,
159159
this.template.getCollectionName(DefaultIndexOperationsIntegrationTestsSample.class),

0 commit comments

Comments
 (0)