@ -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" ) ;
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
* you may not use this file except in compliance with the License .
@ -15,6 +15,8 @@
* /
* /
package org.springframework.data.mongodb.core ;
package org.springframework.data.mongodb.core ;
import static org.springframework.data.domain.Sort.Direction.* ;
import java.util.ArrayList ;
import java.util.ArrayList ;
import java.util.List ;
import java.util.List ;
@ -22,7 +24,6 @@ import org.springframework.dao.DataAccessException;
import org.springframework.data.mongodb.core.index.IndexDefinition ;
import org.springframework.data.mongodb.core.index.IndexDefinition ;
import org.springframework.data.mongodb.core.index.IndexField ;
import org.springframework.data.mongodb.core.index.IndexField ;
import org.springframework.data.mongodb.core.index.IndexInfo ;
import org.springframework.data.mongodb.core.index.IndexInfo ;
import org.springframework.data.mongodb.core.query.Order ;
import org.springframework.util.Assert ;
import org.springframework.util.Assert ;
import com.mongodb.DBCollection ;
import com.mongodb.DBCollection ;
@ -34,9 +35,13 @@ import com.mongodb.MongoException;
*
*
* @author Mark Pollack
* @author Mark Pollack
* @author Oliver Gierke
* @author Oliver Gierke
* @author Komi Innocent
* /
* /
public class DefaultIndexOperations implements IndexOperations {
public class DefaultIndexOperations implements IndexOperations {
private static final Double ONE = Double . valueOf ( 1 ) ;
private static final Double MINUS_ONE = Double . valueOf ( - 1 ) ;
private final MongoOperations mongoOperations ;
private final MongoOperations mongoOperations ;
private final String collectionName ;
private final String collectionName ;
@ -135,12 +140,17 @@ public class DefaultIndexOperations implements IndexOperations {
Object value = keyDbObject . get ( key ) ;
Object value = keyDbObject . get ( key ) ;
if ( Integer . valueOf ( 1 ) . equals ( value ) ) {
if ( "2d" . equals ( value ) ) {
indexFields . add ( IndexField . create ( key , Order . ASCENDING ) ) ;
} else if ( Integer . valueOf ( - 1 ) . equals ( value ) ) {
indexFields . add ( IndexField . create ( key , Order . DESCENDING ) ) ;
} else if ( "2d" . equals ( value ) ) {
indexFields . add ( IndexField . geo ( key ) ) ;
indexFields . add ( IndexField . geo ( key ) ) ;
} else {
Double keyValue = new Double ( value . toString ( ) ) ;
if ( ONE . equals ( keyValue ) ) {
indexFields . add ( IndexField . create ( key , ASC ) ) ;
} else if ( MINUS_ONE . equals ( keyValue ) ) {
indexFields . add ( IndexField . create ( key , DESC ) ) ;
}
}
}
}
}