Skip to content

Commit 53f3ec0

Browse files
committed
Added Reposiotories post processor
1 parent a6fb459 commit 53f3ec0

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

0 commit comments

Comments
 (0)