From 53a6895b32c3ab6c2710a09d8b9fd251cc98797e Mon Sep 17 00:00:00 2001 From: wenshao Date: Thu, 17 Jan 2013 22:07:12 +0800 Subject: [PATCH] remove clearParameter log error --- .../druid/pool/DruidPooledConnection.java | 10 ++-- .../druid/bvt/pool/ExceptionSorterTest.java | 49 +++++++++++++++++++ 2 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 src/test/java/com/alibaba/druid/bvt/pool/ExceptionSorterTest.java diff --git a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java index 94143ba5c3..a211164db8 100644 --- a/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java +++ b/src/main/java/com/alibaba/druid/pool/DruidPooledConnection.java @@ -73,7 +73,7 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql. public DruidPooledConnection(DruidConnectionHolder holder){ super(holder.getConnection()); - + this.conn = holder.getConnection(); this.holder = holder; dupCloseLogEnable = holder.getDataSource().isDupCloseLogEnable(); @@ -140,12 +140,16 @@ public class DruidPooledConnection extends PoolableWrapper implements javax.sql. if (holder == null) { return; } - + if (holder.isPoolPreparedStatements()) { try { rawStatement.clearParameters(); } catch (SQLException ex) { - LOG.error("clear parameter error", ex); + if (rawStatement.getConnection().isClosed()) { + return; + } + + LOG.warn("clear parameter error", ex); } } diff --git a/src/test/java/com/alibaba/druid/bvt/pool/ExceptionSorterTest.java b/src/test/java/com/alibaba/druid/bvt/pool/ExceptionSorterTest.java new file mode 100644 index 0000000000..552c35ff89 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/pool/ExceptionSorterTest.java @@ -0,0 +1,49 @@ +package com.alibaba.druid.bvt.pool; + +import java.sql.Connection; +import java.sql.PreparedStatement; + +import junit.framework.TestCase; + +import org.junit.Assert; + +import com.alibaba.druid.mock.MockConnection; +import com.alibaba.druid.pool.DruidDataSource; +import com.alibaba.druid.pool.vendor.MockExceptionSorter; + +public class ExceptionSorterTest extends TestCase { + + private DruidDataSource dataSource; + + protected void setUp() throws Exception { + dataSource = new DruidDataSource(); + dataSource.setUrl("jdbc:mock:xxx"); + dataSource.setTestOnBorrow(true); + dataSource.setDbType("mysql"); + dataSource.setPoolPreparedStatements(true); + + dataSource.init(); + } + + protected void tearDown() throws Exception { + dataSource.close(); + } + + public void test_exceptionSorter() throws Exception { + Assert.assertTrue(dataSource.getExceptionSorterClassName(), + dataSource.getExceptionSorter() instanceof MockExceptionSorter); + + Connection conn = dataSource.getConnection(); + MockConnection mockConn = conn.unwrap(MockConnection.class); + + PreparedStatement stmt = conn.prepareStatement("select 1"); + + stmt.execute(); + + mockConn.close(); + + stmt.close(); + + conn.close(); + } +}