jdbc 연결을 계측하려고합니다. 이 주제에 관해 몇 가지 비슷한 질문이 있다는 것을 알고 있습니다.
나는 모든 것을 시도했지만 지금까지 내 문제를 해결하기위한 견본을 찾지 못했습니다. 내가 톰캣 7 및 Java 7. 여기에 내가 내의 context.xml에서 오라클 연결 풀을 정의 어디 함께 일하고 있어요 Apache Commons DBCP connection object problem, Thread: ClassCastException in org.apache.tomcat.dbcp.dbcp.PoolingDataSource$PoolGuardConnectionWrapper
: 또한 어떠한 결과,이 질문에 대한 답변을 시도
<Resource name="jdbc/myDS"
type="javax.sql.DataSource"
auth="Container"
maxActive="350"
maxIdle="50"
minIdle="10"
maxWait="10000"
username="user_own"
password="mypassw"
accessToUnderlyingConnectionAllowed="true"
driverClassName="oracle.jdbc.driver.OracleDriver"
url="jdbc:oracle:thin:@192.168.110.173:1521/orcl" />
내 계측 코드 :
private static void initInstrumentation(Connection con, final String usuario, final String modulo, final String accion) throws Exception {
if (IncVariablesPlx.getParameter("instrumentation.active").equals("1")) {
try {
OracleConnection oracleConnection = null;
//This is where I try to get the oracle connection, but no succeed
if (con != null) {
if (con instanceof OracleConnection) {//NEVER COME IN HERE
oracleConnection = (OracleConnection) con;
} else if (con.isWrapperFor(OracleConnection.class)) {//NEVER COME IN HERE
oracleConnection = con.unwrap(OracleConnection.class);
} else{
//NO ORACLECONNECTION NO isWrapperFor -> ALWAYS ENDS HERE!!!
//oracleConnection = (OracleConnection) ((DelegatingConnection) con).getDelegate();
oracleConnection = (OracleConnection) new DelegatingConnection(con).getInnermostDelegate();
}
}
if (oracleConnection != null) {
String[] metrics = new String[OracleConnection.END_TO_END_STATE_INDEX_MAX];
metrics[OracleConnection.END_TO_END_MODULE_INDEX] = modulo;
metrics[OracleConnection.END_TO_END_ACTION_INDEX] = "Inicio: " + accion;
metrics[OracleConnection.END_TO_END_CLIENTID_INDEX] = usuario;
oracleConnection.setEndToEndMetrics(metrics, (short) 0);
}
} catch (Exception e) {
throw new Exception("Error initInstrumentation " + e);
}
}
}
내 열린 연결 방법 :
private static Connection genericOpenConnection() throws Exception {
Connection con = null;
try {
DataSource dataSource = (DataSource) new InitialContext().lookup(IncFuncionesPlx.cStrPlx(IncVariablesPlx.getParameter("dataSourceJndiName")));
con = dataSource.getConnection();
con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
} catch (Exception e) {
Error.escribeLog("Error : " + e.getMessage());
throw new SQLException(e.getMessage());
}
return con;
}
그래서 openConnection 및 initInstrumentation을 호출 한 후 Oracle 연결에 대한 연결을 캐스팅하려고 시도하는 다음 예외가 발생합니다. 이 작업을 수행하는 방법에 대한 아이디어가 있습니까? 나는 무엇이 잘못 되었는가? 미리 감사드립니다.
java.lang.ClassCastException가 : org.apache.tomcat.dbcp.dbcp.PoolingDataSource $ PoolGuardConnectionWrapper이 oracle.jdbc.OracleConnection
아래에 설명 된대로 연결이 현재 검색 한되고, 내가 읽은 모든 것을 해봤 포함 당신은 그것이 중복 된 것이라고 질문 ... – elcadro
'getInnermostDelegate'를 호출 해 보았습니까? –
네, 저도 시도해 봤습니다 ... – elcadro