use of com.alibaba.druid.stat.JdbcStatContext in project druid by alibaba.
the class StatFilter method statement_close.
@Override
public void statement_close(FilterChain chain, StatementProxy statement) throws SQLException {
chain.statement_close(statement);
JdbcDataSourceStat dataSourceStat = chain.getDataSource().getDataSourceStat();
dataSourceStat.getStatementStat().incrementStatementCloseCounter();
JdbcStatContext context = JdbcStatManager.getInstance().getStatContext();
if (context != null) {
context.setName(null);
context.setFile(null);
context.setSql(null);
}
}
use of com.alibaba.druid.stat.JdbcStatContext in project druid by alibaba.
the class StatFilterTest2 method setStatSql.
public static final void setStatSql(String val) {
JdbcStatContext context = JdbcStatManager.getInstance().getStatContext();
if (context == null) {
context = JdbcStatManager.getInstance().createStatContext();
JdbcStatManager.getInstance().setStatContext(context);
}
context.setSql(val);
}
use of com.alibaba.druid.stat.JdbcStatContext in project druid by alibaba.
the class StatFilter method createSqlStat.
public JdbcSqlStat createSqlStat(StatementProxy statement, String sql) {
DataSourceProxy dataSource = statement.getConnectionProxy().getDirectDataSource();
JdbcDataSourceStat dataSourceStat = dataSource.getDataSourceStat();
JdbcStatContext context = JdbcStatManager.getInstance().getStatContext();
String contextSql = context != null ? context.getSql() : null;
if (contextSql != null && contextSql.length() > 0) {
return dataSourceStat.createSqlStat(contextSql);
} else {
DbType dbType = this.dbType;
if (dbType == null) {
dbType = DbType.of(dataSource.getDbType());
}
sql = mergeSql(sql, dbType);
return dataSourceStat.createSqlStat(sql);
}
}
use of com.alibaba.druid.stat.JdbcStatContext in project druid by alibaba.
the class StatFilter method internalBeforeStatementExecute.
private final void internalBeforeStatementExecute(StatementProxy statement, String sql) {
JdbcDataSourceStat dataSourceStat = statement.getConnectionProxy().getDirectDataSource().getDataSourceStat();
dataSourceStat.getStatementStat().beforeExecute();
final ConnectionProxy connection = statement.getConnectionProxy();
final JdbcConnectionStat.Entry connectionCounter = getConnectionInfo(connection);
statement.setLastExecuteStartNano();
connectionCounter.setLastSql(sql);
if (connectionStackTraceEnable) {
connectionCounter.setLastStatementStatckTrace(new Exception());
}
// //////////SQL
JdbcSqlStat sqlStat = statement.getSqlStat();
if (sqlStat == null || sqlStat.isRemoved()) {
sqlStat = createSqlStat(statement, sql);
statement.setSqlStat(sqlStat);
}
JdbcStatContext statContext = JdbcStatManager.getInstance().getStatContext();
if (statContext != null) {
sqlStat.setName(statContext.getName());
sqlStat.setFile(statContext.getFile());
}
boolean inTransaction = false;
try {
inTransaction = !statement.getConnectionProxy().getAutoCommit();
} catch (SQLException e) {
LOG.error("getAutoCommit error", e);
}
if (sqlStat != null) {
sqlStat.setExecuteLastStartTime(System.currentTimeMillis());
sqlStat.incrementRunningCount();
if (inTransaction) {
sqlStat.incrementInTransactionCount();
}
}
StatFilterContext.getInstance().executeBefore(sql, inTransaction);
String mergedSql;
if (sqlStat != null) {
mergedSql = sqlStat.getSql();
} else {
mergedSql = sql;
}
Profiler.enter(mergedSql, Profiler.PROFILE_TYPE_SQL);
}
use of com.alibaba.druid.stat.JdbcStatContext in project druid by alibaba.
the class ConnectionTest3 method setUp.
protected void setUp() throws Exception {
DruidDataSourceStatManager.clear();
driver = new MockDriver();
dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriver(driver);
dataSource.setInitialSize(1);
dataSource.setMaxActive(2);
dataSource.setMaxIdle(2);
dataSource.setMinIdle(1);
// 300 / 10
dataSource.setMinEvictableIdleTimeMillis(300 * 1000);
// 180 / 10
dataSource.setTimeBetweenEvictionRunsMillis(180 * 1000);
dataSource.setTestWhileIdle(true);
dataSource.setTestOnBorrow(false);
dataSource.setValidationQuery("SELECT 1");
dataSource.setFilters("stat,trace");
JdbcStatContext context = new JdbcStatContext();
context.setTraceEnable(true);
JdbcStatManager.getInstance().setStatContext(context);
}
Aggregations