From 8549dd07544325d3a80cc63dffa740adc88da1f4 Mon Sep 17 00:00:00 2001 From: wenshao Date: Fri, 16 Sep 2011 00:39:49 +0000 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84mock=E5=92=8C=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.alibabatech.com/svn/druid/trunk@786 b9813039-fb51-4c41-a8b9-e21c2acb5095 --- .../com/alibaba/druid/mock/MockResultSet.java | 45 ++++-- .../alibaba/druid/pool/PoolableResultSet.java | 8 +- .../druid/bvt/pool/basic/ResultSetTest.java | 26 ++++ .../druid/bvt/pool/basic/ResultSetTest2.java | 132 ++++++++++++++++-- 4 files changed, 178 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/alibaba/druid/mock/MockResultSet.java b/src/main/java/com/alibaba/druid/mock/MockResultSet.java index e696901a00..c78ca4af28 100644 --- a/src/main/java/com/alibaba/druid/mock/MockResultSet.java +++ b/src/main/java/com/alibaba/druid/mock/MockResultSet.java @@ -739,41 +739,58 @@ public class MockResultSet implements ResultSet { @Override public void insertRow() throws SQLException { - + if (closed) { + throw new SQLException("resultSet closed"); + } } @Override public void updateRow() throws SQLException { - + if (closed) { + throw new SQLException("resultSet closed"); + } } @Override public void deleteRow() throws SQLException { - + if (closed) { + throw new SQLException("resultSet closed"); + } } @Override public void refreshRow() throws SQLException { - + if (closed) { + throw new SQLException("resultSet closed"); + } } @Override public void cancelRowUpdates() throws SQLException { - + if (closed) { + throw new SQLException("resultSet closed"); + } } @Override public void moveToInsertRow() throws SQLException { - + if (closed) { + throw new SQLException("resultSet closed"); + } } @Override public void moveToCurrentRow() throws SQLException { - + if (closed) { + throw new SQLException("resultSet closed"); + } } @Override public Statement getStatement() throws SQLException { + if (closed) { + throw new SQLException("resultSet closed"); + } return statement; } @@ -909,14 +926,12 @@ public class MockResultSet implements ResultSet { @Override public RowId getRowId(int columnIndex) throws SQLException { - - return null; + return (RowId) getObject(columnIndex); } @Override public RowId getRowId(String columnLabel) throws SQLException { - - return null; + return (RowId) getObject(columnLabel); } @Override @@ -931,14 +946,16 @@ public class MockResultSet implements ResultSet { @Override public int getHoldability() throws SQLException { - + if (closed) { + throw new SQLException("resultSet closed"); + } + return 0; } @Override public boolean isClosed() throws SQLException { - - return false; + return closed; } @Override diff --git a/src/main/java/com/alibaba/druid/pool/PoolableResultSet.java b/src/main/java/com/alibaba/druid/pool/PoolableResultSet.java index 92cdbea9fd..8321770f24 100644 --- a/src/main/java/com/alibaba/druid/pool/PoolableResultSet.java +++ b/src/main/java/com/alibaba/druid/pool/PoolableResultSet.java @@ -1073,12 +1073,8 @@ public final class PoolableResultSet extends PoolableWrapper implements ResultSe } @Override - public Statement getStatement() throws SQLException { - try { - return stmt; - } catch (Throwable t) { - throw checkException(t); - } + public Statement getStatement() { + return stmt; } @Override diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest.java index 0eff073967..672365f02f 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest.java @@ -1467,6 +1467,32 @@ public class ResultSetTest extends TestCase { Assert.assertNotNull(error); } } + public void test_getRowId() throws Exception { + resultSet.next(); + + resultSet.getRowId(1); + resultSet.getRowId("1"); + + { + SQLException error = null; + try { + resultSet.getRowId(0); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + + { + SQLException error = null; + try { + resultSet.getRowId("0"); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } public void test_getTimestamp() throws Exception { resultSet.next(); diff --git a/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest2.java b/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest2.java index 5e7c77fce9..ec361c22a8 100644 --- a/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest2.java +++ b/src/test/java/com/alibaba/druid/bvt/pool/basic/ResultSetTest2.java @@ -10,8 +10,8 @@ import com.alibaba.druid.mock.MockResultSet; import com.alibaba.druid.pool.PoolableResultSet; import com.alibaba.druid.pool.PoolableStatement; - public class ResultSetTest2 extends TestCase { + private PoolableStatement stmt; private MockResultSet raw; private PoolableResultSet resultSet; @@ -32,11 +32,11 @@ public class ResultSetTest2 extends TestCase { raw.getRows().add(new Object[] { null }); resultSet = new PoolableResultSet(stmt, raw); } - + public void test_rowDeleted() throws Exception { resultSet.rowDeleted(); raw.close(); - + { SQLException error = null; try { @@ -47,11 +47,11 @@ public class ResultSetTest2 extends TestCase { Assert.assertNotNull(error); } } - + public void test_rowInserted() throws Exception { resultSet.rowInserted(); raw.close(); - + { SQLException error = null; try { @@ -62,11 +62,11 @@ public class ResultSetTest2 extends TestCase { Assert.assertNotNull(error); } } - + public void test_rowUpdated() throws Exception { resultSet.rowInserted(); raw.close(); - + { SQLException error = null; try { @@ -77,11 +77,11 @@ public class ResultSetTest2 extends TestCase { Assert.assertNotNull(error); } } - + public void test_getConcurrency() throws Exception { resultSet.getConcurrency(); raw.close(); - + { SQLException error = null; try { @@ -92,11 +92,11 @@ public class ResultSetTest2 extends TestCase { Assert.assertNotNull(error); } } - + public void test_getType() throws Exception { resultSet.getType(); raw.close(); - + { SQLException error = null; try { @@ -107,12 +107,12 @@ public class ResultSetTest2 extends TestCase { Assert.assertNotNull(error); } } - + public void test_FetchSize() throws Exception { resultSet.setFetchSize(10); Assert.assertEquals(10, resultSet.getFetchSize()); raw.close(); - + { SQLException error = null; try { @@ -122,6 +122,112 @@ public class ResultSetTest2 extends TestCase { } Assert.assertNotNull(error); } + { + SQLException error = null; + try { + resultSet.setFetchSize(10); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getHoldability() throws Exception { + resultSet.getHoldability(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.getHoldability(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_getStatement() throws Exception { + resultSet.getStatement(); + + raw.close(); + + { + SQLException error = null; + try { + raw.getStatement(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } } + public void test_moveToCurrentRow() throws Exception { + resultSet.moveToCurrentRow(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.moveToCurrentRow(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_moveToInsertRow() throws Exception { + resultSet.moveToInsertRow(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.moveToInsertRow(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_cancelRowUpdates() throws Exception { + resultSet.cancelRowUpdates(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.cancelRowUpdates(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + public void test_refreshRow() throws Exception { + resultSet.refreshRow(); + + raw.close(); + + { + SQLException error = null; + try { + resultSet.refreshRow(); + } catch (SQLException ex) { + error = ex; + } + Assert.assertNotNull(error); + } + } + + }