|
27 | 27 | import org.springframework.jdbc.core.SingleColumnRowMapper;
|
28 | 28 |
|
29 | 29 | /**
|
30 |
| - * Default implementation of {@link RowMapperFactory}. Honors the custom mappings defined |
31 |
| - * in {@link QueryMappingConfiguration}. |
| 30 | + * Default implementation of {@link RowMapperFactory}. Honors the custom mappings defined in |
| 31 | + * {@link QueryMappingConfiguration}. |
32 | 32 | * <p>
|
33 |
| - * This implementation is not capable of loading the {@link RowMapper} or {@link ResultSetExtractor} |
34 |
| - * by reference via corresponding methods from {@link RowMapperFactory}. |
| 33 | + * This implementation is not capable of loading the {@link RowMapper} or {@link ResultSetExtractor} by reference via |
| 34 | + * corresponding methods from {@link RowMapperFactory}. |
35 | 35 | *
|
36 | 36 | * @implNote Public APIs of this class are thread-safe.
|
37 | 37 | * @author Mikhail Polivakha
|
| 38 | + * @since 4.0 |
38 | 39 | */
|
39 | 40 | public class DefaultRowMapperFactory implements RowMapperFactory {
|
40 | 41 |
|
41 |
| - private final RelationalMappingContext context; |
42 |
| - private final JdbcConverter converter; |
43 |
| - private final QueryMappingConfiguration queryMappingConfiguration; |
44 |
| - private final EntityCallbacks entityCallbacks; |
45 |
| - private final ApplicationEventPublisher publisher; |
| 42 | + private final RelationalMappingContext context; |
| 43 | + private final JdbcConverter converter; |
| 44 | + private final QueryMappingConfiguration queryMappingConfiguration; |
| 45 | + private final EntityCallbacks entityCallbacks; |
| 46 | + private final ApplicationEventPublisher publisher; |
46 | 47 |
|
47 |
| - public DefaultRowMapperFactory( |
48 |
| - RelationalMappingContext context, |
49 |
| - JdbcConverter converter, |
50 |
| - QueryMappingConfiguration queryMappingConfiguration, |
51 |
| - EntityCallbacks entityCallbacks, |
52 |
| - ApplicationEventPublisher publisher |
53 |
| - ) { |
54 |
| - this.context = context; |
55 |
| - this.converter = converter; |
56 |
| - this.queryMappingConfiguration = queryMappingConfiguration; |
57 |
| - this.entityCallbacks = entityCallbacks; |
58 |
| - this.publisher = publisher; |
59 |
| - } |
| 48 | + public DefaultRowMapperFactory(RelationalMappingContext context, JdbcConverter converter, |
| 49 | + QueryMappingConfiguration queryMappingConfiguration, EntityCallbacks entityCallbacks, |
| 50 | + ApplicationEventPublisher publisher) { |
60 | 51 |
|
61 |
| - @Override |
62 |
| - @SuppressWarnings("unchecked") |
63 |
| - public RowMapper<Object> create(Class<?> returnedObjectType) { |
| 52 | + this.context = context; |
| 53 | + this.converter = converter; |
| 54 | + this.queryMappingConfiguration = queryMappingConfiguration; |
| 55 | + this.entityCallbacks = entityCallbacks; |
| 56 | + this.publisher = publisher; |
| 57 | + } |
64 | 58 |
|
65 |
| - RelationalPersistentEntity<?> persistentEntity = context.getPersistentEntity(returnedObjectType); |
| 59 | + @Override |
| 60 | + @SuppressWarnings("unchecked") |
| 61 | + public RowMapper<Object> create(Class<?> returnedObjectType) { |
66 | 62 |
|
67 |
| - if (persistentEntity == null) { |
68 |
| - return (RowMapper<Object>) SingleColumnRowMapper.newInstance(returnedObjectType, |
69 |
| - converter.getConversionService()); |
70 |
| - } |
| 63 | + RelationalPersistentEntity<?> persistentEntity = context.getPersistentEntity(returnedObjectType); |
71 | 64 |
|
72 |
| - return (RowMapper<Object>) determineDefaultMapper(returnedObjectType); |
73 |
| - } |
| 65 | + if (persistentEntity == null) { |
74 | 66 |
|
75 |
| - private RowMapper<?> determineDefaultMapper(Class<?> returnedObjectType) { |
| 67 | + return (RowMapper<Object>) SingleColumnRowMapper.newInstance(returnedObjectType, |
| 68 | + converter.getConversionService()); |
| 69 | + } |
76 | 70 |
|
77 |
| - RowMapper<?> configuredQueryMapper = queryMappingConfiguration.getRowMapper(returnedObjectType); |
| 71 | + return (RowMapper<Object>) determineDefaultMapper(returnedObjectType); |
| 72 | + } |
78 | 73 |
|
79 |
| - if (configuredQueryMapper != null) { |
80 |
| - return configuredQueryMapper; |
81 |
| - } |
| 74 | + private RowMapper<?> determineDefaultMapper(Class<?> returnedObjectType) { |
82 | 75 |
|
83 |
| - EntityRowMapper<?> defaultEntityRowMapper = new EntityRowMapper<>( // |
84 |
| - context.getRequiredPersistentEntity(returnedObjectType), // |
85 |
| - converter // |
86 |
| - ); |
| 76 | + RowMapper<?> configuredQueryMapper = queryMappingConfiguration.getRowMapper(returnedObjectType); |
87 | 77 |
|
88 |
| - return new CallbackCapableRowMapper<>(defaultEntityRowMapper, publisher, entityCallbacks); |
89 |
| - } |
| 78 | + if (configuredQueryMapper != null) { |
| 79 | + return configuredQueryMapper; |
| 80 | + } |
| 81 | + |
| 82 | + EntityRowMapper<?> defaultEntityRowMapper = new EntityRowMapper<>( // |
| 83 | + context.getRequiredPersistentEntity(returnedObjectType), // |
| 84 | + converter // |
| 85 | + ); |
| 86 | + |
| 87 | + return new CallbackCapableRowMapper<>(defaultEntityRowMapper, publisher, entityCallbacks); |
| 88 | + } |
90 | 89 | }
|
0 commit comments