1616package org .springframework .data .map .repository .config ;
1717
1818import java .lang .reflect .Constructor ;
19- import java .util .Map ;
2019import java .util .Optional ;
20+ import java .util .function .Predicate ;
2121
2222import org .jspecify .annotations .Nullable ;
2323
2626import org .springframework .beans .factory .config .RuntimeBeanReference ;
2727import org .springframework .beans .factory .support .AbstractBeanDefinition ;
2828import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
29- import org .springframework .core .type .AnnotationMetadata ;
3029import org .springframework .data .config .ParsingUtils ;
3130import org .springframework .data .keyvalue .core .KeyValueTemplate ;
3231import org .springframework .data .keyvalue .core .QueryEngine ;
3837import org .springframework .data .repository .config .RepositoryConfigurationExtension ;
3938import org .springframework .data .repository .config .RepositoryConfigurationSource ;
4039import org .springframework .util .ClassUtils ;
41- import org .springframework .util .StringUtils ;
4240
4341/**
4442 * {@link RepositoryConfigurationExtension} for Map-based repositories.
@@ -92,32 +90,28 @@ private static Object getKeySpaceStore(RepositoryConfigurationSource source) {
9290
9391 Optional <String > keySpaceStoreRef = source .getAttribute ("keySpaceStoreRef" , String .class );
9492
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 ));
10096 }
10197
10298 private static @ Nullable SortAccessor <?> getSortAccessor (RepositoryConfigurationSource source ) {
10399
104- Class <? extends SortAccessor <?>> sortAccessorType = (Class <? extends SortAccessor <?>>) getAnnotationAttributes (
105- source ).get ("sortAccessor" );
100+ Class <? extends SortAccessor <?>> sortAccessorType = getClassAttribute (source , "sortAccessor" );
106101
107- if (sortAccessorType != null && ! sortAccessorType . isInterface () ) {
108- return BeanUtils . instantiateClass ( sortAccessorType ) ;
102+ if (sortAccessorType == null ) {
103+ return null ;
109104 }
110105
111- return null ;
106+ return BeanUtils . instantiateClass ( sortAccessorType ) ;
112107 }
113108
114109 private static @ Nullable QueryEngine <?, ?, ?> getQueryEngine (@ Nullable SortAccessor <?> sortAccessor ,
115110 RepositoryConfigurationSource source ) {
116111
117- Class <? extends QueryEngineFactory > queryEngineFactoryType = (Class <? extends QueryEngineFactory >) getAnnotationAttributes (
118- source ).get ("queryEngineFactory" );
112+ Class <? extends QueryEngineFactory > queryEngineFactoryType = getClassAttribute (source , "queryEngineFactory" );
119113
120- if (queryEngineFactoryType == null || queryEngineFactoryType . isInterface () ) {
114+ if (queryEngineFactoryType == null ) {
121115 return null ;
122116 }
123117
@@ -132,21 +126,8 @@ private static Object getKeySpaceStore(RepositoryConfigurationSource source) {
132126 return BeanUtils .instantiateClass (queryEngineFactoryType ).create ();
133127 }
134128
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 );
151131 }
132+
152133}
0 commit comments