Skip to content

Commit 8ae6474

Browse files
committed
remove old method
1 parent d528913 commit 8ae6474

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/JdbcDeleteQueryCreator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ protected List<ParametrizedQuery> complete(@Nullable Criteria criteria, Sort sor
9292
Condition condition = criteria == null ? null
9393
: queryMapper.getMappedObject(parameterSource, criteria, table, entity);
9494

95-
List<Column> idColumns = context.getAggregatePath(entity).getTableInfo().idColumnInfos()
96-
.toList(ci -> table.column(ci.name()));
95+
List<Column> idColumns = context.getAggregatePath(entity).getTableInfo().idColumnInfos().toColumnList(table);
9796

9897
// create select criteria query for subselect
9998
SelectWhere selectBuilder = StatementBuilder.select(idColumns).from(table);
@@ -138,14 +137,12 @@ private void deleteRelations(List<Delete> deleteChain, RelationalPersistentEntit
138137
// MariaDB prior to 11.6 does not support aliases for delete statements
139138
Table table = sqlContext.getUnaliasedTable(aggregatePath);
140139

141-
List<Column> reverseColumns = aggregatePath.getTableInfo().backReferenceColumnInfos()
142-
.toList(ci -> table.column(ci.name()));
140+
List<Column> reverseColumns = aggregatePath.getTableInfo().backReferenceColumnInfos().toColumnList(table);
143141
Expression expression = Expressions.of(reverseColumns);
144142

145143
Condition inCondition = Conditions.in(expression, parentSelect);
146144

147-
List<Column> parentIdColumns = aggregatePath.getIdDefiningParentPath().getTableInfo().idColumnInfos()
148-
.toList(ci -> table.column(ci.name()));
145+
List<Column> parentIdColumns = aggregatePath.getIdDefiningParentPath().getTableInfo().idColumnInfos().toColumnList(table);
149146

150147
Select select = StatementBuilder.select( //
151148
parentIdColumns //

spring-data-relational/src/main/java/org/springframework/data/relational/core/mapping/AggregatePath.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.function.BiConsumer;
2424
import java.util.function.BiFunction;
2525
import java.util.function.BinaryOperator;
26-
import java.util.function.Function;
2726
import java.util.function.Predicate;
2827
import java.util.stream.Stream;
2928
import java.util.stream.StreamSupport;
@@ -482,6 +481,7 @@ class ColumnInfos {
482481

483482
private final AggregatePath basePath;
484483
private final Map<AggregatePath, ColumnInfo> columnInfos;
484+
private final Map<Table, List<Column>> columnCache = new HashMap<>();
485485

486486
/**
487487
* Creates a new ColumnInfos instances based on the arguments.
@@ -542,18 +542,19 @@ public boolean isEmpty() {
542542
}
543543

544544
/**
545-
* Applies a function to all the {@link ColumnInfo} instances and returns the result in a list.
545+
* Converts the given {@link Table} into a list of {@link Column}s. This method retrieves and caches the list of
546+
* columns for the specified table. If the columns are not already cached, it computes the list by mapping
547+
* {@code columnInfos} to their corresponding {@link Column} in the provided table and then stores the result in the
548+
* cache.
546549
*
547-
* @param mapper the function to be applied
548-
* @param <T> the type returned by {@literal mapper} and contained in the resulting {@literal List}
549-
* @return the list of results from mapper.
550+
* @param table the {@link Table} for which the columns should be generated; must not be {@literal null}.
551+
* @return a list of {@link Column}s associated with the specified {@link Table}. Guaranteed no to be
552+
* {@literal null}.
550553
*/
551-
public <T> List<T> toList(Function<ColumnInfo, T> mapper) {
552-
return columnInfos.values().stream().map(mapper).toList();
553-
}
554-
555554
public List<Column> toColumnList(Table table) {
556-
return toList(columnInfo -> table.column(columnInfo.name));
555+
556+
return columnCache.computeIfAbsent(table,
557+
t -> columnInfos.values().stream().map(columnInfo -> t.column(columnInfo.name)).toList());
557558
}
558559

559560
/**

0 commit comments

Comments
 (0)