21
21
import java .util .Map ;
22
22
import java .util .Optional ;
23
23
import java .util .Set ;
24
+ import java .util .function .Function ;
24
25
import java .util .stream .Stream ;
25
26
26
27
import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
42
43
import org .springframework .util .StringUtils ;
43
44
44
45
/**
45
- * Annotation based {@link RepositoryConfigurationSource}.
46
+ * Annotation- based {@link RepositoryConfigurationSource}.
46
47
*
47
48
* @author Oliver Gierke
48
49
* @author Thomas Darimont
@@ -67,9 +68,7 @@ public class AnnotationRepositoryConfigurationSource extends RepositoryConfigura
67
68
private final AnnotationMetadata configMetadata ;
68
69
private final AnnotationMetadata enableAnnotationMetadata ;
69
70
private final AnnotationAttributes attributes ;
70
- private final ResourceLoader resourceLoader ;
71
- private final Environment environment ;
72
- private final BeanDefinitionRegistry registry ;
71
+ private final Function <AnnotationAttributes , Stream <TypeFilter >> typeFilterFunction ;
73
72
private final boolean hasExplicitFilters ;
74
73
75
74
/**
@@ -83,7 +82,7 @@ public class AnnotationRepositoryConfigurationSource extends RepositoryConfigura
83
82
* @param registry must not be {@literal null}.
84
83
* @deprecated since 2.2. Prefer to use overload taking a {@link BeanNameGenerator} additionally.
85
84
*/
86
- @ Deprecated
85
+ @ Deprecated ( since = "2.2" )
87
86
public AnnotationRepositoryConfigurationSource (AnnotationMetadata metadata , Class <? extends Annotation > annotation ,
88
87
ResourceLoader resourceLoader , Environment environment , BeanDefinitionRegistry registry ) {
89
88
this (metadata , annotation , resourceLoader , environment , registry , null );
@@ -120,12 +119,12 @@ public AnnotationRepositoryConfigurationSource(AnnotationMetadata metadata, Clas
120
119
this .attributes = new AnnotationAttributes (annotationAttributes );
121
120
this .enableAnnotationMetadata = AnnotationMetadata .introspect (annotation );
122
121
this .configMetadata = metadata ;
123
- this .resourceLoader = resourceLoader ;
124
- this .environment = environment ;
125
- this .registry = registry ;
122
+ this .typeFilterFunction = it -> TypeFilterUtils .createTypeFiltersFor (it , environment , resourceLoader , registry )
123
+ .stream ();
126
124
this .hasExplicitFilters = hasExplicitFilters (attributes );
127
125
}
128
126
127
+ @ Override
129
128
public Streamable <String > getBasePackages () {
130
129
131
130
String [] value = attributes .getStringArray ("value" );
@@ -139,7 +138,7 @@ public Streamable<String> getBasePackages() {
139
138
return Streamable .of (ClassUtils .getPackageName (className ));
140
139
}
141
140
142
- Set <String > packages = new HashSet <>();
141
+ Set <String > packages = new HashSet <>(value . length + basePackages . length + basePackageClasses . length );
143
142
packages .addAll (Arrays .asList (value ));
144
143
packages .addAll (Arrays .asList (basePackages ));
145
144
@@ -150,18 +149,22 @@ public Streamable<String> getBasePackages() {
150
149
return Streamable .of (packages );
151
150
}
152
151
152
+ @ Override
153
153
public Optional <Object > getQueryLookupStrategyKey () {
154
154
return Optional .ofNullable (attributes .get (QUERY_LOOKUP_STRATEGY ));
155
155
}
156
156
157
+ @ Override
157
158
public Optional <String > getNamedQueryLocation () {
158
159
return getNullDefaultedAttribute (NAMED_QUERIES_LOCATION );
159
160
}
160
161
162
+ @ Override
161
163
public Optional <String > getRepositoryImplementationPostfix () {
162
164
return getNullDefaultedAttribute (REPOSITORY_IMPLEMENTATION_POSTFIX );
163
165
}
164
166
167
+ @ Override
165
168
@ NonNull
166
169
public Object getSource () {
167
170
return configMetadata ;
@@ -265,25 +268,22 @@ public BootstrapMode getBootstrapMode() {
265
268
public String getResourceDescription () {
266
269
267
270
String simpleClassName = ClassUtils .getShortName (configMetadata .getClassName ());
268
- String annoationClassName = ClassUtils .getShortName (enableAnnotationMetadata .getClassName ());
271
+ String annotationClassName = ClassUtils .getShortName (enableAnnotationMetadata .getClassName ());
269
272
270
- return String .format ("@%s declared on %s" , annoationClassName , simpleClassName );
273
+ return String .format ("@%s declared on %s" , annotationClassName , simpleClassName );
271
274
}
272
275
273
276
private Streamable <TypeFilter > parseFilters (String attributeName ) {
274
277
275
278
AnnotationAttributes [] filters = attributes .getAnnotationArray (attributeName );
276
-
277
- return Streamable .of (() -> Arrays .stream (filters ) //
278
- .flatMap (it -> TypeFilterUtils .createTypeFiltersFor (it , this .environment , this .resourceLoader , this .registry )
279
- .stream ()));
279
+ return Streamable .of (() -> Arrays .stream (filters ).flatMap (typeFilterFunction ));
280
280
}
281
281
282
282
/**
283
283
* Returns the {@link String} attribute with the given name and defaults it to {@literal Optional#empty()} in case
284
284
* it's empty.
285
285
*
286
- * @param attributeName
286
+ * @param attributeName must not be {@literal null}.
287
287
* @return
288
288
*/
289
289
private Optional <String > getNullDefaultedAttribute (String attributeName ) {
0 commit comments