Browse Source

DATAMONGO-667 - Removed deprecated types and added further deprecations.

Removed Sort in favor of Sort in Spring Data Commons. Deprecated Order in favor of Direction in Spring Data Commons. Changed implementation to use the types from Spring Data Commons.
pull/30/merge
Oliver Gierke 13 years ago
parent
commit
0eb315a758
  1. 3
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoFactoryBean.java
  2. 37
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java
  3. 45
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java
  4. 167
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/SimpleMongoMappingContext.java
  5. 26
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java
  6. 36
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java
  7. 56
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Sort.java
  8. 7
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java
  9. 50
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java
  10. 15
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java
  11. 3
      spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/MongoAnnotationProcessor.java
  12. 11
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/MongoTemplateTests.java
  13. 15
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java
  14. 5
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/geo/GeoSpatialTests.java
  15. 13
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java
  16. 8
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java
  17. 7
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/CustomCollectionWithIndex.java
  18. 7
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/DetectedCollectionWithIndex.java
  19. 11
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java
  20. 8
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection1.java
  21. 7
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection2.java
  22. 7
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonMultiDimArrays.java
  23. 32
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/SimpleMappingContextUnitTests.java
  24. 18
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexTests.java
  25. 15
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java
  26. 18
      spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2010-2012 the original author or authors.
* Copyright 2010-2013 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.
@ -117,6 +117,7 @@ public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean, D @@ -117,6 +117,7 @@ public class MongoFactoryBean implements FactoryBean<Mongo>, InitializingBean, D
* (non-Javadoc)
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
*/
@SuppressWarnings("deprecation")
public void afterPropertiesSet() throws Exception {
Mongo mongo;

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2010-2011 the original author or authors.
* Copyright 2010-2013 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.
@ -18,18 +18,20 @@ package org.springframework.data.mongodb.core.index; @@ -18,18 +18,20 @@ package org.springframework.data.mongodb.core.index;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.query.Order;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
@SuppressWarnings("deprecation")
public class Index implements IndexDefinition {
public enum Duplicates {
RETAIN, DROP
}
private final Map<String, Order> fieldSpec = new LinkedHashMap<String, Order>();
private final Map<String, Direction> fieldSpec = new LinkedHashMap<String, Direction>();
private String name;
@ -42,12 +44,37 @@ public class Index implements IndexDefinition { @@ -42,12 +44,37 @@ public class Index implements IndexDefinition {
public Index() {
}
public Index(String key, Direction direction) {
fieldSpec.put(key, direction);
}
/**
* Creates a new {@link Indexed} on the given key and {@link Order}.
*
* @deprecated use {@link #Index(String, Direction)} instead.
* @param key must not be {@literal null} or empty.
* @param order must not be {@literal null}.
*/
@Deprecated
public Index(String key, Order order) {
fieldSpec.put(key, order);
this(key, order.toDirection());
}
/**
* Adds the given field to the index.
*
* @deprecated use {@link #on(String, Direction)} instead.
* @param key must not be {@literal null} or empty.
* @param order must not be {@literal null}.
* @return
*/
@Deprecated
public Index on(String key, Order order) {
fieldSpec.put(key, order);
return on(key, order.toDirection());
}
public Index on(String key, Direction direction) {
fieldSpec.put(key, direction);
return this;
}
@ -76,7 +103,7 @@ public class Index implements IndexDefinition { @@ -76,7 +103,7 @@ public class Index implements IndexDefinition {
public DBObject getIndexKeys() {
DBObject dbo = new BasicDBObject();
for (String k : fieldSpec.keySet()) {
dbo.put(k, (fieldSpec.get(k).equals(Order.ASCENDING) ? 1 : -1));
dbo.put(k, fieldSpec.get(k).equals(Direction.ASC) ? 1 : -1);
}
return dbo;
}

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

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2013 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.
@ -15,6 +15,7 @@ @@ -15,6 +15,7 @@
*/
package org.springframework.data.mongodb.core.index;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.query.Order;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@ -24,30 +25,38 @@ import org.springframework.util.ObjectUtils; @@ -24,30 +25,38 @@ import org.springframework.util.ObjectUtils;
*
* @author Oliver Gierke
*/
@SuppressWarnings("deprecation")
public final class IndexField {
private final String key;
private final Order order;
private final Direction direction;
private final boolean isGeo;
private IndexField(String key, Order order, boolean isGeo) {
private IndexField(String key, Direction direction, boolean isGeo) {
Assert.hasText(key);
Assert.isTrue(order != null ^ isGeo);
Assert.isTrue(direction != null ^ isGeo);
this.key = key;
this.order = order;
this.direction = direction;
this.isGeo = isGeo;
}
/**
* Creates a default {@link IndexField} with the given key and {@link Order}.
*
* @deprecated use {@link #create(String, Direction)}.
* @param key must not be {@literal null} or emtpy.
* @param order must not be {@literal null}.
* @param direction must not be {@literal null}.
* @return
*/
@Deprecated
public static IndexField create(String key, Order order) {
Assert.notNull(order);
return new IndexField(key, order.toDirection(), false);
}
public static IndexField create(String key, Direction order) {
Assert.notNull(order);
return new IndexField(key, order, false);
}
@ -70,12 +79,23 @@ public final class IndexField { @@ -70,12 +79,23 @@ public final class IndexField {
}
/**
* Returns the order of the {@link IndexField} or {@literal null} in case we have a geo index field.
* Returns the direction of the {@link IndexField} or {@literal null} in case we have a geo index field.
*
* @return the order
* @deprecated use {@link #getDirection()} instead.
* @return the direction
*/
@Deprecated
public Order getOrder() {
return order;
return Direction.ASC.equals(direction) ? Order.ASCENDING : Order.DESCENDING;
}
/**
* Returns the direction of the {@link IndexField} or {@literal null} in case we have a geo index field.
*
* @return the direction
*/
public Direction getDirection() {
return direction;
}
/**
@ -104,7 +124,8 @@ public final class IndexField { @@ -104,7 +124,8 @@ public final class IndexField {
IndexField that = (IndexField) obj;
return this.key.equals(that.key) && ObjectUtils.nullSafeEquals(this.order, that.order) && this.isGeo == that.isGeo;
return this.key.equals(that.key) && ObjectUtils.nullSafeEquals(this.direction, that.direction)
&& this.isGeo == that.isGeo;
}
/*
@ -116,7 +137,7 @@ public final class IndexField { @@ -116,7 +137,7 @@ public final class IndexField {
int result = 17;
result += 31 * ObjectUtils.nullSafeHashCode(key);
result += 31 * ObjectUtils.nullSafeHashCode(order);
result += 31 * ObjectUtils.nullSafeHashCode(direction);
result += 31 * ObjectUtils.nullSafeHashCode(isGeo);
return result;
}
@ -127,6 +148,6 @@ public final class IndexField { @@ -127,6 +148,6 @@ public final class IndexField {
*/
@Override
public String toString() {
return String.format("IndexField [ key: %s, order: %s, isGeo: %s]", key, order, isGeo);
return String.format("IndexField [ key: %s, direction: %s, isGeo: %s]", key, direction, isGeo);
}
}

167
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/SimpleMongoMappingContext.java

@ -1,167 +0,0 @@ @@ -1,167 +0,0 @@
/*
* Copyright 2012-2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core.mapping;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import org.springframework.data.mapping.Association;
import org.springframework.data.mapping.context.AbstractMappingContext;
import org.springframework.data.mapping.model.AbstractPersistentProperty;
import org.springframework.data.mapping.model.BasicPersistentEntity;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.mongodb.MongoCollectionUtils;
import org.springframework.data.util.TypeInformation;
/**
* @deprecated use {@link MongoMappingContext} instead.
* @author Oliver Gierke
*/
@Deprecated
public class SimpleMongoMappingContext extends
AbstractMappingContext<SimpleMongoMappingContext.SimpleMongoPersistentEntity<?>, MongoPersistentProperty> {
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentEntity(org.springframework.data.util.TypeInformation)
*/
@Override
protected <T> SimpleMongoPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) {
return new SimpleMongoPersistentEntity<T>(typeInformation);
}
/*
* (non-Javadoc)
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentProperty(java.lang.reflect.Field, java.beans.PropertyDescriptor, org.springframework.data.mapping.model.MutablePersistentEntity, org.springframework.data.mapping.model.SimpleTypeHolder)
*/
@Override
protected SimplePersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor,
SimpleMongoPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) {
return new SimplePersistentProperty(field, descriptor, owner, simpleTypeHolder);
}
static class SimplePersistentProperty extends AbstractPersistentProperty<MongoPersistentProperty> implements
MongoPersistentProperty {
private static final List<String> ID_FIELD_NAMES = Arrays.asList("id", "_id");
/**
* Creates a new {@link SimplePersistentProperty}.
*
* @param field
* @param propertyDescriptor
* @param information
*/
public SimplePersistentProperty(Field field, PropertyDescriptor propertyDescriptor, MongoPersistentEntity<?> owner,
SimpleTypeHolder simpleTypeHolder) {
super(field, propertyDescriptor, owner, simpleTypeHolder);
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.BasicPersistentProperty#isIdProperty()
*/
public boolean isIdProperty() {
return ID_FIELD_NAMES.contains(field.getName());
}
/* (non-Javadoc)
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#getKey()
*/
public String getFieldName() {
return isIdProperty() ? "_id" : getName();
}
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#getFieldOrder()
*/
public int getFieldOrder() {
return Integer.MAX_VALUE;
}
/* (non-Javadoc)
* @see org.springframework.data.mapping.AbstractPersistentProperty#createAssociation()
*/
@Override
protected Association<MongoPersistentProperty> createAssociation() {
return new Association<MongoPersistentProperty>(this, null);
}
/* (non-Javadoc)
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#isDbReference()
*/
public boolean isDbReference() {
return false;
}
/* (non-Javadoc)
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#getDBRef()
*/
public DBRef getDBRef() {
return null;
}
/* (non-Javadoc)
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#isVersion()
*/
public boolean isVersionProperty() {
return false;
}
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.mapping.MongoPersistentProperty#usePropertyAccess()
*/
public boolean usePropertyAccess() {
return false;
}
}
static class SimpleMongoPersistentEntity<T> extends BasicPersistentEntity<T, MongoPersistentProperty> implements
MongoPersistentEntity<T> {
/**
* @param information
*/
public SimpleMongoPersistentEntity(TypeInformation<T> information) {
super(information);
}
/* (non-Javadoc)
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentEntity#getCollection()
*/
public String getCollection() {
return MongoCollectionUtils.getPreferredCollectionName(getType());
}
/* (non-Javadoc)
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentEntity#getVersionProperty()
*/
public MongoPersistentProperty getVersionProperty() {
return null;
}
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.mapping.MongoPersistentEntity#hasVersionProperty()
*/
public boolean hasVersionProperty() {
return false;
}
}
}

26
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2010-2011 the original author or authors.
* Copyright 2010-2013 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.
@ -15,11 +15,31 @@ @@ -15,11 +15,31 @@
*/
package org.springframework.data.mongodb.core.query;
import org.springframework.data.domain.Sort.Direction;
/**
* An enum that specifies the ordering for sort or index specifications
*
* @author trisberg
* @deprecated prefer {@link Direction}
* @author Thomas Risberg
* @author Oliver Gierke
*/
@Deprecated
public enum Order {
ASCENDING, DESCENDING
ASCENDING {
@Override
public Direction toDirection() {
return Direction.ASC;
}
},
DESCENDING {
@Override
public Direction toDirection() {
return Direction.DESC;
}
};
public abstract Direction toDirection();
}

36
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java

@ -39,9 +39,7 @@ public class Query { @@ -39,9 +39,7 @@ public class Query {
private LinkedHashMap<String, Criteria> criteria = new LinkedHashMap<String, Criteria>();
private Field fieldSpec;
private Sort coreSort;
@SuppressWarnings("deprecation")
private org.springframework.data.mongodb.core.query.Sort sort;
private Sort sort;
private int skip;
private int limit;
private String hint;
@ -116,21 +114,6 @@ public class Query { @@ -116,21 +114,6 @@ public class Query {
return this;
}
/**
* Returns a {@link org.springframework.data.mongodb.core.query.Sort} instance to define ordering properties.
*
* @deprecated use {@link #with(Sort)} instead
* @return
*/
@Deprecated
public org.springframework.data.mongodb.core.query.Sort sort() {
if (this.sort == null) {
this.sort = new org.springframework.data.mongodb.core.query.Sort();
}
return this.sort;
}
/**
* Sets the given pagination information on the {@link Query} instance. Will transparently set {@code skip} and
* {@code limit} as well as applying the {@link Sort} instance defined with the {@link Pageable}.
@ -169,10 +152,10 @@ public class Query { @@ -169,10 +152,10 @@ public class Query {
}
}
if (this.coreSort == null) {
this.coreSort = sort;
if (this.sort == null) {
this.sort = sort;
} else {
this.coreSort = this.coreSort.and(sort);
this.sort = this.sort.and(sort);
}
return this;
@ -195,25 +178,20 @@ public class Query { @@ -195,25 +178,20 @@ public class Query {
return fieldSpec.getFieldsObject();
}
@SuppressWarnings("deprecation")
public DBObject getSortObject() {
if (this.coreSort == null && this.sort == null) {
if (this.sort == null && this.sort == null) {
return null;
}
DBObject dbo = new BasicDBObject();
if (this.coreSort != null) {
for (org.springframework.data.domain.Sort.Order order : this.coreSort) {
if (this.sort != null) {
for (org.springframework.data.domain.Sort.Order order : this.sort) {
dbo.put(order.getProperty(), order.isAscending() ? 1 : -1);
}
}
if (this.sort != null) {
dbo.putAll(this.sort.getSortObject());
}
return dbo;
}

56
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Sort.java

@ -1,56 +0,0 @@ @@ -1,56 +0,0 @@
/*
* Copyright 2010-2012 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core.query;
import java.util.LinkedHashMap;
import java.util.Map;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
/**
* Helper class to define sorting criterias for a Query instance.
*
* @author Thomas Risberg
* @author Oliver Gierke
* @deprecated use {@link org.springframework.data.domain.Sort} instead. See
* {@link Query#with(org.springframework.data.domain.Sort)}.
*/
@Deprecated
public class Sort {
private Map<String, Order> fieldSpec = new LinkedHashMap<String, Order>();
public Sort() {
}
public Sort(String key, Order order) {
fieldSpec.put(key, order);
}
public Sort on(String key, Order order) {
fieldSpec.put(key, order);
return this;
}
public DBObject getSortObject() {
DBObject dbo = new BasicDBObject();
for (String k : fieldSpec.keySet()) {
dbo.put(k, fieldSpec.get(k).equals(Order.ASCENDING) ? 1 : -1);
}
return dbo;
}
}

7
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2010-2012 the original author or authors.
* Copyright 2010-2013 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.
@ -228,10 +228,10 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> { @@ -228,10 +228,10 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
return criteria.is(parameters.nextConverted(property));
case NEGATING_SIMPLE_PROPERTY:
return criteria.ne(parameters.nextConverted(property));
}
default:
throw new IllegalArgumentException("Unsupported keyword!");
}
}
/**
* Returns the next element from the given {@link Iterator} expecting it to be of a certain type.
@ -277,6 +277,7 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> { @@ -277,6 +277,7 @@ class MongoQueryCreator extends AbstractQueryCreator<Query, Criteria> {
case CONTAINING:
source = "*" + source + "*";
break;
default:
}
return source.replaceAll("\\*", ".*");

50
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2010-2012 the original author or authors.
* Copyright 2010-2013 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.
@ -15,10 +15,7 @@ @@ -15,10 +15,7 @@
*/
package org.springframework.data.mongodb.repository.query;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.mongodb.core.query.Query;
import com.mongodb.DBCursor;
@ -27,6 +24,7 @@ import com.mongodb.DBCursor; @@ -27,6 +24,7 @@ import com.mongodb.DBCursor;
*
* @author Oliver Gierke
*/
@Deprecated
public abstract class QueryUtils {
private QueryUtils() {
@ -34,51 +32,13 @@ public abstract class QueryUtils { @@ -34,51 +32,13 @@ public abstract class QueryUtils {
}
/**
* Applies the given {@link Pageable} to the given {@link Query}. Will do nothing if {@link Pageable} is
* {@literal null}.
* Turns an {@link Order} into an {@link org.springframework.data.mongodb.core.query.Order}.
*
* @deprecated use {@link Query#with(Pageable)}.
* @param query must not be {@literal null}.
* @param pageable
* @deprecated use {@link Order} directly.
* @param order
* @return
*/
@Deprecated
public static Query applyPagination(Query query, Pageable pageable) {
if (pageable == null) {
return query;
}
query.limit(pageable.getPageSize());
query.skip(pageable.getOffset());
return query.with(pageable.getSort());
}
/**
* Applies the given {@link Sort} to the {@link Query}. Will do nothing if {@link Sort} is {@literal null}.
*
* @deprecated use {@link Query#with(Pageable)}.
* @param query must not be {@literal null}.
* @param sort
* @return
*/
@Deprecated
public static Query applySorting(Query query, Sort sort) {
if (sort == null) {
return query;
}
org.springframework.data.mongodb.core.query.Sort bSort = query.sort();
for (Order order : sort) {
bSort.on(order.getProperty(), toOrder(order));
}
return query;
}
public static org.springframework.data.mongodb.core.query.Order toOrder(Order order) {
return order.isAscending() ? org.springframework.data.mongodb.core.query.Order.ASCENDING
: org.springframework.data.mongodb.core.query.Order.DESCENDING;

15
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2011-2012 the original author or authors.
* Copyright 2011-2013 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.
@ -22,12 +22,11 @@ import java.util.Set; @@ -22,12 +22,11 @@ import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.data.mongodb.core.query.Order;
import org.springframework.data.mongodb.repository.query.MongoEntityMetadata;
import org.springframework.data.mongodb.repository.query.PartTreeMongoQuery;
import org.springframework.data.mongodb.repository.query.QueryUtils;
import org.springframework.data.repository.core.support.QueryCreationListener;
import org.springframework.data.repository.query.parser.Part;
import org.springframework.data.repository.query.parser.Part.Type;
@ -74,14 +73,14 @@ class IndexEnsuringQueryCreationListener implements QueryCreationListener<PartTr @@ -74,14 +73,14 @@ class IndexEnsuringQueryCreationListener implements QueryCreationListener<PartTr
return;
}
String property = part.getProperty().toDotPath();
Order order = toOrder(sort, property);
Direction order = toDirection(sort, property);
index.on(property, order);
}
// Add fixed sorting criteria to index
if (sort != null) {
for (Sort.Order order : sort) {
index.on(order.getProperty(), QueryUtils.toOrder(order));
index.on(order.getProperty(), order.getDirection());
}
}
@ -90,13 +89,13 @@ class IndexEnsuringQueryCreationListener implements QueryCreationListener<PartTr @@ -90,13 +89,13 @@ class IndexEnsuringQueryCreationListener implements QueryCreationListener<PartTr
LOG.debug(String.format("Created %s!", index));
}
private static Order toOrder(Sort sort, String property) {
private static Direction toDirection(Sort sort, String property) {
if (sort == null) {
return Order.DESCENDING;
return Direction.DESC;
}
org.springframework.data.domain.Sort.Order order = sort.getOrderFor(property);
return order == null ? Order.DESCENDING : order.isAscending() ? Order.ASCENDING : Order.DESCENDING;
return order == null ? Direction.DESC : order.isAscending() ? Direction.ASC : Direction.DESC;
}
}

3
spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/MongoAnnotationProcessor.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2013 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.
@ -39,7 +39,6 @@ import com.mysema.query.apt.DefaultConfiguration; @@ -39,7 +39,6 @@ import com.mysema.query.apt.DefaultConfiguration;
*
* @author Oliver Gierke
*/
@SuppressWarnings("restriction")
@SupportedAnnotationTypes({ "com.mysema.query.annotations.*", "org.springframework.data.mongodb.core.mapping.*" })
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class MongoAnnotationProcessor extends AbstractQuerydslProcessor {

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

@ -50,6 +50,8 @@ import org.springframework.dao.OptimisticLockingFailureException; @@ -50,6 +50,8 @@ import org.springframework.dao.OptimisticLockingFailureException;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.Version;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mapping.model.MappingException;
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
import org.springframework.data.mongodb.MongoDbFactory;
@ -62,7 +64,6 @@ import org.springframework.data.mongodb.core.index.IndexInfo; @@ -62,7 +64,6 @@ import org.springframework.data.mongodb.core.index.IndexInfo;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Order;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.test.context.ContextConfiguration;
@ -235,7 +236,7 @@ public class MongoTemplateTests { @@ -235,7 +236,7 @@ public class MongoTemplateTests {
MongoTemplate template = new MongoTemplate(factory);
template.setWriteResultChecking(WriteResultChecking.EXCEPTION);
template.indexOps(Person.class).ensureIndex(new Index().on("firstName", Order.DESCENDING).unique());
template.indexOps(Person.class).ensureIndex(new Index().on("firstName", Direction.DESC).unique());
Person person = new Person(new ObjectId(), "Amol");
person.setAge(28);
@ -292,7 +293,7 @@ public class MongoTemplateTests { @@ -292,7 +293,7 @@ public class MongoTemplateTests {
p2.setAge(40);
template.insert(p2);
template.indexOps(Person.class).ensureIndex(new Index().on("age", Order.DESCENDING).unique(Duplicates.DROP));
template.indexOps(Person.class).ensureIndex(new Index().on("age", Direction.DESC).unique(Duplicates.DROP));
DBCollection coll = template.getCollection(template.getCollectionName(Person.class));
List<DBObject> indexInfo = coll.getIndexInfo();
@ -322,7 +323,7 @@ public class MongoTemplateTests { @@ -322,7 +323,7 @@ public class MongoTemplateTests {
List<IndexField> indexFields = ii.getIndexFields();
IndexField field = indexFields.get(0);
assertThat(field, is(IndexField.create("age", Order.DESCENDING)));
assertThat(field, is(IndexField.create("age", Direction.DESC)));
}
@Test
@ -949,7 +950,7 @@ public class MongoTemplateTests { @@ -949,7 +950,7 @@ public class MongoTemplateTests {
// test query with a sort
Query q2 = new Query(Criteria.where("age").gt(10));
q2.sort().on("age", Order.DESCENDING);
q2.with(new Sort(Direction.DESC, "age"));
PersonWithAList p5 = template.findOne(q2, PersonWithAList.class);
assertThat(p5.getFirstName(), is("Mark"));
}

15
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java

@ -46,7 +46,6 @@ import org.mockito.runners.MockitoJUnitRunner; @@ -46,7 +46,6 @@ import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.core.convert.converter.Converter;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.annotation.TypeAlias;
@ -1593,18 +1592,4 @@ public class MappingMongoConverterUnitTests { @@ -1593,18 +1592,4 @@ public class MappingMongoConverterUnitTests {
return m_property;
}
}
private class LocalDateToDateConverter implements Converter<LocalDate, Date> {
public Date convert(LocalDate source) {
return source.toDateMidnight().toDate();
}
}
private class DateToLocalDateConverter implements Converter<Date, LocalDate> {
public LocalDate convert(Date source) {
return new LocalDate(source.getTime());
}
}
}

5
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/geo/GeoSpatialTests.java

@ -33,6 +33,7 @@ import org.junit.Test; @@ -33,6 +33,7 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.CollectionCallback;
import org.springframework.data.mongodb.core.IndexOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
@ -41,7 +42,6 @@ import org.springframework.data.mongodb.core.index.GeospatialIndex; @@ -41,7 +42,6 @@ import org.springframework.data.mongodb.core.index.GeospatialIndex;
import org.springframework.data.mongodb.core.index.IndexField;
import org.springframework.data.mongodb.core.index.IndexInfo;
import org.springframework.data.mongodb.core.query.NearQuery;
import org.springframework.data.mongodb.core.query.Order;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.monitor.ServerInfo;
import org.springframework.expression.ExpressionParser;
@ -58,6 +58,7 @@ import com.mongodb.WriteConcern; @@ -58,6 +58,7 @@ import com.mongodb.WriteConcern;
* Modified from https://github.com/deftlabs/mongo-java-geospatial-example
*
* @author Mark Pollack
* @author Oliver Gierke
*/
public class GeoSpatialTests {
@ -211,7 +212,7 @@ public class GeoSpatialTests { @@ -211,7 +212,7 @@ public class GeoSpatialTests {
List<IndexField> fields = indexInfo.get(0).getIndexFields();
assertThat(fields.size(), is(1));
assertThat(fields, hasItem(IndexField.create("_id", Order.ASCENDING)));
assertThat(fields, hasItem(IndexField.create("_id", Direction.ASC)));
fields = indexInfo.get(1).getIndexFields();
assertThat(fields.size(), is(1));

13
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2013 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.
@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*; @@ -19,6 +19,7 @@ import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.query.Order;
/**
@ -26,14 +27,16 @@ import org.springframework.data.mongodb.core.query.Order; @@ -26,14 +27,16 @@ import org.springframework.data.mongodb.core.query.Order;
*
* @author Oliver Gierke
*/
@SuppressWarnings("deprecation")
public class IndexFieldUnitTests {
@Test
public void createsPlainIndexFieldCorrectly() {
IndexField field = IndexField.create("foo", Order.ASCENDING);
IndexField field = IndexField.create("foo", Direction.ASC);
assertThat(field.getKey(), is("foo"));
assertThat(field.getDirection(), is(Direction.ASC));
assertThat(field.getOrder(), is(Order.ASCENDING));
assertThat(field.isGeo(), is(false));
}
@ -44,15 +47,15 @@ public class IndexFieldUnitTests { @@ -44,15 +47,15 @@ public class IndexFieldUnitTests {
IndexField field = IndexField.geo("foo");
assertThat(field.getKey(), is("foo"));
assertThat(field.getOrder(), is(nullValue()));
assertThat(field.getDirection(), is(nullValue()));
assertThat(field.isGeo(), is(true));
}
@Test
public void correctEqualsForPlainFields() {
IndexField first = IndexField.create("foo", Order.ASCENDING);
IndexField second = IndexField.create("foo", Order.ASCENDING);
IndexField first = IndexField.create("foo", Direction.ASC);
IndexField second = IndexField.create("foo", Direction.ASC);
assertThat(first, is(second));
assertThat(second, is(first));

8
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2012 the original author or authors.
* Copyright 2012-2013 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.
@ -21,7 +21,7 @@ import static org.junit.Assert.*; @@ -21,7 +21,7 @@ import static org.junit.Assert.*;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.data.mongodb.core.query.Order;
import org.springframework.data.domain.Sort.Direction;
/**
* Unit tests for {@link IndexInfo}.
@ -33,8 +33,8 @@ public class IndexInfoUnitTests { @@ -33,8 +33,8 @@ public class IndexInfoUnitTests {
@Test
public void isIndexForFieldsCorrectly() {
IndexField fooField = IndexField.create("foo", Order.ASCENDING);
IndexField barField = IndexField.create("bar", Order.DESCENDING);
IndexField fooField = IndexField.create("foo", Direction.ASC);
IndexField barField = IndexField.create("bar", Direction.DESC);
IndexInfo info = new IndexInfo(Arrays.asList(fooField, barField), "myIndex", false, false, false);
assertThat(info.isIndexForFields(Arrays.asList("foo", "bar")), is(true));

7
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/CustomCollectionWithIndex.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 by the original author(s).
* Copyright 2011-2013 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.
@ -13,21 +13,18 @@ @@ -13,21 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core.mapping;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Jon Brisbin <jbrisbin@vmware.com>
* @author Jon Brisbin
*/
@Document(collection = "foobar")
public class CustomCollectionWithIndex {
@Id
@SuppressWarnings("unused")
private String id;
@Indexed
private String name;

7
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/DetectedCollectionWithIndex.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 by the original author(s).
* Copyright 2011-2013 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.
@ -13,21 +13,18 @@ @@ -13,21 +13,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core.mapping;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Jon Brisbin <jbrisbin@vmware.com>
* @author Jon Brisbin
*/
@Document
public class DetectedCollectionWithIndex {
@Id
@SuppressWarnings("unused")
private String id;
@Indexed
private String name;

11
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 by the original author(s).
* Copyright 2011-2013 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.
@ -13,7 +13,6 @@ @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core.mapping;
import static org.hamcrest.Matchers.*;
@ -37,12 +36,13 @@ import org.springframework.context.ApplicationContext; @@ -37,12 +36,13 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;
import org.springframework.data.annotation.Id;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.MongoCollectionUtils;
import org.springframework.data.mongodb.core.CollectionCallback;
import org.springframework.data.mongodb.core.MongoDbUtils;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Order;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.test.util.ReflectionTestUtils;
@ -53,7 +53,8 @@ import com.mongodb.Mongo; @@ -53,7 +53,8 @@ import com.mongodb.Mongo;
import com.mongodb.MongoException;
/**
* @author Jon Brisbin <jbrisbin@vmware.com>
* @author Jon Brisbin
* @author Oliver Gierke
*/
public class MappingTests {
@ -464,7 +465,7 @@ public class MappingTests { @@ -464,7 +465,7 @@ public class MappingTests {
template.insert(p4);
Query q = query(where("id").in("1", "2"));
q.sort().on("id", Order.ASCENDING);
q.with(new Sort(Direction.ASC, "id"));
List<PersonPojoStringId> people = template.find(q, PersonPojoStringId.class);
assertEquals(2, people.size());

8
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection1.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 by the original author(s).
* Copyright 2011-2013 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.
@ -13,24 +13,20 @@ @@ -13,24 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core.mapping;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Jon Brisbin <jbrisbin@vmware.com>
* @author Jon Brisbin
*/
@Document(collection = "person1")
public class PersonCustomCollection1 extends BasePerson {
@Id
@SuppressWarnings("unused")
private String id;
public PersonCustomCollection1(Integer ssn, String firstName, String lastName) {
super(ssn, firstName, lastName);
}
}

7
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection2.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 by the original author(s).
* Copyright 2011-2013 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.
@ -13,20 +13,17 @@ @@ -13,20 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core.mapping;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Jon Brisbin <jbrisbin@vmware.com>
* @author Jon Brisbin
*/
@Document(collection = "person2")
public class PersonCustomCollection2 extends BasePerson {
@Id
@SuppressWarnings("unused")
private String id;
public PersonCustomCollection2(Integer ssn, String firstName, String lastName) {

7
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonMultiDimArrays.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright (c) 2011 by the original author(s).
* Copyright 2011-2013 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.
@ -13,20 +13,17 @@ @@ -13,20 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.mongodb.core.mapping;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* @author Jon Brisbin <jbrisbin@vmware.com>
* @author Jon Brisbin
*/
@Document
public class PersonMultiDimArrays extends BasePerson {
@Id
@SuppressWarnings("unused")
private String id;
private String[][] grid;

32
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/SimpleMappingContextUnitTests.java

@ -1,32 +0,0 @@ @@ -1,32 +0,0 @@
package org.springframework.data.mongodb.core.mapping;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
import org.springframework.data.mongodb.core.mapping.SimpleMongoMappingContext;
import org.springframework.data.mongodb.core.mapping.SimpleMongoMappingContext.SimpleMongoPersistentEntity;
/**
* Unit tests for {@link SimpleMongoMappingContext}.
*
* @author Oliver Gierke
*/
public class SimpleMappingContextUnitTests {
@Test
public void returnsIdPropertyCorrectly() {
SimpleMongoMappingContext context = new SimpleMongoMappingContext();
SimpleMongoPersistentEntity<?> entity = context.getPersistentEntity(Person.class);
MongoPersistentProperty idProperty = entity.getIdProperty();
assertThat(idProperty, is(notNullValue()));
assertThat(idProperty.getName(), is("id"));
}
static class Person {
String id;
}
}

18
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2010-2011 the original author or authors.
* Copyright 2010-2013 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.
@ -15,32 +15,32 @@ @@ -15,32 +15,32 @@
*/
package org.springframework.data.mongodb.core.query;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.mongodb.core.index.GeospatialIndex;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.data.mongodb.core.index.Index.Duplicates;
import org.springframework.data.mongodb.core.query.Order;
public class IndexTests {
@Test
public void testWithAscendingIndex() {
Index i = new Index().on("name", Order.ASCENDING);
Index i = new Index().on("name", Direction.ASC);
assertEquals("{ \"name\" : 1}", i.getIndexKeys().toString());
}
@Test
public void testWithDescendingIndex() {
Index i = new Index().on("name", Order.DESCENDING);
Index i = new Index().on("name", Direction.DESC);
assertEquals("{ \"name\" : -1}", i.getIndexKeys().toString());
}
@Test
public void testNamedMultiFieldUniqueIndex() {
Index i = new Index().on("name", Order.ASCENDING).on("age", Order.DESCENDING);
Index i = new Index().on("name", Direction.ASC).on("age", Direction.DESC);
i.named("test").unique();
assertEquals("{ \"name\" : 1 , \"age\" : -1}", i.getIndexKeys().toString());
assertEquals("{ \"name\" : \"test\" , \"unique\" : true}", i.getIndexOptions().toString());
@ -48,7 +48,7 @@ public class IndexTests { @@ -48,7 +48,7 @@ public class IndexTests {
@Test
public void testWithDropDuplicates() {
Index i = new Index().on("name", Order.ASCENDING);
Index i = new Index().on("name", Direction.ASC);
i.unique(Duplicates.DROP);
assertEquals("{ \"name\" : 1}", i.getIndexKeys().toString());
assertEquals("{ \"unique\" : true , \"dropDups\" : true}", i.getIndexOptions().toString());
@ -56,7 +56,7 @@ public class IndexTests { @@ -56,7 +56,7 @@ public class IndexTests {
@Test
public void testWithSparse() {
Index i = new Index().on("name", Order.ASCENDING);
Index i = new Index().on("name", Direction.ASC);
i.sparse().unique();
assertEquals("{ \"name\" : 1}", i.getIndexKeys().toString());
assertEquals("{ \"unique\" : true , \"sparse\" : true}", i.getIndexOptions().toString());
@ -72,7 +72,7 @@ public class IndexTests { @@ -72,7 +72,7 @@ public class IndexTests {
@Test
public void ensuresPropertyOrder() {
Index on = new Index("foo", Order.ASCENDING).on("bar", Order.ASCENDING);
Index on = new Index("foo", Direction.ASC).on("bar", Direction.ASC);
assertThat(on.getIndexKeys().toString(), is("{ \"foo\" : 1 , \"bar\" : 1}"));
}
}

15
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java

@ -177,26 +177,13 @@ public class QueryTests { @@ -177,26 +177,13 @@ public class QueryTests {
Assert.assertEquals(expected, q.getQueryObject().toString());
}
/**
* @see DATAMONGO-538
*/
@Test
@SuppressWarnings("deprecation")
public void addsDeprecatedSortCorrectly() {
Query query = new Query();
query.sort().on("foo", Order.DESCENDING);
assertThat(query.getSortObject().toString(), is("{ \"foo\" : -1}"));
}
/**
* @see DATAMONGO-538
*/
@Test
public void addsSortCorrectly() {
Query query = new Query().with(new org.springframework.data.domain.Sort(Direction.DESC, "foo"));
Query query = new Query().with(new Sort(Direction.DESC, "foo"));
assertThat(query.getSortObject().toString(), is("{ \"foo\" : -1}"));
}

18
spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2010-2012 the original author or authors.
* Copyright 2010-2013 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.
@ -17,22 +17,27 @@ package org.springframework.data.mongodb.core.query; @@ -17,22 +17,27 @@ package org.springframework.data.mongodb.core.query;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.springframework.data.mongodb.core.query.Order.*;
import org.junit.Test;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
@SuppressWarnings("deprecation")
/**
* Unit tests for sorting.
*
* @author Oliver Gierke
*/
public class SortTests {
@Test
public void testWithSortAscending() {
Sort s = new Sort().on("name", ASCENDING);
Query s = new Query().with(new Sort(Direction.ASC, "name"));
assertEquals("{ \"name\" : 1}", s.getSortObject().toString());
}
@Test
public void testWithSortDescending() {
Sort s = new Sort().on("name", DESCENDING);
Query s = new Query().with(new Sort(Direction.DESC, "name"));
assertEquals("{ \"name\" : -1}", s.getSortObject().toString());
}
@ -41,7 +46,8 @@ public class SortTests { @@ -41,7 +46,8 @@ public class SortTests {
*/
@Test
public void preservesOrderKeysOnMultipleSorts() {
Sort sort = new Sort("foo", DESCENDING).on("bar", DESCENDING);
Query sort = new Query().with(new Sort(Direction.DESC, "foo").and(new Sort(Direction.DESC, "bar")));
assertThat(sort.getSortObject().toString(), is("{ \"foo\" : -1 , \"bar\" : -1}"));
}
}

Loading…
Cancel
Save