2929import org .springframework .data .repository .query .parser .AbstractQueryCreator ;
3030import org .springframework .data .repository .query .parser .Part ;
3131import org .springframework .data .repository .query .parser .PartTree ;
32+ import org .springframework .lang .Nullable ;
3233import org .springframework .util .CollectionUtils ;
3334
3435/**
3738 * @author Christoph Strobl
3839 * @author Mark Paluch
3940 * @author John Blum
41+ * @author Junghoon Ban
4042 * @since 1.7
4143 */
4244public class RedisQueryCreator extends AbstractQueryCreator <KeyValueQuery <RedisOperationChain >, RedisOperationChain > {
@@ -78,16 +80,16 @@ protected RedisOperationChain or(RedisOperationChain base, RedisOperationChain c
7880 }
7981
8082 @ Override
81- protected KeyValueQuery <RedisOperationChain > complete (final RedisOperationChain criteria , Sort sort ) {
83+ protected KeyValueQuery <RedisOperationChain > complete (@ Nullable final RedisOperationChain criteria , Sort sort ) {
8284
8385 KeyValueQuery <RedisOperationChain > query = new KeyValueQuery <>(criteria );
8486
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 ) {
8890
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 ();
9193 }
9294
9395 if (sort .isSorted ()) {
@@ -99,43 +101,39 @@ protected KeyValueQuery<RedisOperationChain> complete(final RedisOperationChain
99101
100102 private NearPath getNearPath (Part part , Iterator <Object > iterator ) {
101103
104+ String path = part .getProperty ().toDotPath ();
102105 Object value = iterator .next ();
103106
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+ }
111110
112- point = ( Point ) value ;
111+ if ( value instanceof Point point ) {
113112
114113 if (!iterator .hasNext ()) {
115114 String message = "Expected to find distance value for geo query; Are you missing a parameter" ;
116115 throw new InvalidDataAccessApiUsageException (message );
117116 }
118117
118+ Distance distance ;
119119 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 );
124125 } else {
125126
126127 String message = String .format ("Expected to find Distance or Numeric value for geo query but was %s" ,
127128 distObject .getClass ());
128-
129129 throw new InvalidDataAccessApiUsageException (message );
130130 }
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 ());
135131
136- throw new InvalidDataAccessApiUsageException ( message );
132+ return new NearPath ( path , point , distance );
137133 }
138134
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 );
140138 }
141139}
0 commit comments