29
29
import org .springframework .data .repository .query .parser .AbstractQueryCreator ;
30
30
import org .springframework .data .repository .query .parser .Part ;
31
31
import org .springframework .data .repository .query .parser .PartTree ;
32
+ import org .springframework .lang .Nullable ;
32
33
import org .springframework .util .CollectionUtils ;
33
34
34
35
/**
37
38
* @author Christoph Strobl
38
39
* @author Mark Paluch
39
40
* @author John Blum
41
+ * @author Junghoon Ban
40
42
* @since 1.7
41
43
*/
42
44
public class RedisQueryCreator extends AbstractQueryCreator <KeyValueQuery <RedisOperationChain >, RedisOperationChain > {
@@ -78,16 +80,16 @@ protected RedisOperationChain or(RedisOperationChain base, RedisOperationChain c
78
80
}
79
81
80
82
@ Override
81
- protected KeyValueQuery <RedisOperationChain > complete (final RedisOperationChain criteria , Sort sort ) {
83
+ protected KeyValueQuery <RedisOperationChain > complete (@ Nullable final RedisOperationChain criteria , Sort sort ) {
82
84
83
85
KeyValueQuery <RedisOperationChain > query = new KeyValueQuery <>(criteria );
84
86
85
- if (query . getCriteria () != null && !CollectionUtils .isEmpty (query . getCriteria () .getSismember ())
86
- && !CollectionUtils .isEmpty (query . getCriteria () .getOrSismember ()))
87
- if (query . getCriteria (). getSismember ().size () == 1 && query . getCriteria () .getOrSismember ().size () == 1 ) {
87
+ if (criteria != null && !CollectionUtils .isEmpty (criteria .getSismember ())
88
+ && !CollectionUtils .isEmpty (criteria .getOrSismember ()))
89
+ if (criteria . getSismember ().size () == 1 && criteria .getOrSismember ().size () == 1 ) {
88
90
89
- query . getCriteria (). getOrSismember ().add (query . getCriteria () .getSismember ().iterator ().next ());
90
- query . getCriteria () .getSismember ().clear ();
91
+ criteria . getOrSismember ().add (criteria .getSismember ().iterator ().next ());
92
+ criteria .getSismember ().clear ();
91
93
}
92
94
93
95
if (sort .isSorted ()) {
@@ -99,43 +101,39 @@ protected KeyValueQuery<RedisOperationChain> complete(final RedisOperationChain
99
101
100
102
private NearPath getNearPath (Part part , Iterator <Object > iterator ) {
101
103
104
+ String path = part .getProperty ().toDotPath ();
102
105
Object value = iterator .next ();
103
106
104
- Point point ;
105
- Distance distance ;
106
-
107
- if (value instanceof Circle ) {
108
- point = ((Circle ) value ).getCenter ();
109
- distance = ((Circle ) value ).getRadius ();
110
- } else if (value instanceof Point ) {
107
+ if (value instanceof Circle circle ) {
108
+ return new NearPath (path , circle .getCenter (), circle .getRadius ());
109
+ }
111
110
112
- point = ( Point ) value ;
111
+ if ( value instanceof Point point ) {
113
112
114
113
if (!iterator .hasNext ()) {
115
114
String message = "Expected to find distance value for geo query; Are you missing a parameter" ;
116
115
throw new InvalidDataAccessApiUsageException (message );
117
116
}
118
117
118
+ Distance distance ;
119
119
Object distObject = iterator .next ();
120
- if (distObject instanceof Distance ) {
121
- distance = (Distance ) distObject ;
122
- } else if (distObject instanceof Number ) {
123
- distance = new Distance (((Number ) distObject ).doubleValue (), Metrics .KILOMETERS );
120
+
121
+ if (distObject instanceof Distance distanceValue ) {
122
+ distance = distanceValue ;
123
+ } else if (distObject instanceof Number numberValue ) {
124
+ distance = new Distance (numberValue .doubleValue (), Metrics .KILOMETERS );
124
125
} else {
125
126
126
127
String message = String .format ("Expected to find Distance or Numeric value for geo query but was %s" ,
127
128
distObject .getClass ());
128
-
129
129
throw new InvalidDataAccessApiUsageException (message );
130
130
}
131
- } else {
132
-
133
- String message = String .format ("Expected to find a Circle or Point/Distance for geo query but was %s." ,
134
- value .getClass ());
135
131
136
- throw new InvalidDataAccessApiUsageException ( message );
132
+ return new NearPath ( path , point , distance );
137
133
}
138
134
139
- return new NearPath (part .getProperty ().toDotPath (), point , distance );
135
+ String message = String .format ("Expected to find a Circle or Point/Distance for geo query but was %s." ,
136
+ value .getClass ());
137
+ throw new InvalidDataAccessApiUsageException (message );
140
138
}
141
139
}
0 commit comments