- java.sql.Connection? factory, -. - , / , createStatement() .
public class ProxyConnection implements Connection {
private Connection realConnection;
public ProxyConnection(Connection realConnection) {
this.realConnection = realConnection;
}
public Statement createStatement() throws SQLException {
createCounter.incrementAndGet();
logger.info("call to createStatment", new Exception("createStatement"));
if (throwOnBadCall) {
throw new SQLException("calls to createStatement aren't allowed"));
}
return realConnection.createStatement();
}
, volatile boolean logBadCall, . , , 80% - , , .
If you do not have a centralized location for the connection, then you may have to put the connection pool or factory in the chain a little.
Hope this helps.
source
share