|
19 | 19 | import java.util.ArrayList; |
20 | 20 | import java.util.List; |
21 | 21 | import java.util.Map; |
| 22 | +import java.util.function.BiFunction; |
22 | 23 | import java.util.function.Function; |
23 | 24 | import java.util.function.Predicate; |
24 | 25 |
|
@@ -148,31 +149,27 @@ <T> SqlIdentifierParameterSource forQueryByIds(Iterable<?> ids, Class<T> domainT |
148 | 149 |
|
149 | 150 | SqlIdentifierParameterSource parameterSource = new SqlIdentifierParameterSource(); |
150 | 151 |
|
151 | | - RelationalPersistentEntity<?> entity = context.getPersistentEntity(domainType); |
| 152 | + RelationalPersistentEntity<?> entity = context.getRequiredPersistentEntity(domainType); |
152 | 153 | RelationalPersistentProperty singleIdProperty = entity.getRequiredIdProperty(); |
| 154 | + RelationalPersistentEntity<?> complexId = context.getPersistentEntity(singleIdProperty); |
| 155 | + AggregatePath.ColumnInfos idColumnInfos = context.getAggregatePath(entity).getTableInfo().idColumnInfos(); |
153 | 156 |
|
154 | | - if (singleIdProperty.isEntity()) { |
155 | | - |
156 | | - RelationalPersistentEntity<?> complexId = context.getPersistentEntity(singleIdProperty); |
157 | | - |
158 | | - AggregatePath.ColumnInfos idColumnInfos = context.getAggregatePath(entity).getTableInfo().idColumnInfos(); |
| 157 | + BiFunction<Object, AggregatePath, Object> valueExtractor = complexId == null |
| 158 | + ? (id, ap) -> id |
| 159 | + : (id, ap) -> complexId.getPropertyPathAccessor(id).getProperty(ap.getRequiredPersistentPropertyPath()); |
159 | 160 |
|
160 | | - List<Object[]> parameterValues = new ArrayList<>(); |
161 | | - for (Object id : ids) { |
| 161 | + List<Object[]> parameterValues = new ArrayList<>(); |
| 162 | + for (Object id : ids) { |
162 | 163 |
|
163 | | - PersistentPropertyPathAccessor<Object> accessor = complexId.getPropertyPathAccessor(id); |
| 164 | + List<Object> tupleList = new ArrayList<>(); |
| 165 | + idColumnInfos.forEach((ap, ci) -> { |
| 166 | + tupleList.add(valueExtractor.apply(id, ap)); |
| 167 | + }); |
| 168 | + parameterValues.add(tupleList.toArray(new Object[0])); |
| 169 | + } |
164 | 170 |
|
165 | | - List<Object> tupleList = new ArrayList<>(); |
166 | | - idColumnInfos.forEach((ap, ci) -> { |
167 | | - tupleList.add(accessor.getProperty(ap.getRequiredPersistentPropertyPath())); |
168 | | - }); |
169 | | - parameterValues.add(tupleList.toArray(new Object[0])); |
170 | | - } |
| 171 | + parameterSource.addValue(SqlGenerator.IDS_SQL_PARAMETER, parameterValues); |
171 | 172 |
|
172 | | - parameterSource.addValue(SqlGenerator.IDS_SQL_PARAMETER, parameterValues); |
173 | | - } else { |
174 | | - addConvertedPropertyValuesAsList(parameterSource, getRequiredPersistentEntity(domainType).getRequiredIdProperty(), ids); |
175 | | - } |
176 | 173 | return parameterSource; |
177 | 174 | } |
178 | 175 |
|
|
0 commit comments