66
66
import org .springframework .data .mongodb .core .aggregation .TypedAggregation ;
67
67
import org .springframework .data .mongodb .core .convert .DbRefResolver ;
68
68
import org .springframework .data .mongodb .core .convert .DefaultDbRefResolver ;
69
- import org .springframework .data .mongodb .core .convert .EntityBackedSortConverter ;
70
69
import org .springframework .data .mongodb .core .convert .MappingMongoConverter ;
71
70
import org .springframework .data .mongodb .core .convert .MongoConverter ;
72
71
import org .springframework .data .mongodb .core .convert .MongoWriter ;
73
72
import org .springframework .data .mongodb .core .convert .QueryMapper ;
74
- import org .springframework .data .mongodb .core .convert .SortConverter ;
75
73
import org .springframework .data .mongodb .core .convert .UpdateMapper ;
76
74
import org .springframework .data .mongodb .core .geo .GeoResults ;
77
75
import org .springframework .data .mongodb .core .index .MongoMappingEventPublisher ;
@@ -357,7 +355,7 @@ protected void logCommandExecutionError(final DBObject command, CommandResult re
357
355
}
358
356
359
357
public void executeQuery (Query query , String collectionName , DocumentCallbackHandler dch ) {
360
- executeQuery (query , collectionName , dch , new QueryCursorPreparer (query , new SortConverter () ));
358
+ executeQuery (query , collectionName , dch , new QueryCursorPreparer (query , null ));
361
359
}
362
360
363
361
/**
@@ -535,7 +533,7 @@ public <T> List<T> find(final Query query, Class<T> entityClass, String collecti
535
533
}
536
534
537
535
return doFind (collectionName , query .getQueryObject (), query .getFieldsObject (), entityClass ,
538
- new QueryCursorPreparer (query , new EntityBackedSortConverter ( mappingContext .getPersistentEntity (entityClass ) )));
536
+ new QueryCursorPreparer (query , mappingContext .getPersistentEntity (entityClass )));
539
537
}
540
538
541
539
public <T > T findById (Object id , Class <T > entityClass ) {
@@ -618,8 +616,7 @@ public <T> T findAndModify(Query query, Update update, FindAndModifyOptions opti
618
616
public <T > T findAndModify (Query query , Update update , FindAndModifyOptions options , Class <T > entityClass ,
619
617
String collectionName ) {
620
618
return doFindAndModify (collectionName , query .getQueryObject (), query .getFieldsObject (),
621
- new EntityBackedSortConverter (mappingContext .getPersistentEntity (entityClass )).convert (query .getSort ()),
622
- entityClass , update , options );
619
+ getMappedSortObject (query , mappingContext .getPersistentEntity (entityClass )), entityClass , update , options );
623
620
}
624
621
625
622
// Find methods that take a Query to express the query and that return a single object that is also removed from the
@@ -632,8 +629,7 @@ public <T> T findAndRemove(Query query, Class<T> entityClass) {
632
629
public <T > T findAndRemove (Query query , Class <T > entityClass , String collectionName ) {
633
630
634
631
return doFindAndRemove (collectionName , query .getQueryObject (), query .getFieldsObject (),
635
- new EntityBackedSortConverter (mappingContext .getPersistentEntity (entityClass )).convert (query .getSort ()),
636
- entityClass );
632
+ getMappedSortObject (query , mappingContext .getPersistentEntity (entityClass )), entityClass );
637
633
}
638
634
639
635
public long count (Query query , Class <?> entityClass ) {
@@ -1947,6 +1943,15 @@ private static final MongoConverter getDefaultMongoConverter(MongoDbFactory fact
1947
1943
return converter ;
1948
1944
}
1949
1945
1946
+ private DBObject getMappedSortObject (Query query , MongoPersistentEntity <?> entity ) {
1947
+
1948
+ if (query == null || query .getSortObject () == null ) {
1949
+ return null ;
1950
+ }
1951
+
1952
+ return queryMapper .getMappedObject (query .getSortObject (), entity );
1953
+ }
1954
+
1950
1955
// Callback implementations
1951
1956
1952
1957
/**
@@ -2140,13 +2145,12 @@ public WriteConcern resolve(MongoAction action) {
2140
2145
class QueryCursorPreparer implements CursorPreparer {
2141
2146
2142
2147
private final Query query ;
2143
- private final SortConverter sortConverter ;
2148
+ private final MongoPersistentEntity <?> entity ;
2144
2149
2145
- public QueryCursorPreparer (Query query , SortConverter sortConverter ) {
2150
+ public QueryCursorPreparer (Query query , MongoPersistentEntity <?> entity ) {
2146
2151
2147
- Assert .notNull (sortConverter , "SortConverter must not be null" );
2148
2152
this .query = query ;
2149
- this .sortConverter = sortConverter ;
2153
+ this .entity = entity ;
2150
2154
}
2151
2155
2152
2156
/*
@@ -2173,8 +2177,8 @@ public DBCursor prepare(DBCursor cursor) {
2173
2177
if (query .getLimit () > 0 ) {
2174
2178
cursorToUse = cursorToUse .limit (query .getLimit ());
2175
2179
}
2176
- if (query .getSort () != null ) {
2177
- cursorToUse = cursorToUse .sort (sortConverter . convert (query . getSort () ));
2180
+ if (query .getSortObject () != null ) {
2181
+ cursorToUse = cursorToUse .sort (getMappedSortObject (query , entity ));
2178
2182
}
2179
2183
if (StringUtils .hasText (query .getHint ())) {
2180
2184
cursorToUse = cursorToUse .hint (query .getHint ());
0 commit comments