db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (DERBY-5872) Inconsistency between isWrapperFor() and unwrap() in logical statements
Date Sat, 21 Jul 2012 16:43:34 GMT

     [ https://issues.apache.org/jira/browse/DERBY-5872?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Knut Anders Hatlen updated DERBY-5872:
--------------------------------------

    Attachment: derby-5872-1a.diff

The attached patch makes LogicalStatementEntity.isWrapperFor() work at the logical level,
like it does in the other Logical* classes.

The patch also adds test cases in jdbc4.PreparedStatementTest and jdbc4.CallableStatementTest
that expose the bug.

Additionally, it makes jdbcapi.ClosedObjectTest run on the Logical* classes too. I did this
because I noticed ClosedObjectTest didn't fail with my first attempt at a fix, where I had
forgotten to add a check for the statement being closed in isWrapperFor(). So I enabled the
test for these classes too in order to get more complete testing of the method.

All the regression tests passed with the patch.
                
> Inconsistency between isWrapperFor() and unwrap() in logical statements
> -----------------------------------------------------------------------
>
>                 Key: DERBY-5872
>                 URL: https://issues.apache.org/jira/browse/DERBY-5872
>             Project: Derby
>          Issue Type: Bug
>          Components: JDBC
>    Affects Versions: 10.4.1.3, 10.5.1.1, 10.6.1.0, 10.7.1.1, 10.8.1.2, 10.9.1.0
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>         Attachments: derby-5872-1a.diff
>
>
> I noticed this when I refactored the logical statement classes in DERBY-5868. The isWrapperFor()
method forwards calls to the underlying physical statement, but the unwrap() method works
purely at the logical level.
> For example, if you produce a LogicalPreparedStatement40 instance with this code
>         ClientConnectionPoolDataSource ds = new ClientConnectionPoolDataSource();
>         ds.setDatabaseName("testdb");
>         ds.setCreateDatabase("create");
>         ds.setMaxStatements(10);
>         PooledConnection pc = ds.getPooledConnection();
>         Connection c = pc.getConnection();
>         PreparedStatement ps = c.prepareStatement("values 1");
> you'll see that
>         System.out.println(ps.isWrapperFor(LogicalPreparedStatement40.class));
> prints false, telling that ps is not a wrapper for LogicalPreparedStatement40. However,
trying to unwrap ps as a LogicalPreparedStatement succeeds:
>         LogicalPreparedStatement40 lps = ps.unwrap(LogicalPreparedStatement40.class);
> On the other hand
>         System.out.println(ps.isWrapperFor(PreparedStatement40.class));
> prints true, indicating that ps is a wrapper for PreparedStatement40, but trying to unwrap
it as one, fails:
>         PreparedStatement40 ps4 = ps.unwrap(PreparedStatement40.class);
> Exception in thread "main" java.sql.SQLException: Unable to unwrap for 'class org.apache.derby.client.am.PreparedStatement40'
> 	at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(SQLExceptionFactory40.java:108)
> 	at org.apache.derby.client.am.SqlException.getSQLException(SqlException.java:364)
> 	at org.apache.derby.client.am.LogicalStatementEntity.unwrap(LogicalStatementEntity.java:258)
> 	at org.apache.derby.client.am.LogicalPreparedStatement.unwrap(LogicalPreparedStatement.java:57)
> 	at Test.main(Test.java:37)
> Caused by: org.apache.derby.client.am.SqlException: Unable to unwrap for 'class org.apache.derby.client.am.PreparedStatement40'
> 	... 3 more

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message