diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoFactoryBean.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoFactoryBean.java index 7a001bd12..8cb09fc79 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoFactoryBean.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoFactoryBean.java @@ -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, InitializingBean, D * (non-Javadoc) * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ + @SuppressWarnings("deprecation") public void afterPropertiesSet() throws Exception { Mongo mongo; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java index 0ba1db0ac..0a5e6d3d4 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/Index.java @@ -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; 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 fieldSpec = new LinkedHashMap(); + private final Map fieldSpec = new LinkedHashMap(); private String name; @@ -42,12 +44,37 @@ public class Index implements IndexDefinition { public Index() { } - public Index(String key, Order order) { - fieldSpec.put(key, order); + 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) { + 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 { 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; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java index 11c78383d..79cddfff3 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/index/IndexField.java @@ -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 @@ */ 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; * * @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 { } /** - * 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 { 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 { 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 { */ @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); } } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/SimpleMongoMappingContext.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/SimpleMongoMappingContext.java deleted file mode 100644 index 57e356ea0..000000000 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/SimpleMongoMappingContext.java +++ /dev/null @@ -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, MongoPersistentProperty> { - - /* - * (non-Javadoc) - * @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentEntity(org.springframework.data.util.TypeInformation) - */ - @Override - protected SimpleMongoPersistentEntity createPersistentEntity(TypeInformation typeInformation) { - return new SimpleMongoPersistentEntity(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 implements - MongoPersistentProperty { - - private static final List 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 createAssociation() { - return new Association(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 extends BasicPersistentEntity implements - MongoPersistentEntity { - - /** - * @param information - */ - public SimpleMongoPersistentEntity(TypeInformation 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; - } - } -} diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java index ab3e53bc6..5936218b7 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Order.java @@ -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 @@ */ 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(); } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java index 3fe766256..2b32629a7 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Query.java @@ -39,9 +39,7 @@ public class Query { private LinkedHashMap criteria = new LinkedHashMap(); 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 { 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 { } } - 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 { 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; } diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Sort.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Sort.java deleted file mode 100644 index a53682254..000000000 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/query/Sort.java +++ /dev/null @@ -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 fieldSpec = new LinkedHashMap(); - - 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; - } -} diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java index 978cebe3a..24e7c9981 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/MongoQueryCreator.java @@ -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. @@ -169,68 +169,68 @@ class MongoQueryCreator extends AbstractQueryCreator { PotentiallyConvertingIterator parameters) { switch (type) { - case AFTER: - case GREATER_THAN: - return criteria.gt(parameters.nextConverted(property)); - case GREATER_THAN_EQUAL: - return criteria.gte(parameters.nextConverted(property)); - case BEFORE: - case LESS_THAN: - return criteria.lt(parameters.nextConverted(property)); - case LESS_THAN_EQUAL: - return criteria.lte(parameters.nextConverted(property)); - case BETWEEN: - return criteria.gt(parameters.nextConverted(property)).lt(parameters.nextConverted(property)); - case IS_NOT_NULL: - return criteria.ne(null); - case IS_NULL: - return criteria.is(null); - case NOT_IN: - return criteria.nin(nextAsArray(parameters, property)); - case IN: - return criteria.in(nextAsArray(parameters, property)); - case LIKE: - case STARTING_WITH: - case ENDING_WITH: - case CONTAINING: - String value = parameters.next().toString(); - return criteria.regex(toLikeRegex(value, type)); - case REGEX: - return criteria.regex(parameters.next().toString()); - case EXISTS: - return criteria.exists((Boolean) parameters.next()); - case TRUE: - return criteria.is(true); - case FALSE: - return criteria.is(false); - case NEAR: + case AFTER: + case GREATER_THAN: + return criteria.gt(parameters.nextConverted(property)); + case GREATER_THAN_EQUAL: + return criteria.gte(parameters.nextConverted(property)); + case BEFORE: + case LESS_THAN: + return criteria.lt(parameters.nextConverted(property)); + case LESS_THAN_EQUAL: + return criteria.lte(parameters.nextConverted(property)); + case BETWEEN: + return criteria.gt(parameters.nextConverted(property)).lt(parameters.nextConverted(property)); + case IS_NOT_NULL: + return criteria.ne(null); + case IS_NULL: + return criteria.is(null); + case NOT_IN: + return criteria.nin(nextAsArray(parameters, property)); + case IN: + return criteria.in(nextAsArray(parameters, property)); + case LIKE: + case STARTING_WITH: + case ENDING_WITH: + case CONTAINING: + String value = parameters.next().toString(); + return criteria.regex(toLikeRegex(value, type)); + case REGEX: + return criteria.regex(parameters.next().toString()); + case EXISTS: + return criteria.exists((Boolean) parameters.next()); + case TRUE: + return criteria.is(true); + case FALSE: + return criteria.is(false); + case NEAR: - Distance distance = accessor.getMaxDistance(); - Point point = accessor.getGeoNearLocation(); - point = point == null ? nextAs(parameters, Point.class) : point; + Distance distance = accessor.getMaxDistance(); + Point point = accessor.getGeoNearLocation(); + point = point == null ? nextAs(parameters, Point.class) : point; - if (distance == null) { - return criteria.near(point); - } else { - if (distance.getMetric() != null) { - criteria.nearSphere(point); + if (distance == null) { + return criteria.near(point); } else { - criteria.near(point); + if (distance.getMetric() != null) { + criteria.nearSphere(point); + } else { + criteria.near(point); + } + criteria.maxDistance(distance.getNormalizedValue()); } - criteria.maxDistance(distance.getNormalizedValue()); - } - return criteria; + return criteria; - case WITHIN: - Object parameter = parameters.next(); - return criteria.within((Shape) parameter); - case SIMPLE_PROPERTY: - return criteria.is(parameters.nextConverted(property)); - case NEGATING_SIMPLE_PROPERTY: - return criteria.ne(parameters.nextConverted(property)); + case WITHIN: + Object parameter = parameters.next(); + return criteria.within((Shape) parameter); + case SIMPLE_PROPERTY: + return criteria.is(parameters.nextConverted(property)); + case NEGATING_SIMPLE_PROPERTY: + return criteria.ne(parameters.nextConverted(property)); + default: + throw new IllegalArgumentException("Unsupported keyword!"); } - - throw new IllegalArgumentException("Unsupported keyword!"); } /** @@ -268,15 +268,16 @@ class MongoQueryCreator extends AbstractQueryCreator { private String toLikeRegex(String source, Type type) { switch (type) { - case STARTING_WITH: - source = source + "*"; - break; - case ENDING_WITH: - source = "*" + source; - break; - case CONTAINING: - source = "*" + source + "*"; - break; + case STARTING_WITH: + source = source + "*"; + break; + case ENDING_WITH: + source = "*" + source; + break; + case CONTAINING: + source = "*" + source + "*"; + break; + default: } return source.replaceAll("\\*", ".*"); diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java index f769e7c52..0d92fe7b0 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/QueryUtils.java @@ -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 @@ */ 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; * * @author Oliver Gierke */ +@Deprecated public abstract class QueryUtils { private 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; diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java index 414244e94..4ae998db9 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/support/IndexEnsuringQueryCreationListener.java @@ -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; 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 indexInfo = coll.getIndexInfo(); @@ -322,7 +323,7 @@ public class MongoTemplateTests { List 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 { // 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")); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java index 2a12ccbaf..e095b32b1 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/MappingMongoConverterUnitTests.java @@ -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 { return m_property; } } - - private class LocalDateToDateConverter implements Converter { - - public Date convert(LocalDate source) { - return source.toDateMidnight().toDate(); - } - } - - private class DateToLocalDateConverter implements Converter { - - public LocalDate convert(Date source) { - return new LocalDate(source.getTime()); - } - } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/geo/GeoSpatialTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/geo/GeoSpatialTests.java index 4ede5c85a..da7e1ad3a 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/geo/GeoSpatialTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/geo/GeoSpatialTests.java @@ -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; 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; * 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 { List 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)); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java index 86cb4e64c..a92cf8969 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexFieldUnitTests.java @@ -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.*; 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; * * @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 { 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)); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java index de1156ba8..cf4bdb828 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/index/IndexInfoUnitTests.java @@ -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.*; 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 { @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)); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/CustomCollectionWithIndex.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/CustomCollectionWithIndex.java index 206115562..5445840ad 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/CustomCollectionWithIndex.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/CustomCollectionWithIndex.java @@ -1,11 +1,11 @@ /* - * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -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 + * @author Jon Brisbin */ @Document(collection = "foobar") public class CustomCollectionWithIndex { @Id - @SuppressWarnings("unused") private String id; @Indexed private String name; diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/DetectedCollectionWithIndex.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/DetectedCollectionWithIndex.java index ee76c6aec..20a4edd8c 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/DetectedCollectionWithIndex.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/DetectedCollectionWithIndex.java @@ -1,11 +1,11 @@ /* - * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -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 + * @author Jon Brisbin */ @Document public class DetectedCollectionWithIndex { @Id - @SuppressWarnings("unused") private String id; @Indexed private String name; diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java index 7386bce73..c25754c41 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/MappingTests.java @@ -1,11 +1,11 @@ /* - * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -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; 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; import com.mongodb.MongoException; /** - * @author Jon Brisbin + * @author Jon Brisbin + * @author Oliver Gierke */ 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 people = template.find(q, PersonPojoStringId.class); assertEquals(2, people.size()); diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection1.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection1.java index d22a8cd5a..3e713b035 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection1.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection1.java @@ -1,11 +1,11 @@ /* - * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -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 + * @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); } - } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection2.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection2.java index af2265d7e..d1b2d3b77 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection2.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonCustomCollection2.java @@ -1,11 +1,11 @@ /* - * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -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 + * @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) { diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonMultiDimArrays.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonMultiDimArrays.java index 3ae66363e..6981a43ab 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonMultiDimArrays.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/PersonMultiDimArrays.java @@ -1,11 +1,11 @@ /* - * 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. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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, @@ -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 + * @author Jon Brisbin */ @Document public class PersonMultiDimArrays extends BasePerson { @Id - @SuppressWarnings("unused") private String id; private String[][] grid; diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/SimpleMappingContextUnitTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/SimpleMappingContextUnitTests.java deleted file mode 100644 index 6fb6a2826..000000000 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/mapping/SimpleMappingContextUnitTests.java +++ /dev/null @@ -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; - } -} diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexTests.java index 10b684786..e073a08d7 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/IndexTests.java @@ -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 @@ */ 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 { @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 { @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 { @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}")); } } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java index f7415bbc2..0063226f0 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/QueryTests.java @@ -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}")); } diff --git a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java index e460d2ef9..6450ac7d6 100644 --- a/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java +++ b/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/query/SortTests.java @@ -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; 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 { */ @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}")); } }