代码重构

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@515 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-07-25 13:35:12 +00:00
parent f612aa1a7b
commit d841ed010d
3 changed files with 11 additions and 18 deletions
@@ -261,7 +261,8 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
LOG.debug("skip not validate connection.");
}
poolalbeConnection.close(false);
Connection realConnection = poolalbeConnection.getConnection();
JdbcUtils.close(realConnection);
continue;
}
} else {
@@ -272,6 +273,11 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
}
}
if (isRemoveAbandoned()) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
activeConnections.put(poolalbeConnection, new ActiveConnectionTraceInfo(poolalbeConnection, System.currentTimeMillis(), stackTrace));
}
return poolalbeConnection;
}
}
@@ -311,11 +317,6 @@ public class DruidDataSource extends DruidAbstractDataSource implements DruidDat
activeCount++;
poolalbeConnection = new PoolableConnection(holder);
if (isRemoveAbandoned()) {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
activeConnections.put(poolalbeConnection, new ActiveConnectionTraceInfo(poolalbeConnection, System.currentTimeMillis(), stackTrace));
}
} catch (InterruptedException e) {
connectErrorCount++;
throw new SQLException(e.getMessage(), e);
@@ -43,7 +43,6 @@ import com.alibaba.druid.logging.Log;
import com.alibaba.druid.logging.LogFactory;
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
import com.alibaba.druid.util.JdbcUtils;
/**
* @author wenshao<szujobs@hotmail.com>
@@ -124,10 +123,6 @@ public class PoolableConnection implements PooledConnection, Connection {
@Override
public void close() throws SQLException {
close(true);
}
public void close(boolean recyle) throws SQLException {
if (holder == null) {
LOG.warn("dup close");
return;
@@ -152,11 +147,8 @@ public class PoolableConnection implements PooledConnection, Connection {
}
holder.reset();
if (recyle) {
holder.getDataSource().recycle(this);
} else {
JdbcUtils.close(holder.getConnection());
}
holder.getDataSource().recycle(this);
holder = null;
conn = null;
}
@@ -17,8 +17,8 @@ public class TestIdle extends TestCase {
public void test_idle() throws Exception {
MockDriver driver = MockDriver.instance;
// BasicDataSource dataSource = new BasicDataSource();
DruidDataSource dataSource = new DruidDataSource();
BasicDataSource dataSource = new BasicDataSource();
// DruidDataSource dataSource = new DruidDataSource();
dataSource.setUrl("jdbc:mock:xxx");
dataSource.setDriverClassName("com.alibaba.druid.mock.MockDriver");
dataSource.setInitialSize(1);