Java Code Examples for java.sql.ResultSetMetaData#unwrap()

The following examples show how to use java.sql.ResultSetMetaData#unwrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RowSetMetaDataTests.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test99() throws Exception {
    RowSetMetaData rsmd1 = rsmd;
    ResultSetMetaData rsmd2 = rsmd;
    Class clzz = rsmd.getClass();
    assertTrue(rsmd1.isWrapperFor(clzz));
    assertTrue(rsmd2.isWrapperFor(clzz));
    RowSetMetaDataImpl rsmdi = (RowSetMetaDataImpl) rsmd2.unwrap(clzz);

    // False should be returned
    assertFalse(rsmd1.isWrapperFor(this.getClass()));
    assertFalse(rsmd2.isWrapperFor(this.getClass()));
}
 
Example 2
Source File: RowSetMetaDataTests.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test99() throws Exception {
    RowSetMetaData rsmd1 = rsmd;
    ResultSetMetaData rsmd2 = rsmd;
    Class clzz = rsmd.getClass();
    assertTrue(rsmd1.isWrapperFor(clzz));
    assertTrue(rsmd2.isWrapperFor(clzz));
    RowSetMetaDataImpl rsmdi = (RowSetMetaDataImpl) rsmd2.unwrap(clzz);

    // False should be returned
    assertFalse(rsmd1.isWrapperFor(this.getClass()));
    assertFalse(rsmd2.isWrapperFor(this.getClass()));
}
 
Example 3
Source File: RowSetMetaDataTests.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test99() throws Exception {
    RowSetMetaData rsmd1 = rsmd;
    ResultSetMetaData rsmd2 = rsmd;
    Class clzz = rsmd.getClass();
    assertTrue(rsmd1.isWrapperFor(clzz));
    assertTrue(rsmd2.isWrapperFor(clzz));
    RowSetMetaDataImpl rsmdi = (RowSetMetaDataImpl) rsmd2.unwrap(clzz);

    // False should be returned
    assertFalse(rsmd1.isWrapperFor(this.getClass()));
    assertFalse(rsmd2.isWrapperFor(this.getClass()));
}
 
Example 4
Source File: RowSetMetaDataTests.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test99() throws Exception {
    RowSetMetaData rsmd1 = rsmd;
    ResultSetMetaData rsmd2 = rsmd;
    Class clzz = rsmd.getClass();
    assertTrue(rsmd1.isWrapperFor(clzz));
    assertTrue(rsmd2.isWrapperFor(clzz));
    RowSetMetaDataImpl rsmdi = (RowSetMetaDataImpl) rsmd2.unwrap(clzz);

    // False should be returned
    assertFalse(rsmd1.isWrapperFor(this.getClass()));
    assertFalse(rsmd2.isWrapperFor(this.getClass()));
}
 
Example 5
Source File: RowSetMetaDataTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test99() throws Exception {
    RowSetMetaData rsmd1 = rsmd;
    ResultSetMetaData rsmd2 = rsmd;
    Class clzz = rsmd.getClass();
    assertTrue(rsmd1.isWrapperFor(clzz));
    assertTrue(rsmd2.isWrapperFor(clzz));
    RowSetMetaDataImpl rsmdi = (RowSetMetaDataImpl) rsmd2.unwrap(clzz);

    // False should be returned
    assertFalse(rsmd1.isWrapperFor(this.getClass()));
    assertFalse(rsmd2.isWrapperFor(this.getClass()));
}
 
Example 6
Source File: RowSetMetaDataTests.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test99() throws Exception {
    RowSetMetaData rsmd1 = rsmd;
    ResultSetMetaData rsmd2 = rsmd;
    Class clzz = rsmd.getClass();
    assertTrue(rsmd1.isWrapperFor(clzz));
    assertTrue(rsmd2.isWrapperFor(clzz));
    RowSetMetaDataImpl rsmdi = (RowSetMetaDataImpl) rsmd2.unwrap(clzz);

    // False should be returned
    assertFalse(rsmd1.isWrapperFor(this.getClass()));
    assertFalse(rsmd2.isWrapperFor(this.getClass()));
}
 
Example 7
Source File: RowSetMetaDataTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test99() throws Exception {
    RowSetMetaData rsmd1 = rsmd;
    ResultSetMetaData rsmd2 = rsmd;
    Class clzz = rsmd.getClass();
    assertTrue(rsmd1.isWrapperFor(clzz));
    assertTrue(rsmd2.isWrapperFor(clzz));
    RowSetMetaDataImpl rsmdi = (RowSetMetaDataImpl) rsmd2.unwrap(clzz);

    // False should be returned
    assertFalse(rsmd1.isWrapperFor(this.getClass()));
    assertFalse(rsmd2.isWrapperFor(this.getClass()));
}
 
Example 8
Source File: RowSetMetaDataTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test99() throws Exception {
    RowSetMetaData rsmd1 = rsmd;
    ResultSetMetaData rsmd2 = rsmd;
    Class clzz = rsmd.getClass();
    assertTrue(rsmd1.isWrapperFor(clzz));
    assertTrue(rsmd2.isWrapperFor(clzz));
    RowSetMetaDataImpl rsmdi = (RowSetMetaDataImpl) rsmd2.unwrap(clzz);

    // False should be returned
    assertFalse(rsmd1.isWrapperFor(this.getClass()));
    assertFalse(rsmd2.isWrapperFor(this.getClass()));
}
 
Example 9
Source File: RowSetMetaDataTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test99() throws Exception {
    RowSetMetaData rsmd1 = rsmd;
    ResultSetMetaData rsmd2 = rsmd;
    Class clzz = rsmd.getClass();
    assertTrue(rsmd1.isWrapperFor(clzz));
    assertTrue(rsmd2.isWrapperFor(clzz));
    RowSetMetaDataImpl rsmdi = (RowSetMetaDataImpl) rsmd2.unwrap(clzz);

    // False should be returned
    assertFalse(rsmd1.isWrapperFor(this.getClass()));
    assertFalse(rsmd2.isWrapperFor(this.getClass()));
}
 
Example 10
Source File: ResultSetAsyncIT.java    From snowflake-jdbc with Apache License 2.0 4 votes vote down vote up
@Test
public void testAsyncResultSetFunctionsWithNewSession() throws SQLException
{
  Connection connection = getConnection();
  final Map<String, String> params = getConnectionParameters();
  Statement statement = connection.createStatement();
  statement.execute("create or replace table test_rsmd(colA number(20, 5), colB string)");
  statement.execute("insert into test_rsmd values(1.00, 'str'),(2.00, 'str2')");
  String createTableSql = "select * from test_rsmd";
  ResultSet
      rs = statement.unwrap(SnowflakeStatement.class).executeAsyncQuery(createTableSql);
  String queryID = rs.unwrap(SnowflakeResultSet.class).getQueryID();
  statement.execute("drop table if exists test_rsmd");
  rs.close();
  // close statement and connection
  statement.close();
  connection.close();
  connection = getConnection();
  // open a new connection and create a result set
  ResultSet resultSet = connection.unwrap(SnowflakeConnection.class).createResultSet(queryID);
  ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
  // getCatalogName(), getSchemaName(), and getTableName() are empty
  // when session is re-opened
  assertEquals("",
               resultSetMetaData.getCatalogName(1).toUpperCase());
  assertEquals("",
               resultSetMetaData.getSchemaName(1).toUpperCase());
  assertEquals("", resultSetMetaData.getTableName(1));
  assertEquals(String.class.getName(),
               resultSetMetaData.getColumnClassName(2));
  assertEquals(2, resultSetMetaData.getColumnCount());
  assertEquals(22, resultSetMetaData.getColumnDisplaySize(1));
  assertEquals("COLA", resultSetMetaData.getColumnLabel(1));
  assertEquals("COLA", resultSetMetaData.getColumnName(1));
  assertEquals(3, resultSetMetaData.getColumnType(1));
  assertEquals("NUMBER", resultSetMetaData.getColumnTypeName(1));
  assertEquals(20, resultSetMetaData.getPrecision(1));
  assertEquals(5, resultSetMetaData.getScale(1));
  assertFalse(resultSetMetaData.isAutoIncrement(1));
  assertFalse(resultSetMetaData.isCaseSensitive(1));
  assertFalse(resultSetMetaData.isCurrency(1));
  assertFalse(resultSetMetaData.isDefinitelyWritable(1));
  assertEquals(ResultSetMetaData.columnNullable,
               resultSetMetaData.isNullable(1));
  assertTrue(resultSetMetaData.isReadOnly(1));
  assertTrue(resultSetMetaData.isSearchable(1));
  assertTrue(resultSetMetaData.isSigned(1));

  SnowflakeResultSetMetaData secretMetaData =
      resultSetMetaData.unwrap(SnowflakeResultSetMetaData.class);
  List<String> colNames = secretMetaData.getColumnNames();
  assertEquals("COLA", colNames.get(0));
  assertEquals("COLB", colNames.get(1));
  assertEquals(Types.DECIMAL, secretMetaData.getInternalColumnType(1));
  assertEquals(Types.VARCHAR, secretMetaData.getInternalColumnType(2));
  assertTrue(Pattern
                 .matches(
                     "[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}",
                     secretMetaData.getQueryID()));
  assertEquals(secretMetaData.getQueryID(), resultSet.unwrap(SnowflakeResultSet.class).getQueryID());
  resultSet.close();
  statement.close();
  connection.close();
}
 
Example 11
Source File: ResultSetAsyncIT.java    From snowflake-jdbc with Apache License 2.0 4 votes vote down vote up
@Test
public void testResultSetMetadata() throws SQLException
{
  Connection connection = getConnection();
  Statement statement = connection.createStatement();
  statement.execute("create or replace table test_rsmd(colA number(20, 5), colB string)");
  statement.execute("insert into test_rsmd values(1.00, 'str'),(2.00, 'str2')");
  ResultSet resultSet = statement.unwrap(SnowflakeStatement.class).executeAsyncQuery("select * from test_rsmd");
  ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
  assertEquals("",
               resultSetMetaData.getCatalogName(1).toUpperCase());
  assertEquals("",
               resultSetMetaData.getSchemaName(1).toUpperCase());
  assertEquals("", resultSetMetaData.getTableName(1));
  assertEquals(String.class.getName(),
               resultSetMetaData.getColumnClassName(2));
  assertEquals(2, resultSetMetaData.getColumnCount());
  assertEquals(22, resultSetMetaData.getColumnDisplaySize(1));
  assertEquals("COLA", resultSetMetaData.getColumnLabel(1));
  assertEquals("COLA", resultSetMetaData.getColumnName(1));
  assertEquals(3, resultSetMetaData.getColumnType(1));
  assertEquals("NUMBER", resultSetMetaData.getColumnTypeName(1));
  assertEquals(20, resultSetMetaData.getPrecision(1));
  assertEquals(5, resultSetMetaData.getScale(1));
  assertFalse(resultSetMetaData.isAutoIncrement(1));
  assertFalse(resultSetMetaData.isCaseSensitive(1));
  assertFalse(resultSetMetaData.isCurrency(1));
  assertFalse(resultSetMetaData.isDefinitelyWritable(1));
  assertEquals(ResultSetMetaData.columnNullable,
               resultSetMetaData.isNullable(1));
  assertTrue(resultSetMetaData.isReadOnly(1));
  assertTrue(resultSetMetaData.isSearchable(1));
  assertTrue(resultSetMetaData.isSigned(1));
  SnowflakeResultSetMetaData secretMetaData =
      resultSetMetaData.unwrap(SnowflakeResultSetMetaData.class);
  List<String> colNames = secretMetaData.getColumnNames();
  assertEquals("COLA", colNames.get(0));
  assertEquals("COLB", colNames.get(1));
  assertEquals(Types.DECIMAL, secretMetaData.getInternalColumnType(1));
  assertEquals(Types.VARCHAR, secretMetaData.getInternalColumnType(2));
  assertTrue(Pattern
                 .matches("[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}",
                          secretMetaData.getQueryID()));
  assertEquals(secretMetaData.getQueryID(), resultSet.unwrap(SnowflakeResultSet.class).getQueryID());

  statement.execute("drop table if exists test_rsmd");
  statement.close();
  connection.close();
}
 
Example 12
Source File: ResultSetIT.java    From snowflake-jdbc with Apache License 2.0 4 votes vote down vote up
@Test
public void testResultSetMetadata() throws SQLException
{
  Connection connection = getConnection();
  final Map<String, String> params = getConnectionParameters();
  Statement statement = connection.createStatement();

  statement.execute("create or replace table test_rsmd(colA number(20, 5), colB string)");
  statement.execute("insert into test_rsmd values(1.00, 'str'),(2.00, 'str2')");
  ResultSet resultSet = statement.executeQuery("select * from test_rsmd");
  ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
  assertEquals(params.get("database").toUpperCase(),
               resultSetMetaData.getCatalogName(1).toUpperCase());
  assertEquals(params.get("schema").toUpperCase(),
               resultSetMetaData.getSchemaName(1).toUpperCase());
  assertEquals("TEST_RSMD", resultSetMetaData.getTableName(1));
  assertEquals(String.class.getName(),
               resultSetMetaData.getColumnClassName(2));
  assertEquals(2, resultSetMetaData.getColumnCount());
  assertEquals(22, resultSetMetaData.getColumnDisplaySize(1));
  assertEquals("COLA", resultSetMetaData.getColumnLabel(1));
  assertEquals("COLA", resultSetMetaData.getColumnName(1));
  assertEquals(3, resultSetMetaData.getColumnType(1));
  assertEquals("NUMBER", resultSetMetaData.getColumnTypeName(1));
  assertEquals(20, resultSetMetaData.getPrecision(1));
  assertEquals(5, resultSetMetaData.getScale(1));
  assertFalse(resultSetMetaData.isAutoIncrement(1));
  assertFalse(resultSetMetaData.isCaseSensitive(1));
  assertFalse(resultSetMetaData.isCurrency(1));
  assertFalse(resultSetMetaData.isDefinitelyWritable(1));
  assertEquals(ResultSetMetaData.columnNullable,
               resultSetMetaData.isNullable(1));
  assertTrue(resultSetMetaData.isReadOnly(1));
  assertTrue(resultSetMetaData.isSearchable(1));
  assertTrue(resultSetMetaData.isSigned(1));
  SnowflakeResultSetMetaData secretMetaData =
      resultSetMetaData.unwrap(SnowflakeResultSetMetaData.class);
  List<String> colNames = secretMetaData.getColumnNames();
  assertEquals("COLA", colNames.get(0));
  assertEquals("COLB", colNames.get(1));
  assertEquals(Types.DECIMAL, secretMetaData.getInternalColumnType(1));
  assertEquals(Types.VARCHAR, secretMetaData.getInternalColumnType(2));
  assertTrue(Pattern
                 .matches("[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}",
                          secretMetaData.getQueryID()));

  statement.execute("drop table if exists test_rsmd");
  statement.close();
  connection.close();
}