package com.skyline.energy.interceptor;
import java.lang.reflect.Method;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;
import com.skyline.energy.cache.CacheManager;
import com.skyline.energy.dataaccess.jdbc.JdbcDataAccessor;
import com.skyline.energy.executor.DataAccessExecutor;
import com.skyline.energy.executor.ExecutorFactory;
public class DataAccessInterceptor implements MethodInterceptor {
private final CacheManager cacheManager;
private final JdbcDataAccessor dataAccessor;
public DataAccessInterceptor(CacheManager cacheManager, JdbcDataAccessor dataAccessor) {
this.cacheManager = cacheManager;
this.dataAccessor = dataAccessor;
}
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
DataAccessExecutor executor = ExecutorFactory.getExecutor(cacheManager, dataAccessor, method);
if (executor != null) {
return executor.execute(obj, args);
}
return null;
}
}