Skip to content

Commit

Permalink
optimize: automatically skipping proxy for datasource of type Abstrac…
Browse files Browse the repository at this point in the history
…tRoutingDataSource
  • Loading branch information
iAmClever committed Mar 6, 2025
1 parent f21d0c4 commit f8a43aa
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected boolean shouldSkip(Class<?> beanClass, String beanName) {
@Override
protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey) {
// we only care DataSource bean
if (!(bean instanceof DataSource)) {
if (!(bean instanceof DataSource) || isAbstractRoutingDataSource(bean)) {
return bean;
}

Expand Down Expand Up @@ -108,6 +108,22 @@ protected Object wrapIfNecessary(Object bean, String beanName, Object cacheKey)
return originEnhancer;
}

/**
* Checks if the given bean is an instance of AbstractRoutingDataSource.
*
* @param bean the object to check
* @return true if the bean is an instance of AbstractRoutingDataSource, false otherwise
*/
private boolean isAbstractRoutingDataSource(Object bean) {
try {
Class<?> clazz = Class.forName("org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource");
return clazz.isAssignableFrom(bean.getClass());
} catch (ClassNotFoundException e) {
// AbstractRoutingDataSource not found
return false;
}
}

SeataDataSourceProxy buildProxy(DataSource origin, String proxyMode) {
if (BranchType.AT.name().equalsIgnoreCase(proxyMode)) {
return new DataSourceProxy(origin);
Expand Down

0 comments on commit f8a43aa

Please sign in to comment.