1515 */
1616package org .springframework .data .jdbc .repository .query ;
1717
18- import java .util .ArrayList ;
19- import java .util .List ;
2018import java .util .Optional ;
2119import java .util .function .Predicate ;
2220
@@ -81,14 +79,16 @@ class JdbcQueryCreator extends RelationalQueryCreator<ParametrizedQuery> {
8179 * @param accessor parameter metadata provider, must not be {@literal null}.
8280 * @param isSliceQuery flag denoting if the query returns a {@link org.springframework.data.domain.Slice}.
8381 * @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.
8685 */
8786 @ Deprecated (since = "4.0" , forRemoval = true )
8887 JdbcQueryCreator (RelationalMappingContext context , PartTree tree , JdbcConverter converter , Dialect dialect ,
8988 RelationalEntityMetadata <?> entityMetadata , RelationalParameterAccessor accessor , boolean isSliceQuery ,
9089 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 ));
9292 }
9393
9494 /**
@@ -104,8 +104,8 @@ class JdbcQueryCreator extends RelationalQueryCreator<ParametrizedQuery> {
104104 * @param isSliceQuery flag denoting if the query returns a {@link org.springframework.data.domain.Slice}.
105105 * @param returnedType the {@link ReturnedType} to be returned by the query. Must not be {@literal null}.
106106 * @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}
109109 */
110110 JdbcQueryCreator (RelationalMappingContext context , PartTree tree , JdbcConverter converter , Dialect dialect ,
111111 RelationalEntityMetadata <?> entityMetadata , RelationalParameterAccessor accessor , boolean isSliceQuery ,
@@ -258,125 +258,13 @@ SelectBuilder.SelectLimitOffset createSelectClause(RelationalPersistentEntity<?>
258258
259259 private SelectBuilder .SelectJoin selectBuilder (Table table ) {
260260
261-
262- List <Expression > columnExpressions = new ArrayList <>();
263261 RelationalPersistentEntity <?> entity = entityMetadata .getTableEntity ();
264262
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 ());
346265
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
368267 );
369268 }
370269
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- }
382270}
0 commit comments