16
16
package org .springframework .data .map .repository .config ;
17
17
18
18
import java .lang .reflect .Constructor ;
19
- import java .util .Map ;
20
19
import java .util .Optional ;
20
+ import java .util .function .Predicate ;
21
21
22
22
import org .jspecify .annotations .Nullable ;
23
23
26
26
import org .springframework .beans .factory .config .RuntimeBeanReference ;
27
27
import org .springframework .beans .factory .support .AbstractBeanDefinition ;
28
28
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
29
- import org .springframework .core .type .AnnotationMetadata ;
30
29
import org .springframework .data .config .ParsingUtils ;
31
30
import org .springframework .data .keyvalue .core .KeyValueTemplate ;
32
31
import org .springframework .data .keyvalue .core .QueryEngine ;
38
37
import org .springframework .data .repository .config .RepositoryConfigurationExtension ;
39
38
import org .springframework .data .repository .config .RepositoryConfigurationSource ;
40
39
import org .springframework .util .ClassUtils ;
41
- import org .springframework .util .StringUtils ;
42
40
43
41
/**
44
42
* {@link RepositoryConfigurationExtension} for Map-based repositories.
@@ -92,32 +90,28 @@ private static Object getKeySpaceStore(RepositoryConfigurationSource source) {
92
90
93
91
Optional <String > keySpaceStoreRef = source .getAttribute ("keySpaceStoreRef" , String .class );
94
92
95
- return keySpaceStoreRef .filter (StringUtils ::hasText )
96
- .map (beanName -> new RuntimeBeanReference (beanName , KeySpaceStore .class )).map (Object .class ::cast )
97
- .orElseGet (() -> {
98
- return getAnnotationAttributes (source ).get ("mapType" );
99
- });
93
+ return keySpaceStoreRef .map (beanName -> new RuntimeBeanReference (beanName , KeySpaceStore .class )) //
94
+ .map (Object .class ::cast ) //
95
+ .orElseGet (() -> source .getRequiredAttribute ("mapType" , Class .class ));
100
96
}
101
97
102
98
private static @ Nullable SortAccessor <?> getSortAccessor (RepositoryConfigurationSource source ) {
103
99
104
- Class <? extends SortAccessor <?>> sortAccessorType = (Class <? extends SortAccessor <?>>) getAnnotationAttributes (
105
- source ).get ("sortAccessor" );
100
+ Class <? extends SortAccessor <?>> sortAccessorType = getClassAttribute (source , "sortAccessor" );
106
101
107
- if (sortAccessorType != null && ! sortAccessorType . isInterface () ) {
108
- return BeanUtils . instantiateClass ( sortAccessorType ) ;
102
+ if (sortAccessorType == null ) {
103
+ return null ;
109
104
}
110
105
111
- return null ;
106
+ return BeanUtils . instantiateClass ( sortAccessorType ) ;
112
107
}
113
108
114
109
private static @ Nullable QueryEngine <?, ?, ?> getQueryEngine (@ Nullable SortAccessor <?> sortAccessor ,
115
110
RepositoryConfigurationSource source ) {
116
111
117
- Class <? extends QueryEngineFactory > queryEngineFactoryType = (Class <? extends QueryEngineFactory >) getAnnotationAttributes (
118
- source ).get ("queryEngineFactory" );
112
+ Class <? extends QueryEngineFactory > queryEngineFactoryType = getClassAttribute (source , "queryEngineFactory" );
119
113
120
- if (queryEngineFactoryType == null || queryEngineFactoryType . isInterface () ) {
114
+ if (queryEngineFactoryType == null ) {
121
115
return null ;
122
116
}
123
117
@@ -132,21 +126,8 @@ private static Object getKeySpaceStore(RepositoryConfigurationSource source) {
132
126
return BeanUtils .instantiateClass (queryEngineFactoryType ).create ();
133
127
}
134
128
135
- private static Map <String , Object > getAnnotationAttributes (RepositoryConfigurationSource source ) {
136
-
137
- AnnotationMetadata annotationSource = (AnnotationMetadata ) source .getSource ();
138
-
139
- if (annotationSource == null ) {
140
- throw new IllegalArgumentException ("AnnotationSource not available" );
141
- }
142
-
143
- Map <String , Object > annotationAttributes = annotationSource
144
- .getAnnotationAttributes (EnableMapRepositories .class .getName ());
145
-
146
- if (annotationAttributes == null ) {
147
- throw new IllegalStateException ("No annotation attributes for @EnableMapRepositories" );
148
- }
149
-
150
- return annotationAttributes ;
129
+ private static <T > @ Nullable Class <T > getClassAttribute (RepositoryConfigurationSource source , String attributeName ) {
130
+ return source .getAttribute (attributeName , Class .class ).filter (Predicate .not (Class ::isInterface )).orElse (null );
151
131
}
132
+
152
133
}
0 commit comments