DATAMONGO-1467 - Polishing.

Original pull request: #431.
This commit is contained in:
Oliver Gierke
2016-12-19 19:42:23 +01:00
committed by Christoph Strobl
parent 9a0241992e
commit 3355a436c8
5 changed files with 24 additions and 16 deletions

View File

@@ -47,7 +47,7 @@ import com.mongodb.client.model.IndexOptions;
*/
public class DefaultIndexOperations implements IndexOperations {
public static final String PARTIAL_FILTER_EXPRESSION_KEY = "partialFilterExpression";
private static final String PARTIAL_FILTER_EXPRESSION_KEY = "partialFilterExpression";
private final MongoDbFactory mongoDbFactory;
private final String collectionName;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016. the original author or authors.
* Copyright 2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@@ -28,6 +28,8 @@ import org.bson.Document;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
import com.mongodb.DBObject;
/**
* @author Mark Pollack
* @author Oliver Gierke
@@ -76,10 +78,13 @@ public class IndexInfo {
Object value = keyDbObject.get(key);
if (TWO_D_IDENTIFIERS.contains(value)) {
indexFields.add(IndexField.geo(key));
} else if ("text".equals(value)) {
Document weights = (Document) sourceDocument.get("weights");
for (String fieldName : weights.keySet()) {
indexFields.add(IndexField.text(fieldName, Float.valueOf(weights.get(fieldName).toString())));
}

View File

@@ -16,8 +16,12 @@
package org.springframework.data.mongodb.core.index;
import org.bson.Document;
import lombok.AccessLevel;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
import org.springframework.util.Assert;
import com.mongodb.DBObject;
@@ -28,15 +32,10 @@ import com.mongodb.DBObject;
* @author Christoph Strobl
* @since 1.10
*/
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public class PartialIndexFilter implements IndexFilter {
private final Object filterExpression;
private PartialIndexFilter(Object filterExpression) {
Assert.notNull(filterExpression, "FilterExpression must not be null!");
this.filterExpression = filterExpression;
}
private final @NonNull Object filterExpression;
/**
* Create new {@link PartialIndexFilter} for given {@link DBObject filter expression}.
@@ -44,7 +43,7 @@ public class PartialIndexFilter implements IndexFilter {
* @param where must not be {@literal null}.
* @return
*/
public static PartialIndexFilter filter(Document where) {
public static PartialIndexFilter of(Document where) {
return new PartialIndexFilter(where);
}
@@ -54,10 +53,14 @@ public class PartialIndexFilter implements IndexFilter {
* @param where must not be {@literal null}.
* @return
*/
public static PartialIndexFilter filter(CriteriaDefinition where) {
public static PartialIndexFilter of(CriteriaDefinition where) {
return new PartialIndexFilter(where);
}
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.index.IndexFilter#getFilterObject()
*/
public Document getFilterObject() {
if (filterExpression instanceof Document) {

View File

@@ -100,7 +100,7 @@ public class DefaultIndexOperationsIntegrationTests {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
IndexDefinition id = new Index().named("partial-with-criteria").on("k3y", Direction.ASC)
.partial(filter(where("q-t-y").gte(10)));
.partial(of(where("q-t-y").gte(10)));
indexOps.ensureIndex(id);
@@ -117,7 +117,7 @@ public class DefaultIndexOperationsIntegrationTests {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
IndexDefinition id = new Index().named("partial-with-mapped-criteria").on("k3y", Direction.ASC)
.partial(filter(where("quantity").gte(10)));
.partial(of(where("quantity").gte(10)));
indexOps.ensureIndex(id);
@@ -134,7 +134,7 @@ public class DefaultIndexOperationsIntegrationTests {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
IndexDefinition id = new Index().named("partial-with-dbo").on("k3y", Direction.ASC)
.partial(filter(new org.bson.Document("qty", new org.bson.Document("$gte", 10))));
.partial(of(new org.bson.Document("qty", new org.bson.Document("$gte", 10))));
indexOps.ensureIndex(id);
@@ -151,7 +151,7 @@ public class DefaultIndexOperationsIntegrationTests {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
IndexDefinition id = new Index().named("partial-with-inheritance").on("k3y", Direction.ASC)
.partial(filter(where("age").gte(10)));
.partial(of(where("age").gte(10)));
indexOps = new DefaultIndexOperations(template.getMongoDbFactory(),
this.template.getCollectionName(DefaultIndexOperationsIntegrationTestsSample.class),