添加ExceptionSorter

git-svn-id: http://code.alibabatech.com/svn/druid/trunk@309 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-06-29 09:14:51 +00:00
parent fc538c954a
commit cdabd396a4
4 changed files with 57 additions and 21 deletions
@@ -40,6 +40,7 @@ import javax.sql.StatementEventListener;
import com.alibaba.druid.pool.PoolablePreparedStatement.PreparedStatementKey;
import com.alibaba.druid.pool.PreparedStatementPool.MethodType;
import com.alibaba.druid.pool.vendor.ExceptionSorter;
/**
* @author wenshao<szujobs@hotmail.com>
@@ -54,12 +55,40 @@ public class PoolableConnection implements PooledConnection, Connection {
this.holder = holder;
}
protected SQLException checkException(Throwable t) throws SQLException {
//if (mc != null) mc.connectionError(t);
protected SQLException handleException(Throwable t) throws SQLException {
final ConnectionHolder holder = this.holder;
//
if (holder != null) {
DruidAbstractDataSource dataSource = holder.getDataSource();
if (dataSource != null) {
holder.getDataSource().handleException(t);
}
}
if (t instanceof SQLException) {
throw (SQLException) t;
} else {
SQLException sqlEx = (SQLException) t;
// broadcastConnectionError
ConnectionEvent event = new ConnectionEvent(this, sqlEx);
for (ConnectionEventListener eventListener : holder.getConnectionEventListeners()) {
eventListener.connectionErrorOccurred(event);
}
// exceptionSorter.isExceptionFatal
if (holder != null) {
DruidAbstractDataSource dataSource = holder.getDataSource();
if (dataSource != null) {
ExceptionSorter exceptionSorter = dataSource.getExceptionSoter();
if (exceptionSorter != null && exceptionSorter.isExceptionFatal(sqlEx)) {
this.holder = null; // isClosed() is true
}
}
}
throw sqlEx;
} else {
throw new SQLException("Error", t);
}
}