|
68 | 68 | import org.springframework.data.mapping.PersistentPropertyAccessor;
|
69 | 69 | import org.springframework.data.mapping.context.MappingContext;
|
70 | 70 | import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
|
71 |
| -import org.springframework.data.mapping.model.Property; |
72 | 71 | import org.springframework.data.mongodb.MongoDbFactory;
|
73 | 72 | import org.springframework.data.mongodb.core.BulkOperations.BulkMode;
|
74 | 73 | import org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext;
|
@@ -2325,49 +2324,30 @@ private Document getMappedSortObject(Query query, Class<?> type) {
|
2325 | 2324 | }
|
2326 | 2325 |
|
2327 | 2326 | private Document getMappedFieldsObject(Document fields, MongoPersistentEntity<?> entity, Class<?> targetType) {
|
2328 |
| - |
2329 |
| - Document mappedFields = queryMapper.getMappedFields(fields, entity); |
2330 |
| - return addFieldsForProjection(mappedFields, entity.getType(), targetType); |
| 2327 | + return queryMapper.getMappedFields(addFieldsForProjection(fields, entity.getType(), targetType), entity); |
2331 | 2328 | }
|
2332 | 2329 |
|
2333 | 2330 | /**
|
2334 |
| - * For cases where {@code mappedFields} is {@literal null} or {@literal empty} add fields required for creating the |
2335 |
| - * projection (target) type if the {@code targetType} is a {@literal closed projection}. |
| 2331 | + * For cases where {@code fields} is {@literal null} or {@literal empty} add fields required for creating the |
| 2332 | + * projection (target) type if the {@code targetType} is a {@literal closed interface projection}. |
2336 | 2333 | *
|
2337 |
| - * @param mappedFields can be {@literal null}. |
| 2334 | + * @param fields can be {@literal null}. |
2338 | 2335 | * @param domainType must not be {@literal null}.
|
2339 | 2336 | * @param targetType must not be {@literal null}.
|
2340 | 2337 | * @return {@link Document} with fields to be included.
|
2341 | 2338 | */
|
2342 |
| - private Document addFieldsForProjection(Document mappedFields, Class<?> domainType, Class<?> targetType) { |
2343 |
| - |
2344 |
| - if ((mappedFields != null && !mappedFields.isEmpty()) || ClassUtils.isAssignable(domainType, targetType)) { |
2345 |
| - return mappedFields; |
2346 |
| - } |
2347 |
| - |
2348 |
| - Document fields = new Document(); |
2349 |
| - |
2350 |
| - if (!targetType.isInterface()) { |
2351 |
| - |
2352 |
| - MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(targetType); |
2353 |
| - |
2354 |
| - for (MongoPersistentProperty property : entity) { |
2355 |
| - if (!property.isTransient()) { |
2356 |
| - fields.append(property.getFieldName(), 1); |
2357 |
| - } |
2358 |
| - } |
| 2339 | + private Document addFieldsForProjection(Document fields, Class<?> domainType, Class<?> targetType) { |
2359 | 2340 |
|
| 2341 | + if ((fields != null && !fields.isEmpty()) || !targetType.isInterface() |
| 2342 | + || ClassUtils.isAssignable(domainType, targetType)) { |
2360 | 2343 | return fields;
|
2361 | 2344 | }
|
2362 | 2345 |
|
2363 |
| - ProjectionInformation pi = PROJECTION_FACTORY.getProjectionInformation(targetType); |
2364 |
| - if (pi.isClosed()) { |
2365 |
| - |
2366 |
| - for (PropertyDescriptor pd : pi.getInputProperties()) { |
| 2346 | + ProjectionInformation projectionInformation = PROJECTION_FACTORY.getProjectionInformation(targetType); |
| 2347 | + if (projectionInformation.isClosed()) { |
2367 | 2348 |
|
2368 |
| - MongoPersistentProperty pp = ((MongoMappingContext) mappingContext).createPersistentProperty(Property.of(pd), |
2369 |
| - ((MongoMappingContext) mappingContext).getPersistentEntity(targetType), MongoSimpleTypes.HOLDER); |
2370 |
| - fields.append(pp.getFieldName(), 1); |
| 2349 | + for (PropertyDescriptor descriptor : projectionInformation.getInputProperties()) { |
| 2350 | + fields.append(descriptor.getName(), 1); |
2371 | 2351 | }
|
2372 | 2352 | }
|
2373 | 2353 |
|
|
0 commit comments