15
15
*/
16
16
package io .graphqlcrud ;
17
17
18
+ import java .math .BigDecimal ;
19
+ import java .math .BigInteger ;
18
20
import java .util .*;
19
21
import java .util .concurrent .atomic .AtomicInteger ;
20
22
@@ -269,82 +271,161 @@ public void visitArgument(Field field, GraphQLFieldDefinition definition, GraphQ
269
271
}
270
272
}
271
273
272
- public Condition visitStringValue (Value v , org .jooq .Field left , String conditionName ) {
274
+ public Condition visitStringValue (String value , org .jooq .Field left , String conditionName ) {
273
275
Condition c = null ;
274
- if (conditionName .equals ("eq" ))
275
- c = left .eq (((StringValue )v ).getValue ());
276
- else if (conditionName .equals ("ne" ))
277
- c = left .ne (((StringValue ) v ).getValue ());
278
- else if (conditionName .equals ("lt" ))
279
- c = left .lt (((StringValue ) v ).getValue ());
280
- else if (conditionName .equals ("le" ))
281
- c = left .le (((StringValue ) v ).getValue ());
282
- else if (conditionName .equals ("gt" ))
283
- c = left .gt (((StringValue ) v ).getValue ());
284
- else if (conditionName .equals ("ge" ))
285
- c = left .in (((StringValue ) v ).getValue ());
286
- else if (conditionName .equals ("contains" ))
287
- c = left .contains (((StringValue ) v ).getValue ());
288
- else if (conditionName .equals ("startsWith" ))
289
- c = left .startsWith (((StringValue ) v ).getValue ());
290
- else if (conditionName .equals ("endsWith" ))
291
- c = left .endsWith (((StringValue ) v ).getValue ());
276
+ switch (conditionName ) {
277
+ case "eq" :
278
+ c = left .eq (value );
279
+ break ;
280
+ case "ne" :
281
+ c = left .ne (value );
282
+ break ;
283
+ case "lt" :
284
+ c = left .lt (value );
285
+ break ;
286
+ case "le" :
287
+ c = left .le (value );
288
+ break ;
289
+ case "gt" :
290
+ c = left .gt (value );
291
+ break ;
292
+ case "ge" :
293
+ c = left .in (value );
294
+ break ;
295
+ case "contains" :
296
+ c = left .contains (value );
297
+ break ;
298
+ case "startsWith" :
299
+ c = left .startsWith (value );
300
+ break ;
301
+ case "endsWith" :
302
+ c = left .endsWith (value );
303
+ break ;
304
+ default :
305
+ throw new RuntimeException ("Unexpected value: " + conditionName );
306
+ }
292
307
return c ;
293
308
}
294
309
295
- public Condition visitBooleanValue (Value v , org .jooq .Field left , String conditionName ) {
310
+ public Condition visitBooleanValue (Boolean value , org .jooq .Field left , String conditionName ) {
296
311
Condition c = null ;
297
- if (conditionName .equals ("eq" ))
298
- c = left .eq (((BooleanValue )v ).isValue ());
299
- else if (conditionName .equals ("ne" ))
300
- c = left .ne (((BooleanValue ) v ).isValue ());
312
+ switch (conditionName ) {
313
+ case "eq" :
314
+ c = left .eq (value );
315
+ break ;
316
+ case "ne" :
317
+ c = left .ne (value );
318
+ break ;
319
+ default :
320
+ throw new RuntimeException ("Unexpected value: " + conditionName );
321
+ }
301
322
return c ;
302
323
}
303
324
304
- public Condition visitIntValue (Value v , org .jooq .Field left , String conditionName ) {
325
+ public Condition visitIntValue (BigInteger value , org .jooq .Field left , String conditionName ) {
305
326
Condition c = null ;
306
- if (conditionName .equals ("eq" ))
307
- c = left .eq (((IntValue )v ).getValue ());
308
- else if (conditionName .equals ("ne" ))
309
- c = left .ne (((IntValue ) v ).getValue ());
310
- else if (conditionName .equals ("lt" ))
311
- c = left .lt (((IntValue ) v ).getValue ());
312
- else if (conditionName .equals ("le" ))
313
- c = left .le (((IntValue ) v ).getValue ());
314
- else if (conditionName .equals ("gt" ))
315
- c = left .gt (((IntValue ) v ).getValue ());
316
- else if (conditionName .equals ("ge" ))
317
- c = left .ge (((IntValue ) v ).getValue ());
327
+ switch (conditionName ) {
328
+ case "eq" :
329
+ c = left .eq (value );
330
+ break ;
331
+ case "ne" :
332
+ c = left .ne (value );
333
+ break ;
334
+ case "lt" :
335
+ c = left .lt (value );
336
+ break ;
337
+ case "le" :
338
+ c = left .le (value );
339
+ break ;
340
+ case "gt" :
341
+ c = left .gt (value );
342
+ break ;
343
+ case "ge" :
344
+ c = left .ge (value );
345
+ break ;
346
+ default :
347
+ throw new RuntimeException ("Unexpected value: " + conditionName );
348
+ }
318
349
return c ;
319
350
}
320
351
321
- public Condition visitFloatValue (Value v , org .jooq .Field left , String conditionName ) {
352
+ public Condition visitFloatValue (BigDecimal value , org .jooq .Field left , String conditionName ) {
322
353
Condition c = null ;
323
- if (conditionName .equals ("eq" ))
324
- c = left .eq (((FloatValue )v ).getValue ());
325
- else if (conditionName .equals ("ne" ))
326
- c = left .ne (((FloatValue ) v ).getValue ());
327
- else if (conditionName .equals ("lt" ))
328
- c = left .lt (((FloatValue ) v ).getValue ());
329
- else if (conditionName .equals ("le" ))
330
- c = left .le (((FloatValue ) v ).getValue ());
331
- else if (conditionName .equals ("gt" ))
332
- c = left .gt (((FloatValue ) v ).getValue ());
333
- else if (conditionName .equals ("ge" ))
334
- c = left .ge (((FloatValue ) v ).getValue ());
354
+ switch (conditionName ) {
355
+ case "eq" :
356
+ c = left .eq (value );
357
+ break ;
358
+ case "ne" :
359
+ c = left .ne (value );
360
+ break ;
361
+ case "lt" :
362
+ c = left .lt (value );
363
+ break ;
364
+ case "le" :
365
+ c = left .le (value );
366
+ break ;
367
+ case "gt" :
368
+ c = left .gt (value );
369
+ break ;
370
+ case "ge" :
371
+ c = left .ge (value );
372
+ break ;
373
+ default :
374
+ throw new RuntimeException ("Unexpected value: " + conditionName );
375
+ }
376
+ return c ;
377
+ }
378
+
379
+
380
+ public Condition visitArrayValue (List <Value > v , org .jooq .Field left , String conditionName ) {
381
+ Condition c = null ;
382
+ switch (conditionName ) {
383
+ case "between" :
384
+ if (v .get (0 ) instanceof FloatValue ) {
385
+ c = left .between (((FloatValue ) v .get (0 )).getValue (), ((FloatValue ) v .get (1 )).getValue ());
386
+ } else if (v .get (0 ) instanceof IntValue ) {
387
+ c = left .between (((IntValue ) v .get (0 )).getValue (), ((IntValue ) v .get (1 )).getValue ());
388
+ }
389
+ break ;
390
+ case "in" :
391
+ if (v .get (0 ) instanceof StringValue ) {
392
+ List <String > list = new ArrayList <>();
393
+ for (Value value : v ) {
394
+ list .add (((StringValue ) value ).getValue ());
395
+ }
396
+ c = left .in (list );
397
+ } else if (v .get (0 ) instanceof FloatValue ) {
398
+ List <BigDecimal > list = new ArrayList <>();
399
+ for (Value value : v ) {
400
+ list .add (((FloatValue ) value ).getValue ());
401
+ }
402
+ c = left .in (list );
403
+ } else if (v .get (0 ) instanceof IntValue ) {
404
+ List <BigInteger > list = new ArrayList <>();
405
+ for (Value value : v ) {
406
+ list .add (((IntValue ) value ).getValue ());
407
+ }
408
+ c = left .in (list );
409
+ }
410
+ break ;
411
+ default :
412
+ throw new RuntimeException ("Unexpected value: " + conditionName );
413
+ }
335
414
return c ;
336
415
}
337
416
338
417
public Condition visitValueType (Value v , org .jooq .Field left , String conditionName ) {
339
418
Condition c = null ;
340
419
if (v instanceof StringValue ) {
341
- c = visitStringValue (v ,left ,conditionName );
420
+ c = visitStringValue ((( StringValue ) v ). getValue () ,left ,conditionName );
342
421
} else if (v instanceof BooleanValue ) {
343
- c = visitBooleanValue (v ,left ,conditionName );
422
+ c = visitBooleanValue ((( BooleanValue ) v ). isValue () ,left ,conditionName );
344
423
} else if (v instanceof IntValue ) {
345
- c = visitIntValue (v ,left ,conditionName );
424
+ c = visitIntValue ((( IntValue ) v ). getValue () ,left ,conditionName );
346
425
} else if (v instanceof FloatValue ) {
347
- c = visitFloatValue (v ,left ,conditionName );
426
+ c = visitFloatValue (((FloatValue ) v ).getValue (),left ,conditionName );
427
+ } else if (v instanceof ArrayValue ) {
428
+ c = visitArrayValue (((ArrayValue ) v ).getValues (),left ,conditionName );
348
429
}
349
430
return c ;
350
431
}
@@ -362,12 +443,15 @@ public void visitFilterInputs(Value argumentValue, VistorContext vistorContext,
362
443
left = field (name (vistorContext .alias , field .getName ()));
363
444
org .jooq .Field <Object > finalLeft = left ;
364
445
String finalConditionName = conditionName ;
365
- field .getValue ().getChildren ().forEach (child -> {
366
- Condition condition = visitValueType (((ObjectField ) child ).getValue (), finalLeft , ((ObjectField ) child ).getName ());
367
- visitCondition (finalConditionName , condition );
368
- });
446
+ for (Object object : field .getValue ().getChildren ()) {
447
+ if (object instanceof ObjectField ) {
448
+ Condition condition = visitValueType (((ObjectField ) object ).getValue (), finalLeft , ((ObjectField ) object ).getName ());
449
+ visitCondition (finalConditionName , condition );
450
+ }
451
+ }
369
452
}
370
- visitFilterInputs (field .getValue (), vistorContext , conditionName );
453
+ if (field .getValue () instanceof ObjectValue )
454
+ visitFilterInputs (field .getValue (), vistorContext , conditionName );
371
455
}
372
456
}
373
457
}
@@ -378,7 +462,9 @@ public void visitCondition(String conditionName, Condition conditionValue) {
378
462
vistorContext .condition = conditionValue ;
379
463
}
380
464
else {
381
- if (conditionName .equals ("and" )) {
465
+ if (conditionName == null ) {
466
+ vistorContext .condition = vistorContext .condition .and (conditionValue );
467
+ } else if (conditionName .equals ("and" )) {
382
468
vistorContext .condition = vistorContext .condition .and (conditionValue );
383
469
} else if (conditionName .equals ("or" )) {
384
470
vistorContext .condition = vistorContext .condition .or (conditionValue );
0 commit comments