15
15
*/
16
16
package org .springframework .data .jdbc .repository .query ;
17
17
18
- import java .util .ArrayList ;
19
- import java .util .List ;
20
18
import java .util .Optional ;
21
19
import java .util .function .Predicate ;
22
20
@@ -81,14 +79,16 @@ class JdbcQueryCreator extends RelationalQueryCreator<ParametrizedQuery> {
81
79
* @param accessor parameter metadata provider, must not be {@literal null}.
82
80
* @param isSliceQuery flag denoting if the query returns a {@link org.springframework.data.domain.Slice}.
83
81
* @param returnedType the {@link ReturnedType} to be returned by the query. Must not be {@literal null}.
84
- *
85
- * @deprecated use {@link JdbcQueryCreator#JdbcQueryCreator(RelationalMappingContext, PartTree, JdbcConverter, Dialect, RelationalEntityMetadata, RelationalParameterAccessor, boolean, ReturnedType, Optional, SqlGeneratorSource)} instead.
82
+ * @deprecated use
83
+ * {@link JdbcQueryCreator#JdbcQueryCreator(RelationalMappingContext, PartTree, JdbcConverter, Dialect, RelationalEntityMetadata, RelationalParameterAccessor, boolean, ReturnedType, Optional, SqlGeneratorSource)}
84
+ * instead.
86
85
*/
87
86
@ Deprecated (since = "4.0" , forRemoval = true )
88
87
JdbcQueryCreator (RelationalMappingContext context , PartTree tree , JdbcConverter converter , Dialect dialect ,
89
88
RelationalEntityMetadata <?> entityMetadata , RelationalParameterAccessor accessor , boolean isSliceQuery ,
90
89
ReturnedType returnedType , Optional <Lock > lockMode ) {
91
- this (context , tree , converter , dialect , entityMetadata , accessor , isSliceQuery , returnedType , lockMode , new SqlGeneratorSource (context , converter , dialect ));
90
+ this (context , tree , converter , dialect , entityMetadata , accessor , isSliceQuery , returnedType , lockMode ,
91
+ new SqlGeneratorSource (context , converter , dialect ));
92
92
}
93
93
94
94
/**
@@ -104,8 +104,8 @@ class JdbcQueryCreator extends RelationalQueryCreator<ParametrizedQuery> {
104
104
* @param isSliceQuery flag denoting if the query returns a {@link org.springframework.data.domain.Slice}.
105
105
* @param returnedType the {@link ReturnedType} to be returned by the query. Must not be {@literal null}.
106
106
* @param lockMode lock mode to be used for the query.
107
- * @param sqlGeneratorSource the source providing SqlGenerator instances for generating SQL. Must not be {@literal null}
108
- *
107
+ * @param sqlGeneratorSource the source providing SqlGenerator instances for generating SQL. Must not be
108
+ * {@literal null}
109
109
*/
110
110
JdbcQueryCreator (RelationalMappingContext context , PartTree tree , JdbcConverter converter , Dialect dialect ,
111
111
RelationalEntityMetadata <?> entityMetadata , RelationalParameterAccessor accessor , boolean isSliceQuery ,
@@ -258,125 +258,13 @@ SelectBuilder.SelectLimitOffset createSelectClause(RelationalPersistentEntity<?>
258
258
259
259
private SelectBuilder .SelectJoin selectBuilder (Table table ) {
260
260
261
-
262
- List <Expression > columnExpressions = new ArrayList <>();
263
261
RelationalPersistentEntity <?> entity = entityMetadata .getTableEntity ();
264
262
265
- Predicate <AggregatePath > filter = ap -> returnedType .needsCustomConstruction () && !returnedType .getInputProperties ().contains (ap .getRequiredBaseProperty ().getName ());
266
-
267
- return (SelectBuilder .SelectJoin ) sqlGeneratorSource .getSqlGenerator (entity .getType ()).createSelectBuilder (
268
- filter
269
- , table );
270
- //
271
- // SqlContext sqlContext = new SqlContext();
272
- //
273
- // List<Join> joinTables = new ArrayList<>();
274
- // for (PersistentPropertyPath<RelationalPersistentProperty> path : context
275
- // .findPersistentPropertyPaths(entity.getType(), p -> true)) {
276
- //
277
- // AggregatePath aggregatePath = context.getAggregatePath(path);
278
- //
279
- // if (filter.test(aggregatePath)) { continue;}
280
- //
281
- // // add a join if necessary
282
- // Join join = getJoin(sqlContext, aggregatePath);
283
- // if (join != null) {
284
- // joinTables.add(join);
285
- // }
286
- //
287
- // Column column = getColumn(sqlContext, aggregatePath);
288
- // if (column != null) {
289
- // columnExpressions.add(column);
290
- // }
291
- // }
292
- //
293
- // SelectBuilder.SelectJoin baseSelect = StatementBuilder.select(columnExpressions).from(table);
294
- //
295
- // // TODO: included in SqlGenerator.Join
296
- // for (Join join : joinTables) {
297
- //
298
- // Condition condition = null;
299
- //
300
- // for (int i = 0; i < join.joinColumns.size(); i++) {
301
- // Column parentColumn = join.parentId.get(i);
302
- // Column joinColumn = join.joinColumns.get(i);
303
- // Comparison singleCondition = joinColumn.isEqualTo(parentColumn);
304
- // condition = condition == null ? singleCondition : condition.and(singleCondition);
305
- // }
306
- //
307
- // Assert.state(condition != null, "No condition found");
308
- //
309
- // baseSelect = baseSelect.leftOuterJoin(join.joinTable).on(condition);
310
- // }
311
- //
312
- // return baseSelect;
313
- }
314
-
315
- /**
316
- * Create a {@link Column} for {@link AggregatePath}.
317
- *
318
- * @param sqlContext for generating SQL constructs.
319
- * @param path the path to the column in question.
320
- * @return the statement as a {@link String}. Guaranteed to be not {@literal null}.
321
- */
322
- @ Nullable
323
- private Column getColumn (SqlContext sqlContext , AggregatePath path ) {
324
-
325
- // an embedded itself doesn't give an column, its members will though.
326
- // if there is a collection or map on the path it won't get selected at all, but it will get loaded with a separate
327
- // select
328
- // only the parent path is considered in order to handle arrays that get stored as BINARY properly
329
- if (path .isEmbedded () || path .getParentPath ().isMultiValued ()) {
330
- return null ;
331
- }
332
-
333
- if (path .isEntity ()) {
334
-
335
- if (path .isQualified () //
336
- || path .isCollectionLike () //
337
- || path .hasIdProperty () //
338
- ) {
339
- return null ;
340
- }
341
-
342
- // Simple entities without id include there backreference as an synthetic id in order to distinguish null entities
343
- // from entities with only null values.
344
- return sqlContext .getAnyReverseColumn (path );
345
- }
263
+ Predicate <AggregatePath > filter = ap -> returnedType .needsCustomConstruction ()
264
+ && !returnedType .getInputProperties ().contains (ap .getRequiredBaseProperty ().getName ());
346
265
347
- return sqlContext .getColumn (path );
348
- }
349
-
350
- @ Nullable
351
- Join getJoin (SqlContext sqlContext , AggregatePath path ) {
352
-
353
- if (!path .isEntity () || path .isEmbedded () || path .isMultiValued ()) {
354
- return null ;
355
- }
356
-
357
- Table currentTable = sqlContext .getTable (path );
358
-
359
- AggregatePath idDefiningParentPath = path .getIdDefiningParentPath ();
360
- Table parentTable = sqlContext .getTable (idDefiningParentPath );
361
-
362
- List <Column > reverseColumns = path .getTableInfo ().backReferenceColumnInfos ().toColumnList (currentTable );
363
- List <Column > idColumns = idDefiningParentPath .getTableInfo ().idColumnInfos ().toColumnList (parentTable );
364
- return new Join ( //
365
- currentTable , //
366
- reverseColumns , //
367
- idColumns //
266
+ return (SelectBuilder .SelectJoin ) sqlGeneratorSource .getSqlGenerator (entity .getType ()).createSelectBuilder (table , filter
368
267
);
369
268
}
370
269
371
- /**
372
- * Value object representing a {@code JOIN} association.
373
- */
374
- private record Join (Table joinTable , List <Column > joinColumns , List <Column > parentId ) {
375
-
376
- Join {
377
- Assert .isTrue (joinColumns .size () == parentId .size (),
378
- "Both sides of a join condition must have the same number of columns" );
379
- }
380
-
381
- }
382
270
}
0 commit comments