File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
spring-data-jdbc-ydb/src/main/java/tech/ydb/data/repository/config Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ package tech .ydb .data .repository .config ;
2+
3+ import org .springframework .beans .BeansException ;
4+ import org .springframework .beans .factory .config .BeanPostProcessor ;
5+ import org .springframework .core .annotation .AnnotationUtils ;
6+ import org .springframework .data .jdbc .repository .support .JdbcRepositoryFactoryBean ;
7+ import org .springframework .data .repository .core .support .RepositoryFactoryBeanSupport ;
8+ import org .springframework .stereotype .Component ;
9+
10+ import tech .ydb .data .repository .ViewIndex ;
11+
12+ /**
13+ * Enabling the exposure of the metadata for the {@link JdbcRepositoryFactoryBean}. Enables
14+ * only for those {@link RepositoryFactoryBeanSupport factory beans} that have any {@link ViewIndex}
15+ * annotated methods.
16+ *
17+ * @author Mikhail Polivakha
18+ */
19+ @ Component
20+ @ SuppressWarnings ("rawtypes" )
21+ public class JdbcRepositoryBeanPostProcessor implements BeanPostProcessor {
22+
23+ @ Override
24+ public Object postProcessBeforeInitialization (Object bean , String beanName ) throws BeansException {
25+ if (bean instanceof JdbcRepositoryFactoryBean rfbs && hasAnyViewIndexMethods (rfbs )) {
26+ rfbs .setExposeMetadata (true );
27+ }
28+ return bean ;
29+ }
30+
31+ private static boolean hasAnyViewIndexMethods (JdbcRepositoryFactoryBean rfbs ) {
32+ return rfbs .getRepositoryInformation ()
33+ .getQueryMethods ()
34+ .stream ()
35+ .anyMatch (method -> AnnotationUtils .getAnnotation (method , ViewIndex .class ) != null );
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments