33
33
import org .springframework .data .relational .core .query .CriteriaDefinition ;
34
34
import org .springframework .data .relational .core .query .Query ;
35
35
import org .springframework .data .relational .core .sql .*;
36
- import org .springframework .data .relational .core .sql .render .RenderContext ;
37
36
import org .springframework .data .relational .core .sql .render .SqlRenderer ;
38
37
import org .springframework .data .util .Lazy ;
39
38
import org .springframework .data .util .Pair ;
@@ -94,10 +93,6 @@ class SqlGenerator {
94
93
private final QueryMapper queryMapper ;
95
94
private final Dialect dialect ;
96
95
97
- private final Function <Map <AggregatePath , Column >, Condition > inCondition ;
98
- private final Function <Map <AggregatePath , Column >, Condition > equalityCondition ;
99
- private final Function <Map <AggregatePath , Column >, Condition > notNullCondition ;
100
-
101
96
/**
102
97
* Create a new {@link SqlGenerator} given {@link RelationalMappingContext} and {@link RelationalPersistentEntity}.
103
98
*
@@ -116,11 +111,6 @@ class SqlGenerator {
116
111
this .columns = new Columns (entity , mappingContext , converter );
117
112
this .queryMapper = new QueryMapper (converter );
118
113
this .dialect = dialect ;
119
-
120
- inCondition = inCondition ();
121
- equalityCondition = equalityCondition ();
122
- notNullCondition = isNotNullCondition ();
123
-
124
114
}
125
115
126
116
/**
@@ -208,7 +198,7 @@ private Condition getSubselectCondition(AggregatePath path,
208
198
}
209
199
210
200
private Expression toExpression (Map <AggregatePath , Column > columnsMap ) {
211
- return TupleExpression .maybeWrap (new ArrayList <>(columnsMap .values ()));
201
+ return TupleExpression .maybeWrap (new ArrayList <>(columnsMap .values ()));
212
202
}
213
203
214
204
private BindMarker getBindMarker (SqlIdentifier columnName ) {
@@ -454,7 +444,7 @@ String createDeleteAllSql(@Nullable PersistentPropertyPath<RelationalPersistentP
454
444
return render (deleteAll .build ());
455
445
}
456
446
457
- return createDeleteByPathAndCriteria (mappingContext .getAggregatePath (path ), notNullCondition );
447
+ return createDeleteByPathAndCriteria (mappingContext .getAggregatePath (path ), this :: isNotNullCondition );
458
448
}
459
449
460
450
/**
@@ -465,7 +455,7 @@ String createDeleteAllSql(@Nullable PersistentPropertyPath<RelationalPersistentP
465
455
* @return the statement as a {@link String}. Guaranteed to be not {@literal null}.
466
456
*/
467
457
String createDeleteByPath (PersistentPropertyPath <RelationalPersistentProperty > path ) {
468
- return createDeleteByPathAndCriteria (mappingContext .getAggregatePath (path ), equalityCondition );
458
+ return createDeleteByPathAndCriteria (mappingContext .getAggregatePath (path ), this :: equalityCondition );
469
459
}
470
460
471
461
/**
@@ -476,63 +466,55 @@ String createDeleteByPath(PersistentPropertyPath<RelationalPersistentProperty> p
476
466
* @return the statement as a {@link String}. Guaranteed to be not {@literal null}.
477
467
*/
478
468
String createDeleteInByPath (PersistentPropertyPath <RelationalPersistentProperty > path ) {
479
- return createDeleteByPathAndCriteria (mappingContext .getAggregatePath (path ), inCondition );
469
+ return createDeleteByPathAndCriteria (mappingContext .getAggregatePath (path ), this :: inCondition );
480
470
}
481
471
482
472
/**
483
- * Constructs a function for constructing a where condition. The where condition will be of the form
484
- * {@literal <columns> IN :bind-marker}
473
+ * Constructs a where condition. The where condition will be of the form {@literal <columns> IN :bind-marker}
485
474
*/
486
- private Function <Map <AggregatePath , Column >, Condition > inCondition () {
487
-
488
- return columnMap -> {
475
+ private Condition inCondition (Map <AggregatePath , Column > columnMap ) {
489
476
490
- List <Column > columns = List .copyOf (columnMap .values ());
477
+ List <Column > columns = List .copyOf (columnMap .values ());
491
478
492
- if (columns .size () == 1 ) {
493
- return Conditions .in (columns .get (0 ), getBindMarker (IDS_SQL_PARAMETER ));
494
- }
495
- return Conditions .in (TupleExpression .create (columns ), getBindMarker (IDS_SQL_PARAMETER ));
496
- };
479
+ if (columns .size () == 1 ) {
480
+ return Conditions .in (columns .get (0 ), getBindMarker (IDS_SQL_PARAMETER ));
481
+ }
482
+ return Conditions .in (TupleExpression .create (columns ), getBindMarker (IDS_SQL_PARAMETER ));
497
483
}
498
484
499
485
/**
500
- * Constructs a function for constructing a where. The where condition will be of the form
486
+ * Constructs a where-condition . The where condition will be of the form
501
487
* {@literal <column-a> = :bind-marker-a AND <column-b> = :bind-marker-b ...}
502
488
*/
503
- private Function < Map <AggregatePath , Column >, Condition > equalityCondition ( ) {
489
+ private Condition equalityCondition ( Map <AggregatePath , Column > columnMap ) {
504
490
505
491
AggregatePath .ColumnInfos idColumnInfos = mappingContext .getAggregatePath (entity ).getTableInfo ().idColumnInfos ();
506
492
507
- return columnMap -> {
508
-
509
- Condition result = null ;
510
- for (Map .Entry <AggregatePath , Column > entry : columnMap .entrySet ()) {
511
- BindMarker bindMarker = getBindMarker (idColumnInfos .get (entry .getKey ()).name ());
512
- Comparison singleCondition = entry .getValue ().isEqualTo (bindMarker );
493
+ Condition result = null ;
494
+ for (Map .Entry <AggregatePath , Column > entry : columnMap .entrySet ()) {
495
+ BindMarker bindMarker = getBindMarker (idColumnInfos .get (entry .getKey ()).name ());
496
+ Comparison singleCondition = entry .getValue ().isEqualTo (bindMarker );
513
497
514
- result = result == null ? singleCondition : result .and (singleCondition );
515
- }
516
- return result ;
517
- } ;
498
+ result = result == null ? singleCondition : result .and (singleCondition );
499
+ }
500
+ Assert . state ( result != null , "We need at least one condition" ) ;
501
+ return result ;
518
502
}
519
503
520
504
/**
521
505
* Constructs a function for constructing where a condition. The where condition will be of the form
522
506
* {@literal <column-a> IS NOT NULL AND <column-b> IS NOT NULL ... }
523
507
*/
524
- private Function <Map <AggregatePath , Column >, Condition > isNotNullCondition () {
525
-
526
- return columnMap -> {
508
+ private Condition isNotNullCondition (Map <AggregatePath , Column > columnMap ) {
527
509
528
- Condition result = null ;
529
- for (Column column : columnMap .values ()) {
530
- Condition singleCondition = column .isNotNull ();
510
+ Condition result = null ;
511
+ for (Column column : columnMap .values ()) {
512
+ Condition singleCondition = column .isNotNull ();
531
513
532
- result = result == null ? singleCondition : result .and (singleCondition );
533
- }
534
- return result ;
535
- } ;
514
+ result = result == null ? singleCondition : result .and (singleCondition );
515
+ }
516
+ Assert . state ( result != null , "We need at least one condition" ) ;
517
+ return result ;
536
518
}
537
519
538
520
private String createFindOneSql () {
0 commit comments