我试图拦截对 getConnection() 方法的任何调用来设置 dbms 标识符。我已经实现了一个方面来获取它,但我什么也没得到。任何想法?谢谢!
import java.sql.CallableStatement;
import java.sql.Connection;
import javax.servlet.http.HttpSession;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import es.iberia.tryp.model.entities.Usuario;
@Component
@Aspect
public class ConnectionAspect {
@AfterReturning(value = "execution(java.sql.Connection javax.sql.DataSource+.getConnection(..))", returning = "connection")
//@AfterReturning(value = "execution(java.sql.Connection org.springframework.jdbc.datasource.*.*(*))", returning = "connection")
//@AfterReturning(value = "execution(java.sql.Connection java.sql.Connection *(..))", returning = "connection")
//@AfterReturning(value = "execution(java.sql.Connection org.springframework.jdbc.datasource.DriverManagerDataSource.*(..))", returning = "connection")
public void prepare (Connection connection) throws Throwable {
HttpSession httpSession = (HttpSession) RequestContextHolder.currentRequestAttributes().resolveReference(RequestAttributes.REFERENCE_SESSION);
if (httpSession!=null && (Usuario)httpSession.getAttribute("usuario")!=null && ((String)((Usuario)httpSession.getAttribute("usuario")).getNomina())!=null) {
String nomina = (String)((Usuario)httpSession.getAttribute("usuario")).getNomina();
String prepSql = "{ call DBMS_SESSION.SET_IDENTIFIER('" + nomina +"') }";
CallableStatement cs = connection.prepareCall(prepSql);
cs.execute();
cs.close();
}
}
}
检查您的 xml 文件中是否添加了以下标记。
aop:aspectj-autoproxy
另请检查您是否已在该 ConnectionAspect 类的 xml 中添加了 bean 定义。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)