java.sql.ResultSet#isWrapperFor ( )源码实例Demo

下面列出了java.sql.ResultSet#isWrapperFor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: gemfirexd-oss   文件: ResultSetTest.java
/**
 * Tests the wrapper methods isWrapperFor and unwrap. There are two cases
 * to be tested
 * Case 1: isWrapperFor returns true and we call unwrap
 * Case 2: isWrapperFor returns false and we call unwrap
 *
 *
 * @throws SQLException	Thrown if some unexpected error happens
 */
public void testWrapper() throws SQLException {
    PreparedStatement ps = prepareStatement("select count(*) from sys.systables");
    ResultSet rs = ps.executeQuery();
    Class<ResultSet> wrap_class = ResultSet.class;
    
    //The if succeeds and we call the unwrap method on the conn object        
    if(rs.isWrapperFor(wrap_class)) {
    	ResultSet rs1 = 
            	(ResultSet)rs.unwrap(wrap_class);
    }
    else {
    	assertFalse("isWrapperFor wrongly returns false", rs.isWrapperFor(wrap_class));
    } 
    //Being Test for Case2
    //test for the case when isWrapper returns false
    //using some class that will return false when 
    //passed to isWrapperFor
    Class<PreparedStatement> wrap_class1 = PreparedStatement.class;
    
    try {
        //returning false is the correct behaviour in this case
        //Generate a message if it returns true
        if(rs.isWrapperFor(wrap_class1)) {
            assertTrue("isWrapperFor wrongly returns true", rs.isWrapperFor(wrap_class1));
        }
        else {
            PreparedStatement ps1 = (PreparedStatement)
                                       rs.unwrap(wrap_class1);
            fail("unwrap does not throw the expected exception"); 
        }
    }
    catch (SQLException sqle) {
        //Calling unwrap in this case throws an 
        //SQLException ensure that this SQLException 
        //has the correct SQLState
        assertSQLState(SQLStateConstants.UNABLE_TO_UNWRAP, sqle);
    }
}
 
源代码2 项目: snowflake-jdbc   文件: SnowflakeStatementV1.java
public void close(boolean removeClosedStatementFromConnection) throws SQLException
{
  logger.debug("close()");

  // No exception is raised even if the statement is closed.
  if (resultSet != null)
  {
    resultSet.close();
    resultSet = null;
  }
  isClosed = true;
  batch.clear();

  // also make sure to close all created resultSets from this statement
  for (ResultSet rs : openResultSets)
  {
    if (rs != null && !rs.isClosed())
    {
      if (rs.isWrapperFor(SnowflakeResultSetV1.class))
      {
        rs.unwrap(SnowflakeResultSetV1.class).close(false);
      }
      else
      {
        rs.close();
      }
    }
  }
  openResultSets.clear();
  sfStatement.close();
  if (removeClosedStatementFromConnection)
  {
    connection.removeClosedStatement(this);
  }
}
 
源代码3 项目: gemfirexd-oss   文件: ResultSetTest.java
/**
 * Tests the wrapper methods isWrapperFor and unwrap. There are two cases
 * to be tested
 * Case 1: isWrapperFor returns true and we call unwrap
 * Case 2: isWrapperFor returns false and we call unwrap
 *
 *
 * @throws SQLException	Thrown if some unexpected error happens
 */
public void testWrapper() throws SQLException {
    PreparedStatement ps = prepareStatement("select count(*) from sys.systables");
    ResultSet rs = ps.executeQuery();
    Class<ResultSet> wrap_class = ResultSet.class;
    
    //The if succeeds and we call the unwrap method on the conn object        
    if(rs.isWrapperFor(wrap_class)) {
    	ResultSet rs1 = 
            	(ResultSet)rs.unwrap(wrap_class);
    }
    else {
    	assertFalse("isWrapperFor wrongly returns false", rs.isWrapperFor(wrap_class));
    } 
    //Being Test for Case2
    //test for the case when isWrapper returns false
    //using some class that will return false when 
    //passed to isWrapperFor
    Class<PreparedStatement> wrap_class1 = PreparedStatement.class;
    
    try {
        //returning false is the correct behaviour in this case
        //Generate a message if it returns true
        if(rs.isWrapperFor(wrap_class1)) {
            assertTrue("isWrapperFor wrongly returns true", rs.isWrapperFor(wrap_class1));
        }
        else {
            PreparedStatement ps1 = (PreparedStatement)
                                       rs.unwrap(wrap_class1);
            fail("unwrap does not throw the expected exception"); 
        }
    }
    catch (SQLException sqle) {
        //Calling unwrap in this case throws an 
        //SQLException ensure that this SQLException 
        //has the correct SQLState
        assertSQLState(SQLStateConstants.UNABLE_TO_UNWRAP, sqle);
    }
}
 
源代码4 项目: spliceengine   文件: ResultSetTest.java
/**
 * Tests the wrapper methods isWrapperFor and unwrap. There are two cases
 * to be tested
 * Case 1: isWrapperFor returns true and we call unwrap
 * Case 2: isWrapperFor returns false and we call unwrap
 *
 *
 * @throws SQLException	Thrown if some unexpected error happens
 */
public void testWrapper() throws SQLException {
    PreparedStatement ps = prepareStatement("select count(*) from sys.systables");
    ResultSet rs = ps.executeQuery();
    Class<ResultSet> wrap_class = ResultSet.class;
    
    //The if succeeds and we call the unwrap method on the conn object        
    if(rs.isWrapperFor(wrap_class)) {
    	ResultSet rs1 = 
            	(ResultSet)rs.unwrap(wrap_class);
    }
    else {
    	assertFalse("isWrapperFor wrongly returns false", rs.isWrapperFor(wrap_class));
    } 
    //Being Test for Case2
    //test for the case when isWrapper returns false
    //using some class that will return false when 
    //passed to isWrapperFor
    Class<PreparedStatement> wrap_class1 = PreparedStatement.class;
    
    try {
        //returning false is the correct behaviour in this case
        //Generate a message if it returns true
        if(rs.isWrapperFor(wrap_class1)) {
            assertTrue("isWrapperFor wrongly returns true", rs.isWrapperFor(wrap_class1));
        }
        else {
            PreparedStatement ps1 = (PreparedStatement)
                                       rs.unwrap(wrap_class1);
            fail("unwrap does not throw the expected exception"); 
        }
    }
    catch (SQLException sqle) {
        //Calling unwrap in this case throws an 
        //SQLException ensure that this SQLException 
        //has the correct SQLState
        assertSQLState(SQLStateConstants.UNABLE_TO_UNWRAP, sqle);
    }
}