提交 3120065b authored 作者: Thomas Mueller's avatar Thomas Mueller

Issue 573: Add implementation for Methods "isWrapperFor()" and "unwrap()" in other JDBC classes.

上级 7ad78c92
......@@ -39,6 +39,7 @@ public class TestMetaData extends TestBase {
@Override
public void test() throws SQLException {
deleteDb("metaData");
testUnwrap();
testUnsupportedOperations();
testTempTable();
testColumnResultSetMeta();
......@@ -56,16 +57,29 @@ public class TestMetaData extends TestBase {
testSessionsUncommitted();
testQueryStatistics();
}
private void testUnwrap() throws SQLException {
Connection conn = getConnection("metaData");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select 1 as x from dual");
ResultSetMetaData meta = rs.getMetaData();
assertTrue(meta.isWrapperFor(Object.class));
assertTrue(meta.isWrapperFor(ResultSetMetaData.class));
assertTrue(meta.isWrapperFor(meta.getClass()));
assertTrue(meta == meta.unwrap(Object.class));
assertTrue(meta == meta.unwrap(ResultSetMetaData.class));
assertTrue(meta == meta.unwrap(meta.getClass()));
assertFalse(meta.isWrapperFor(Integer.class));
assertThrows(ErrorCode.INVALID_VALUE_2, meta).
unwrap(Integer.class);
conn.close();
}
private void testUnsupportedOperations() throws SQLException {
Connection conn = getConnection("metaData");
Statement stat = conn.createStatement();
ResultSet rs = stat.executeQuery("select 1 as x from dual");
ResultSetMetaData meta = rs.getMetaData();
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, meta).
isWrapperFor(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, meta).
unwrap(Object.class);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getColumnLabel(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getColumnName(0);
assertThrows(ErrorCode.INVALID_VALUE_2, meta).getColumnType(0);
......@@ -971,6 +985,7 @@ public class TestMetaData extends TestBase {
private void testGeneral() throws SQLException {
Connection conn = getConnection("metaData");
DatabaseMetaData meta = conn.getMetaData();
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))");
......
......@@ -56,6 +56,7 @@ public class TestPreparedStatement extends TestBase {
public void test() throws Exception {
deleteDb("preparedStatement");
Connection conn = getConnection("preparedStatement");
testUnwrap(conn);
testUnsupportedOperations(conn);
testChangeType(conn);
testDateTimeTimestampWithCalendar(conn);
......@@ -95,6 +96,17 @@ public class TestPreparedStatement extends TestBase {
testPreparedStatementWithLiteralsNone();
deleteDb("preparedStatement");
}
private void testUnwrap(Connection conn) throws SQLException {
assertTrue(conn.isWrapperFor(Object.class));
assertTrue(conn.isWrapperFor(Connection.class));
assertTrue(conn.isWrapperFor(conn.getClass()));
assertFalse(conn.isWrapperFor(String.class));
assertTrue(conn == conn.unwrap(Object.class));
assertTrue(conn == conn.unwrap(Connection.class));
assertThrows(ErrorCode.INVALID_VALUE_2, conn).
unwrap(String.class);
}
@SuppressWarnings("deprecation")
private void testUnsupportedOperations(Connection conn) throws Exception {
......@@ -134,17 +146,6 @@ public class TestPreparedStatement extends TestBase {
ParameterMetaData meta = prep.getParameterMetaData();
assertTrue(meta.toString(), meta.toString().endsWith("parameterCount=1"));
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, meta).
isWrapperFor(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, meta).
unwrap(Object.class);
assertTrue(conn.isWrapperFor(Object.class));
assertTrue(conn.isWrapperFor(Connection.class));
assertFalse(conn.isWrapperFor(String.class));
assertTrue(conn == conn.unwrap(Object.class));
assertTrue(conn == conn.unwrap(Connection.class));
assertThrows(ErrorCode.INVALID_VALUE_2, conn).unwrap(String.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, conn).
createSQLXML();
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, conn).
......
......@@ -63,6 +63,7 @@ public class TestResultSet extends TestBase {
stat = conn.createStatement();
testUnwrap();
testReuseSimpleResult();
testUnsupportedOperations();
testAmbiguousColumnNames();
......@@ -101,6 +102,19 @@ public class TestResultSet extends TestBase {
deleteDb("resultSet");
}
private void testUnwrap() throws SQLException {
ResultSet rs = stat.executeQuery("select 1");
assertTrue(rs.isWrapperFor(Object.class));
assertTrue(rs.isWrapperFor(ResultSet.class));
assertTrue(rs.isWrapperFor(rs.getClass()));
assertFalse(rs.isWrapperFor(Integer.class));
assertTrue(rs == rs.unwrap(Object.class));
assertTrue(rs == rs.unwrap(ResultSet.class));
assertTrue(rs == rs.unwrap(rs.getClass()));
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
unwrap(Object.class);
}
private void testReuseSimpleResult() throws SQLException {
ResultSet rs = stat.executeQuery("select table(x array=((1)))");
......@@ -166,10 +180,6 @@ public class TestResultSet extends TestBase {
getCursorName();
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
setFetchDirection(ResultSet.FETCH_FORWARD);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
unwrap(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, rs).
isWrapperFor(Object.class);
}
private void testAmbiguousColumnNames() throws SQLException {
......
......@@ -6,6 +6,7 @@
package org.h2.test.jdbc;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLClientInfoException;
import java.sql.SQLException;
......@@ -41,6 +42,7 @@ public class TestStatement extends TestBase {
public void test() throws Exception {
deleteDb("statement");
conn = getConnection("statement");
testUnwrap();
testUnsupportedOperations();
testTraceError();
testSavepoint();
......@@ -51,14 +53,22 @@ public class TestStatement extends TestBase {
conn.close();
deleteDb("statement");
}
private void testUnsupportedOperations() throws Exception {
private void testUnwrap() throws SQLException {
Statement stat = conn.createStatement();
assertTrue(stat.isWrapperFor(Object.class));
assertTrue(stat.isWrapperFor(DatabaseMetaData.class));
assertTrue(stat.isWrapperFor(stat.getClass()));
assertTrue(stat == stat.unwrap(Object.class));
assertTrue(stat == stat.unwrap(DatabaseMetaData.class));
assertTrue(stat == stat.unwrap(stat.getClass()));
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, stat).
isWrapperFor(Object.class);
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, stat).
unwrap(Object.class);
}
private void testUnsupportedOperations() throws Exception {
conn.setTypeMap(null);
HashMap<String, Class<?>> map = New.hashMap();
conn.setTypeMap(map);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论