46
46
import org .springframework .util .Assert ;
47
47
48
48
import java .util .*;
49
- import java .util .stream .Collectors ;
50
49
51
50
/**
52
51
* Creates a full AQL query from a PartTree and ArangoParameterAccessor
@@ -89,7 +88,7 @@ public DerivedQueryCreator(
89
88
super (tree , accessor );
90
89
this .context = context ;
91
90
this .domainClass = domainClass ;
92
- collectionName = AqlUtils .buildCollectionName (context .getPersistentEntity (domainClass ).getCollection ());
91
+ collectionName = AqlUtils .buildCollectionName (context .getRequiredPersistentEntity (domainClass ).getCollection ());
93
92
this .tree = tree ;
94
93
this .accessor = accessor ;
95
94
this .geoFields = geoFields ;
@@ -127,7 +126,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
127
126
}
128
127
final StringBuilder query = new StringBuilder ();
129
128
130
- final String with = withCollections . stream (). collect ( Collectors . joining ( ", " ) );
129
+ final String with = String . join ( ", " , withCollections );
131
130
if (!with .isEmpty ()) {
132
131
query .append ("WITH " ).append (with ).append (" " );
133
132
}
@@ -160,7 +159,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
160
159
if (sort .isUnsorted ()) {
161
160
sortString = distanceSortKey ;
162
161
} else {
163
- sortString = distanceSortKey + ", " + sortString .substring (5 , sortString . length () );
162
+ sortString = distanceSortKey + ", " + sortString .substring (5 );
164
163
}
165
164
}
166
165
query .append (sortString );
@@ -170,7 +169,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
170
169
}
171
170
172
171
final Pageable pageable = accessor .getPageable ();
173
- if (pageable != null && pageable .isPaged ()) {
172
+ if (pageable .isPaged ()) {
174
173
query .append (" " ).append (AqlUtils .buildLimitClause (pageable ));
175
174
}
176
175
if (tree .isDelete ()) {
@@ -261,7 +260,7 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
261
260
--propertiesLeft ;
262
261
final ArangoPersistentProperty property = (ArangoPersistentProperty ) object ;
263
262
if (propertiesLeft == 0 ) {
264
- simpleProperties .append ("." + AqlUtils .buildFieldName (property .getFieldName ()));
263
+ simpleProperties .append ("." ). append ( AqlUtils .buildFieldName (property .getFieldName ()));
265
264
break ;
266
265
}
267
266
if (property .getRelations ().isPresent ()) {
@@ -274,34 +273,34 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
274
273
final Class <?>[] edgeClasses = relations .edges ();
275
274
final StringBuilder edgesBuilder = new StringBuilder ();
276
275
for (final Class <?> edge : edgeClasses ) {
277
- String collection = context .getPersistentEntity (edge ).getCollection ();
276
+ String collection = context .getRequiredPersistentEntity (edge ).getCollection ();
278
277
if (collection .split ("-" ).length > 1 ) {
279
278
collection = "`" + collection + "`" ;
280
279
}
281
- edgesBuilder .append (( edgesBuilder .length () == 0 ? "" : ", " ) + collection );
280
+ edgesBuilder .append (edgesBuilder .isEmpty () ? "" : ", " ). append ( collection );
282
281
}
283
282
final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer .toString (varsUsed ));
284
283
final String entity = "e" + Integer .toString (++varsUsed );
285
284
final String edges = edgesBuilder .toString ();
286
285
simpleProperties = new StringBuilder ();
287
286
final String iteration = format (TEMPLATE , entity , depths , direction , prevEntity , nested , edges );
288
287
final String predicate = format (PREDICATE_TEMPLATE , iteration );
289
- predicateTemplate = predicateTemplate .length () == 0 ? predicate : format (predicateTemplate , predicate );
288
+ predicateTemplate = predicateTemplate .isEmpty () ? predicate : format (predicateTemplate , predicate );
290
289
} else if (property .isCollectionLike ()) {
291
290
if (property .getRef ().isPresent ()) {
292
291
// collection of references
293
292
final String TEMPLATE = "FOR %s IN %s FILTER %s._id IN %s%s" ;
294
293
final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer .toString (varsUsed ));
295
294
final String entity = "e" + Integer .toString (++varsUsed );
296
- String collection = context .getPersistentEntity (property . getComponentType () ).getCollection ();
295
+ String collection = context .getRequiredPersistentEntity (property ).getCollection ();
297
296
if (collection .split ("-" ).length > 1 ) {
298
297
collection = "`" + collection + "`" ;
299
298
}
300
- final String name = simpleProperties . toString () + "." + AqlUtils .buildFieldName (property .getFieldName ());
299
+ final String name = simpleProperties + "." + AqlUtils .buildFieldName (property .getFieldName ());
301
300
simpleProperties = new StringBuilder ();
302
301
final String iteration = format (TEMPLATE , entity , collection , entity , prevEntity , name );
303
302
final String predicate = format (PREDICATE_TEMPLATE , iteration );
304
- predicateTemplate = predicateTemplate .length () == 0 ? predicate
303
+ predicateTemplate = predicateTemplate .isEmpty () ? predicate
305
304
: format (predicateTemplate , predicate );
306
305
} else {
307
306
// collection
@@ -312,28 +311,28 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
312
311
simpleProperties = new StringBuilder ();
313
312
final String iteration = format (TEMPLATE , entity , prevEntity , name );
314
313
final String predicate = format (PREDICATE_TEMPLATE , iteration );
315
- predicateTemplate = predicateTemplate .length () == 0 ? predicate
314
+ predicateTemplate = predicateTemplate .isEmpty () ? predicate
316
315
: format (predicateTemplate , predicate );
317
316
}
318
317
} else {
319
318
if (property .getRef ().isPresent () || property .getFrom ().isPresent () || property .getTo ().isPresent ()) {
320
319
// single reference
321
320
final String TEMPLATE = "FOR %s IN %s FILTER %s._id == %s%s" ;
322
321
final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer .toString (varsUsed ));
323
- final String entity = "e" + Integer . toString ( ++varsUsed ) ;
324
- String collection = context .getPersistentEntity (property . getType () ).getCollection ();
322
+ final String entity = "e" + ++varsUsed ;
323
+ String collection = context .getRequiredPersistentEntity (property ).getCollection ();
325
324
if (collection .split ("-" ).length > 1 ) {
326
325
collection = "`" + collection + "`" ;
327
326
}
328
- final String name = simpleProperties . toString () + "." + AqlUtils .buildFieldName (property .getFieldName ());
327
+ final String name = simpleProperties + "." + AqlUtils .buildFieldName (property .getFieldName ());
329
328
simpleProperties = new StringBuilder ();
330
329
final String iteration = format (TEMPLATE , entity , collection , entity , prevEntity , name );
331
330
final String predicate = format (PREDICATE_TEMPLATE , iteration );
332
- predicateTemplate = predicateTemplate .length () == 0 ? predicate
331
+ predicateTemplate = predicateTemplate .isEmpty () ? predicate
333
332
: format (predicateTemplate , predicate );
334
333
} else {
335
334
// simple property
336
- simpleProperties .append ("." + AqlUtils .buildFieldName (property .getFieldName ()));
335
+ simpleProperties .append ("." ). append ( AqlUtils .buildFieldName (property .getFieldName ()));
337
336
}
338
337
}
339
338
}
@@ -385,7 +384,7 @@ private void checkUniquePoint(final Point point) {
385
384
* @param part
386
385
*/
387
386
private void checkUniqueLocation (final Part part ) {
388
- isUnique = isUnique == null ? true : isUnique ;
387
+ isUnique = isUnique == null || isUnique ;
389
388
isUnique = (uniqueLocation == null || uniqueLocation .equals (ignorePropertyCase (part ))) ? isUnique : false ;
390
389
if (!geoFields .isEmpty ()) {
391
390
Assert .isTrue (isUnique , "Different location fields are used - Distance is ambiguous" );
@@ -398,8 +397,7 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
398
397
final String [] templateAndProperty = createPredicateTemplateAndPropertyString (part );
399
398
final String template = templateAndProperty [0 ];
400
399
final String property = templateAndProperty [1 ];
401
- Criteria criteria = null ;
402
- final boolean checkUnique = part .getProperty ().toDotPath ().split ("." ).length <= 1 ;
400
+ final boolean checkUnique = part .getProperty ().toDotPath ().split ("\\ ." ).length <= 1 ;
403
401
Class <?> type = part .getProperty ().getType ();
404
402
405
403
// whether the current field type is a type encoded as geoJson
@@ -410,6 +408,7 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
410
408
hasGeoJsonType = true ;
411
409
}
412
410
411
+ Criteria criteria = null ;
413
412
switch (part .getType ()) {
414
413
case SIMPLE_PROPERTY :
415
414
criteria = Criteria .eql (ignorePropertyCase (part , property ), bind (part , iterator ));
@@ -431,7 +430,7 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
431
430
break ;
432
431
case EXISTS :
433
432
final String document = property .substring (0 , property .lastIndexOf ("." ));
434
- final String attribute = property .substring (property .lastIndexOf ("." ) + 1 , property . length () );
433
+ final String attribute = property .substring (property .lastIndexOf ("." ) + 1 );
435
434
criteria = Criteria .exists (document , attribute );
436
435
break ;
437
436
case BEFORE :
@@ -492,10 +491,9 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
492
491
if (nearValue instanceof Point point ) {
493
492
checkUniquePoint (point );
494
493
} else {
495
- bindingCounter = binding .bind (nearValue , shouldIgnoreCase (part ), null , point -> checkUniquePoint ( point ) ,
494
+ bindingCounter = binding .bind (nearValue , shouldIgnoreCase (part ), null , this :: checkUniquePoint ,
496
495
bindingCounter );
497
496
}
498
- criteria = null ;
499
497
break ;
500
498
case WITHIN :
501
499
if (checkUnique ) {
@@ -588,24 +586,24 @@ private int bind(final Part part, final Iterator<Object> iterator, final Boolean
588
586
589
587
private int bind (final Part part , final Object value , final Boolean borderStatus ) {
590
588
final int index = bindingCounter ;
591
- bindingCounter = binding .bind (value , shouldIgnoreCase (part ), borderStatus , point -> checkUniquePoint ( point ) ,
589
+ bindingCounter = binding .bind (value , shouldIgnoreCase (part ), borderStatus , this :: checkUniquePoint ,
592
590
bindingCounter );
593
591
return index ;
594
592
}
595
593
596
594
private int bind (final Object value ) {
597
595
final int index = bindingCounter ;
598
- bindingCounter = binding .bind (value , false , null , point -> checkUniquePoint ( point ) , bindingCounter );
596
+ bindingCounter = binding .bind (value , false , null , this :: checkUniquePoint , bindingCounter );
599
597
return index ;
600
598
}
601
599
602
600
private void bindPoint (final Part part , final Object value , final boolean toGeoJson ) {
603
- bindingCounter = binding .bindPoint (value , shouldIgnoreCase (part ), point -> checkUniquePoint ( point ) ,
601
+ bindingCounter = binding .bindPoint (value , shouldIgnoreCase (part ), this :: checkUniquePoint ,
604
602
bindingCounter , toGeoJson );
605
603
}
606
604
607
605
private void bindCircle (final Part part , final Object value , final boolean toGeoJson ) {
608
- bindingCounter = binding .bindCircle (value , shouldIgnoreCase (part ), point -> checkUniquePoint ( point ) ,
606
+ bindingCounter = binding .bindCircle (value , shouldIgnoreCase (part ), this :: checkUniquePoint ,
609
607
bindingCounter , toGeoJson );
610
608
}
611
609
@@ -614,7 +612,7 @@ private void bindRange(final Part part, final Object value) {
614
612
}
615
613
616
614
private void bindRing (final Part part , final Object value , final boolean toGeoJson ) {
617
- bindingCounter = binding .bindRing (value , shouldIgnoreCase (part ), point -> checkUniquePoint ( point ) ,
615
+ bindingCounter = binding .bindRing (value , shouldIgnoreCase (part ), this :: checkUniquePoint ,
618
616
bindingCounter , toGeoJson );
619
617
}
620
618
@@ -632,7 +630,6 @@ private void collectWithCollections(final PropertyPath propertyPath) {
632
630
propertyPath .stream ()
633
631
.filter (property -> {
634
632
ArangoPersistentProperty p = context .getPersistentPropertyPath (property ).getBaseProperty ();
635
- if (p == null ) return false ;
636
633
Optional <Ref > ref = p .getRef ();
637
634
Optional <Relations > rels = p .getRelations ();
638
635
return ref .isPresent () || rels .isPresent ();
0 commit comments