com.dexcoder.dal.spring.datasource.DynamicDsInterceptor Maven / Gradle / Ivy
package com.dexcoder.dal.spring.datasource;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import com.dexcoder.commons.utils.StrUtils;
/**
* 动态数据源拦截器
*
* Created by liyd on 2015-11-2.
*/
@Aspect
public class DynamicDsInterceptor {
@Pointcut("execution(* org.springframework.jdbc.core.JdbcOperations.*(..))")
public void executeMethod() {
throw new UnsupportedOperationException("不支持的方法");
}
@Around("executeMethod()")
public Object methodAspect(ProceedingJoinPoint pjp) throws Throwable {
String methodName = pjp.getSignature().getName();
if (StrUtils.startsWith(methodName, "query")) {
DynamicDataSourceHolder.setIsWrite(false);
} else {
DynamicDataSourceHolder.setIsWrite(true);
}
return pjp.proceed();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy