mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
support transactionQueryTimeout
This commit is contained in:
@@ -132,6 +132,7 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
protected Driver driver;
|
||||
|
||||
protected int queryTimeout;
|
||||
protected int transactionQueryTimeout;
|
||||
|
||||
protected long createErrorCount;
|
||||
|
||||
@@ -201,6 +202,18 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
|
||||
private final AtomicLong executeCount = new AtomicLong();
|
||||
|
||||
public int getTransactionQueryTimeout() {
|
||||
if (transactionQueryTimeout <= 0) {
|
||||
return queryTimeout;
|
||||
}
|
||||
|
||||
return transactionQueryTimeout;
|
||||
}
|
||||
|
||||
public void setTransactionQueryTimeout(int transactionQueryTimeout) {
|
||||
this.transactionQueryTimeout = transactionQueryTimeout;
|
||||
}
|
||||
|
||||
public long getExecuteCount() {
|
||||
return executeCount.get();
|
||||
}
|
||||
@@ -1029,7 +1042,11 @@ public abstract class DruidAbstractDataSource extends WrapperAdapter implements
|
||||
return transactionIdSeed.getAndIncrement();
|
||||
}
|
||||
|
||||
void initStatement(Statement stmt) throws SQLException {
|
||||
void initStatement(PoolableConnection conn, Statement stmt) throws SQLException {
|
||||
boolean transaction = !conn.getConnectionHolder().isUnderlyingAutoCommit();
|
||||
|
||||
int queryTimeout = transaction ? getTransactionQueryTimeout() : getQueryTimeout();
|
||||
|
||||
if (queryTimeout > 0) {
|
||||
stmt.setQueryTimeout(queryTimeout);
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ public interface DruidAbstractDataSourceMBean {
|
||||
long getStartTransactionCount();
|
||||
|
||||
int getQueryTimeout();
|
||||
|
||||
int getTransactionQueryTimeout();
|
||||
|
||||
String getValidationQuery();
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -227,7 +227,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -266,7 +266,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -300,7 +300,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -334,7 +334,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -368,7 +368,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolablePreparedStatement rtnVal = new PoolablePreparedStatement(this, stmtHolder);
|
||||
|
||||
@@ -405,7 +405,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolableCallableStatement rtnVal = new PoolableCallableStatement(this, stmtHolder);
|
||||
|
||||
@@ -443,7 +443,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolableCallableStatement rtnVal = new PoolableCallableStatement(this, stmtHolder);
|
||||
|
||||
@@ -479,7 +479,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
holder.getDataSource().incrementReusePreparedStatementCount();
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmtHolder.getStatement());
|
||||
holder.getDataSource().initStatement(this, stmtHolder.getStatement());
|
||||
|
||||
PoolableCallableStatement rtnVal = new PoolableCallableStatement(this, stmtHolder);
|
||||
holder.addTrace(rtnVal);
|
||||
@@ -500,7 +500,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
handleException(ex);
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmt);
|
||||
holder.getDataSource().initStatement(this, stmt);
|
||||
|
||||
PoolableStatement poolableStatement = new PoolableStatement(this, stmt);
|
||||
holder.addTrace(poolableStatement);
|
||||
@@ -520,7 +520,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
handleException(ex);
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmt);
|
||||
holder.getDataSource().initStatement(this, stmt);
|
||||
|
||||
PoolableStatement poolableStatement = new PoolableStatement(this, stmt);
|
||||
holder.addTrace(poolableStatement);
|
||||
@@ -539,7 +539,7 @@ public class PoolableConnection implements PooledConnection, Connection {
|
||||
handleException(ex);
|
||||
}
|
||||
|
||||
holder.getDataSource().initStatement(stmt);
|
||||
holder.getDataSource().initStatement(this, stmt);
|
||||
|
||||
PoolableStatement poolableStatement = new PoolableStatement(this, stmt);
|
||||
holder.addTrace(poolableStatement);
|
||||
|
||||
Reference in New Issue
Block a user