4646import org .springframework .util .Assert ;
4747
4848import java .util .*;
49- import java .util .stream .Collectors ;
5049
5150/**
5251 * Creates a full AQL query from a PartTree and ArangoParameterAccessor
@@ -89,7 +88,7 @@ public DerivedQueryCreator(
8988 super (tree , accessor );
9089 this .context = context ;
9190 this .domainClass = domainClass ;
92- collectionName = AqlUtils .buildCollectionName (context .getPersistentEntity (domainClass ).getCollection ());
91+ collectionName = AqlUtils .buildCollectionName (context .getRequiredPersistentEntity (domainClass ).getCollection ());
9392 this .tree = tree ;
9493 this .accessor = accessor ;
9594 this .geoFields = geoFields ;
@@ -127,7 +126,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
127126 }
128127 final StringBuilder query = new StringBuilder ();
129128
130- final String with = withCollections . stream (). collect ( Collectors . joining ( ", " ) );
129+ final String with = String . join ( ", " , withCollections );
131130 if (!with .isEmpty ()) {
132131 query .append ("WITH " ).append (with ).append (" " );
133132 }
@@ -160,7 +159,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
160159 if (sort .isUnsorted ()) {
161160 sortString = distanceSortKey ;
162161 } else {
163- sortString = distanceSortKey + ", " + sortString .substring (5 , sortString . length () );
162+ sortString = distanceSortKey + ", " + sortString .substring (5 );
164163 }
165164 }
166165 query .append (sortString );
@@ -170,7 +169,7 @@ protected QueryWithCollections complete(final Criteria criteria, final Sort sort
170169 }
171170
172171 final Pageable pageable = accessor .getPageable ();
173- if (pageable != null && pageable .isPaged ()) {
172+ if (pageable .isPaged ()) {
174173 query .append (" " ).append (AqlUtils .buildLimitClause (pageable ));
175174 }
176175 if (tree .isDelete ()) {
@@ -261,7 +260,7 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
261260 --propertiesLeft ;
262261 final ArangoPersistentProperty property = (ArangoPersistentProperty ) object ;
263262 if (propertiesLeft == 0 ) {
264- simpleProperties .append ("." + AqlUtils .buildFieldName (property .getFieldName ()));
263+ simpleProperties .append ("." ). append ( AqlUtils .buildFieldName (property .getFieldName ()));
265264 break ;
266265 }
267266 if (property .getRelations ().isPresent ()) {
@@ -274,34 +273,34 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
274273 final Class <?>[] edgeClasses = relations .edges ();
275274 final StringBuilder edgesBuilder = new StringBuilder ();
276275 for (final Class <?> edge : edgeClasses ) {
277- String collection = context .getPersistentEntity (edge ).getCollection ();
276+ String collection = context .getRequiredPersistentEntity (edge ).getCollection ();
278277 if (collection .split ("-" ).length > 1 ) {
279278 collection = "`" + collection + "`" ;
280279 }
281- edgesBuilder .append (( edgesBuilder .length () == 0 ? "" : ", " ) + collection );
280+ edgesBuilder .append (edgesBuilder .isEmpty () ? "" : ", " ). append ( collection );
282281 }
283282 final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer .toString (varsUsed ));
284283 final String entity = "e" + Integer .toString (++varsUsed );
285284 final String edges = edgesBuilder .toString ();
286285 simpleProperties = new StringBuilder ();
287286 final String iteration = format (TEMPLATE , entity , depths , direction , prevEntity , nested , edges );
288287 final String predicate = format (PREDICATE_TEMPLATE , iteration );
289- predicateTemplate = predicateTemplate .length () == 0 ? predicate : format (predicateTemplate , predicate );
288+ predicateTemplate = predicateTemplate .isEmpty () ? predicate : format (predicateTemplate , predicate );
290289 } else if (property .isCollectionLike ()) {
291290 if (property .getRef ().isPresent ()) {
292291 // collection of references
293292 final String TEMPLATE = "FOR %s IN %s FILTER %s._id IN %s%s" ;
294293 final String prevEntity = "e" + (varsUsed == 0 ? "" : Integer .toString (varsUsed ));
295294 final String entity = "e" + Integer .toString (++varsUsed );
296- String collection = context .getPersistentEntity (property . getComponentType () ).getCollection ();
295+ String collection = context .getRequiredPersistentEntity (property ).getCollection ();
297296 if (collection .split ("-" ).length > 1 ) {
298297 collection = "`" + collection + "`" ;
299298 }
300- final String name = simpleProperties . toString () + "." + AqlUtils .buildFieldName (property .getFieldName ());
299+ final String name = simpleProperties + "." + AqlUtils .buildFieldName (property .getFieldName ());
301300 simpleProperties = new StringBuilder ();
302301 final String iteration = format (TEMPLATE , entity , collection , entity , prevEntity , name );
303302 final String predicate = format (PREDICATE_TEMPLATE , iteration );
304- predicateTemplate = predicateTemplate .length () == 0 ? predicate
303+ predicateTemplate = predicateTemplate .isEmpty () ? predicate
305304 : format (predicateTemplate , predicate );
306305 } else {
307306 // collection
@@ -312,28 +311,28 @@ private String[] createPredicateTemplateAndPropertyString(final Part part) {
312311 simpleProperties = new StringBuilder ();
313312 final String iteration = format (TEMPLATE , entity , prevEntity , name );
314313 final String predicate = format (PREDICATE_TEMPLATE , iteration );
315- predicateTemplate = predicateTemplate .length () == 0 ? predicate
314+ predicateTemplate = predicateTemplate .isEmpty () ? predicate
316315 : format (predicateTemplate , predicate );
317316 }
318317 } else {
319318 if (property .getRef ().isPresent () || property .getFrom ().isPresent () || property .getTo ().isPresent ()) {
320319 // single reference
321320 final String TEMPLATE = "FOR %s IN %s FILTER %s._id == %s%s" ;
322321 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 ();
325324 if (collection .split ("-" ).length > 1 ) {
326325 collection = "`" + collection + "`" ;
327326 }
328- final String name = simpleProperties . toString () + "." + AqlUtils .buildFieldName (property .getFieldName ());
327+ final String name = simpleProperties + "." + AqlUtils .buildFieldName (property .getFieldName ());
329328 simpleProperties = new StringBuilder ();
330329 final String iteration = format (TEMPLATE , entity , collection , entity , prevEntity , name );
331330 final String predicate = format (PREDICATE_TEMPLATE , iteration );
332- predicateTemplate = predicateTemplate .length () == 0 ? predicate
331+ predicateTemplate = predicateTemplate .isEmpty () ? predicate
333332 : format (predicateTemplate , predicate );
334333 } else {
335334 // simple property
336- simpleProperties .append ("." + AqlUtils .buildFieldName (property .getFieldName ()));
335+ simpleProperties .append ("." ). append ( AqlUtils .buildFieldName (property .getFieldName ()));
337336 }
338337 }
339338 }
@@ -385,7 +384,7 @@ private void checkUniquePoint(final Point point) {
385384 * @param part
386385 */
387386 private void checkUniqueLocation (final Part part ) {
388- isUnique = isUnique == null ? true : isUnique ;
387+ isUnique = isUnique == null || isUnique ;
389388 isUnique = (uniqueLocation == null || uniqueLocation .equals (ignorePropertyCase (part ))) ? isUnique : false ;
390389 if (!geoFields .isEmpty ()) {
391390 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
398397 final String [] templateAndProperty = createPredicateTemplateAndPropertyString (part );
399398 final String template = templateAndProperty [0 ];
400399 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 ;
403401 Class <?> type = part .getProperty ().getType ();
404402
405403 // 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
410408 hasGeoJsonType = true ;
411409 }
412410
411+ Criteria criteria = null ;
413412 switch (part .getType ()) {
414413 case SIMPLE_PROPERTY :
415414 criteria = Criteria .eql (ignorePropertyCase (part , property ), bind (part , iterator ));
@@ -431,7 +430,7 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
431430 break ;
432431 case EXISTS :
433432 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 );
435434 criteria = Criteria .exists (document , attribute );
436435 break ;
437436 case BEFORE :
@@ -492,10 +491,9 @@ private Criteria createCriteria(final Part part, final Iterator<Object> iterator
492491 if (nearValue instanceof Point point ) {
493492 checkUniquePoint (point );
494493 } else {
495- bindingCounter = binding .bind (nearValue , shouldIgnoreCase (part ), null , point -> checkUniquePoint ( point ) ,
494+ bindingCounter = binding .bind (nearValue , shouldIgnoreCase (part ), null , this :: checkUniquePoint ,
496495 bindingCounter );
497496 }
498- criteria = null ;
499497 break ;
500498 case WITHIN :
501499 if (checkUnique ) {
@@ -588,24 +586,24 @@ private int bind(final Part part, final Iterator<Object> iterator, final Boolean
588586
589587 private int bind (final Part part , final Object value , final Boolean borderStatus ) {
590588 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 ,
592590 bindingCounter );
593591 return index ;
594592 }
595593
596594 private int bind (final Object value ) {
597595 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 );
599597 return index ;
600598 }
601599
602600 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 ,
604602 bindingCounter , toGeoJson );
605603 }
606604
607605 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 ,
609607 bindingCounter , toGeoJson );
610608 }
611609
@@ -614,7 +612,7 @@ private void bindRange(final Part part, final Object value) {
614612 }
615613
616614 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 ,
618616 bindingCounter , toGeoJson );
619617 }
620618
@@ -632,7 +630,6 @@ private void collectWithCollections(final PropertyPath propertyPath) {
632630 propertyPath .stream ()
633631 .filter (property -> {
634632 ArangoPersistentProperty p = context .getPersistentPropertyPath (property ).getBaseProperty ();
635- if (p == null ) return false ;
636633 Optional <Ref > ref = p .getRef ();
637634 Optional <Relations > rels = p .getRelations ();
638635 return ref .isPresent () || rels .isPresent ();
0 commit comments