mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
bug fixed for getHoldable UnsupoortedOperationException
This commit is contained in:
@@ -60,6 +60,8 @@ public final class DruidConnectionHolder {
|
||||
private int underlyingTransactionIsolation;
|
||||
private boolean underlyingAutoCommit;
|
||||
private boolean discard = false;
|
||||
|
||||
public static boolean holdabilityUnsupported = false;
|
||||
|
||||
public DruidConnectionHolder(DruidAbstractDataSource dataSource, Connection conn) throws SQLException{
|
||||
|
||||
@@ -71,7 +73,7 @@ public final class DruidConnectionHolder {
|
||||
this.underlyingAutoCommit = conn.getAutoCommit();
|
||||
|
||||
{
|
||||
boolean initUnderlyHoldability = true;
|
||||
boolean initUnderlyHoldability = !holdabilityUnsupported;
|
||||
if (JdbcConstants.SYBASE.equals(dataSource.getDbType()) //
|
||||
|| JdbcConstants.DB2.equals(dataSource.getDbType()) //
|
||||
) {
|
||||
@@ -80,6 +82,9 @@ public final class DruidConnectionHolder {
|
||||
if (initUnderlyHoldability) {
|
||||
try {
|
||||
this.underlyingHoldability = conn.getHoldability();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
holdabilityUnsupported = true;
|
||||
LOG.warn("getHoldability unsupported", e);
|
||||
} catch (SQLException e) {
|
||||
LOG.warn("getHoldability error", e);
|
||||
}
|
||||
@@ -90,10 +95,8 @@ public final class DruidConnectionHolder {
|
||||
try {
|
||||
this.underlyingTransactionIsolation = conn.getTransactionIsolation();
|
||||
} catch (SQLException e) {
|
||||
if (!"com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException".equals(e.getClass().getName())) { // compatible
|
||||
// for
|
||||
// alibaba
|
||||
// corba
|
||||
// compartible for alibaba corba
|
||||
if (!"com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException".equals(e.getClass().getName())) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.alibaba.druid.bvt.pool;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import com.alibaba.druid.filter.Filter;
|
||||
import com.alibaba.druid.filter.FilterAdapter;
|
||||
import com.alibaba.druid.filter.FilterChain;
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.proxy.jdbc.ConnectionProxy;
|
||||
|
||||
|
||||
public class HoldableUnsupportTest extends TestCase {
|
||||
private DruidDataSource dataSource;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
dataSource = new DruidDataSource();
|
||||
dataSource.setUrl("jdbc:mock:xxx");
|
||||
Filter filter = new FilterAdapter() {
|
||||
@Override
|
||||
public int connection_getHoldability(FilterChain chain, ConnectionProxy connection) throws SQLException {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
};
|
||||
dataSource.getProxyFilters().add(filter);
|
||||
|
||||
}
|
||||
|
||||
protected void tearDown() throws Exception {
|
||||
dataSource.close();
|
||||
}
|
||||
|
||||
public void test_0 () throws Exception {
|
||||
Connection[] connections = new Connection[8];
|
||||
for (int i = 0; i < connections.length; ++i) {
|
||||
connections[i] = dataSource.getConnection();
|
||||
}
|
||||
|
||||
for (int i = 0; i < connections.length; ++i) {
|
||||
connections[i].close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user