Java Code Examples for java.sql.ResultSet#isWrapperFor()

The following examples show how to use java.sql.ResultSet#isWrapperFor() . 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: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 2
Source File: SnowflakeStatementV1.java    From snowflake-jdbc with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 3
Source File: ResultSetTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example 4
Source File: ResultSetTest.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
    }
}