git-svn-id: http://code.alibabatech.com/svn/druid/trunk@765 b9813039-fb51-4c41-a8b9-e21c2acb5095
This commit is contained in:
wenshao
2011-09-15 08:41:49 +00:00
parent 6bf7200408
commit d2113eb906
2 changed files with 104 additions and 45 deletions
@@ -487,192 +487,193 @@ public class MockResultSet implements ResultSet {
@Override
public void updateNull(int columnIndex) throws SQLException {
updateObject(columnIndex, null);
}
@Override
public void updateBoolean(int columnIndex, boolean x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateByte(int columnIndex, byte x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateShort(int columnIndex, short x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateInt(int columnIndex, int x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateLong(int columnIndex, long x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateFloat(int columnIndex, float x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateDouble(int columnIndex, double x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateString(int columnIndex, String x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateBytes(int columnIndex, byte[] x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateDate(int columnIndex, Date x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateTime(int columnIndex, Time x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException {
updateObject(columnIndex, x);
}
@Override
public void updateObject(int columnIndex, Object x) throws SQLException {
Object[] row = rows.get(rowIndex);
row[columnIndex - 1] = x;
}
@Override
public void updateNull(String columnLabel) throws SQLException {
updateObject(columnLabel, null);
}
@Override
public void updateBoolean(String columnLabel, boolean x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateByte(String columnLabel, byte x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateShort(String columnLabel, short x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateInt(String columnLabel, int x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateLong(String columnLabel, long x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateFloat(String columnLabel, float x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateDouble(String columnLabel, double x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateString(String columnLabel, String x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateBytes(String columnLabel, byte[] x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateDate(String columnLabel, Date x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateTime(String columnLabel, Time x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException {
updateObject(columnLabel, reader);
}
@Override
public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException {
updateObject(columnLabel, x);
}
@Override
public void updateObject(String columnLabel, Object x) throws SQLException {
updateObject(Integer.parseInt(columnLabel), x);
}
@Override
@@ -1,5 +1,6 @@
package com.alibaba.druid.bvt.pool;
package com.alibaba.druid.bvt.pool.basic;
import java.math.BigDecimal;
import java.sql.SQLException;
import junit.framework.TestCase;
@@ -10,11 +11,14 @@ import com.alibaba.druid.mock.MockResultSet;
import com.alibaba.druid.pool.PoolableResultSet;
import com.alibaba.druid.pool.PoolableStatement;
public class PoolableResultSetTest extends TestCase {
public class ResultSetTest extends TestCase {
@SuppressWarnings("deprecation")
public void test_0() throws Exception {
PoolableStatement stmt = new PoolableStatement(null, null) {
private PoolableStatement stmt;
private MockResultSet raw;
private PoolableResultSet resultSet;
protected void setUp() throws Exception {
stmt = new PoolableStatement(null, null) {
protected SQLException checkException(Throwable error) throws SQLException {
if (error instanceof SQLException) {
@@ -25,9 +29,13 @@ public class PoolableResultSetTest extends TestCase {
}
};
MockResultSet raw = new MockResultSet(null);
raw = new MockResultSet(null);
raw.getRows().add(new Object[] { null });
PoolableResultSet resultSet = new PoolableResultSet(stmt, raw);
resultSet = new PoolableResultSet(stmt, raw);
}
@SuppressWarnings("deprecation")
public void test_get() throws Exception {
Assert.assertTrue(stmt == resultSet.getPoolableStatement());
Assert.assertTrue(raw == resultSet.getRawResultSet());
@@ -71,6 +79,56 @@ public class PoolableResultSetTest extends TestCase {
resultSet.getUnicodeStream("1");
resultSet.getBinaryStream("1");
}
public void test_set() throws Exception {
long currentMillis = System.currentTimeMillis();
Assert.assertTrue(resultSet.next());
resultSet.updateNull(1);
Assert.assertNull(resultSet.getString(1));
resultSet.updateBoolean(1, true);
Assert.assertEquals(true, resultSet.getBoolean(1));
resultSet.updateByte(1, (byte) 12);
Assert.assertEquals(12, resultSet.getByte(1));
resultSet.updateShort(1, (short) 23);
Assert.assertEquals(23, resultSet.getShort(1));
resultSet.updateInt(1, 34);
Assert.assertEquals(34, resultSet.getInt(1));
resultSet.updateLong(1, 45);
Assert.assertEquals(45, resultSet.getLong(1));
resultSet.updateFloat(1, 1.0F);
Assert.assertEquals(true, 1.0F == resultSet.getFloat(1));
resultSet.updateDouble(1, 2.0D);
Assert.assertEquals(true, 2.0D == resultSet.getDouble(1));
resultSet.updateBigDecimal(1, new BigDecimal("33"));
Assert.assertEquals(new BigDecimal("33"), resultSet.getBigDecimal(1));
resultSet.updateString(1, "xxx");
Assert.assertEquals("xxx", resultSet.getString(1));
resultSet.updateBytes(1, new byte[0]);
Assert.assertEquals(0, resultSet.getBytes(1).length);
resultSet.updateDate(1, new java.sql.Date(currentMillis));
Assert.assertEquals(new java.sql.Date(currentMillis), resultSet.getDate(1));
resultSet.updateTime(1, new java.sql.Time(1000));
Assert.assertEquals(new java.sql.Time(1000), resultSet.getTime(1));
resultSet.updateTimestamp(1, new java.sql.Timestamp(currentMillis));
Assert.assertEquals(new java.sql.Timestamp(currentMillis), resultSet.getTimestamp(1));
}
public void test_get_error() throws Exception {
{
SQLException error = null;
try {