use of com.alibaba.druid.proxy.jdbc.ConnectionProxy in project druid by alibaba.
the class FilterEventAdapter method connection_connect.
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
connection_connectBefore(chain, info);
ConnectionProxy connection = super.connection_connect(chain, info);
connection_connectAfter(connection);
return connection;
}
use of com.alibaba.druid.proxy.jdbc.ConnectionProxy in project druid by alibaba.
the class StatFilter method statement_executeErrorAfter.
@Override
protected void statement_executeErrorAfter(StatementProxy statement, String sql, Throwable error) {
ConnectionProxy connection = statement.getConnectionProxy();
JdbcConnectionStat.Entry connectionCounter = getConnectionInfo(connection);
long nanos = System.nanoTime() - statement.getLastExecuteStartNano();
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
dataSourceStat.getStatementStat().error(error);
dataSourceStat.getStatementStat().afterExecute(nanos);
connectionCounter.error(error);
// SQL
JdbcSqlStat sqlStat = statement.getSqlStat();
if (sqlStat != null) {
sqlStat.decrementExecutingCount();
sqlStat.error(error);
sqlStat.addExecuteTime(statement.getLastExecuteType(), statement.isFirstResultSet(), nanos);
statement.setLastExecuteTimeNano(nanos);
}
StatFilterContext.getInstance().executeAfter(sql, nanos, error);
Profiler.release(nanos);
}
use of com.alibaba.druid.proxy.jdbc.ConnectionProxy in project druid by alibaba.
the class EncodingConvertFilter method connection_connect.
public ConnectionProxy connection_connect(FilterChain chain, Properties info) throws SQLException {
ConnectionProxy conn = chain.connection_connect(info);
CharsetParameter param = new CharsetParameter();
param.setClientEncoding(info.getProperty(CharsetParameter.CLIENTENCODINGKEY));
param.setServerEncoding(info.getProperty(CharsetParameter.SERVERENCODINGKEY));
if (param.getClientEncoding() == null || "".equalsIgnoreCase(param.getClientEncoding())) {
param.setClientEncoding(clientEncoding);
}
if (param.getServerEncoding() == null || "".equalsIgnoreCase(param.getServerEncoding())) {
param.setServerEncoding(serverEncoding);
}
conn.putAttribute(ATTR_CHARSET_PARAMETER, param);
conn.putAttribute(ATTR_CHARSET_CONVERTER, new CharsetConvert(param.getClientEncoding(), param.getServerEncoding()));
return conn;
}
use of com.alibaba.druid.proxy.jdbc.ConnectionProxy in project druid by alibaba.
the class MySqlValidConnectionChecker method isValidConnection.
public boolean isValidConnection(Connection conn, String validateQuery, int validationQueryTimeout) throws Exception {
if (conn.isClosed()) {
return false;
}
if (usePingMethod) {
if (conn instanceof DruidPooledConnection) {
conn = ((DruidPooledConnection) conn).getConnection();
}
if (conn instanceof ConnectionProxy) {
conn = ((ConnectionProxy) conn).getRawObject();
}
if (clazz.isAssignableFrom(conn.getClass())) {
if (validationQueryTimeout < 0) {
validationQueryTimeout = DEFAULT_VALIDATION_QUERY_TIMEOUT;
}
ping.invoke(conn, true, validationQueryTimeout * 1000);
return true;
}
}
String query = validateQuery;
if (validateQuery == null || validateQuery.isEmpty()) {
query = DEFAULT_VALIDATION_QUERY;
}
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
if (validationQueryTimeout > 0) {
stmt.setQueryTimeout(validationQueryTimeout);
}
rs = stmt.executeQuery(query);
return true;
} finally {
JdbcUtils.close(rs);
JdbcUtils.close(stmt);
}
}
use of com.alibaba.druid.proxy.jdbc.ConnectionProxy in project druid by alibaba.
the class PGValidConnectionChecker method isValidConnection.
public boolean isValidConnection(Connection conn, String validateQuery, int validationQueryTimeout) throws Exception {
if (validateQuery == null || validateQuery.isEmpty()) {
validateQuery = this.defaultValidateQuery;
}
if (conn.isClosed()) {
return false;
}
if (conn instanceof DruidPooledConnection) {
conn = ((DruidPooledConnection) conn).getConnection();
}
if (conn instanceof ConnectionProxy) {
conn = ((ConnectionProxy) conn).getRawObject();
}
int queryTimeout = validationQueryTimeout < 0 ? defaultQueryTimeout : validationQueryTimeout;
Statement stmt = null;
ResultSet rs = null;
try {
stmt = conn.createStatement();
stmt.setQueryTimeout(queryTimeout);
rs = stmt.executeQuery(validateQuery);
return true;
} finally {
JdbcUtils.close(rs);
JdbcUtils.close(stmt);
}
}
Aggregations