Derby
  1. Derby
  2. DERBY-5872

Inconsistency between isWrapperFor() and unwrap() in logical statements

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 10.4.1.3, 10.5.1.1, 10.6.1.0, 10.7.1.1, 10.8.1.2, 10.9.1.0
    • Fix Version/s: 10.10.1.1
    • Component/s: JDBC

      Description

      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

      1. derby-5872-1a.diff
        9 kB
        Knut Anders Hatlen

        Activity

        Knut Anders Hatlen created issue -
        Knut Anders Hatlen made changes -
        Field Original Value New Value
        Assignee Knut Anders Hatlen [ knutanders ]
        Knut Anders Hatlen made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Knut Anders Hatlen made changes -
        Attachment derby-5872-1a.diff [ 12537460 ]
        Knut Anders Hatlen made changes -
        Issue & fix info Patch Available [ 10102 ]
        Knut Anders Hatlen made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Issue & fix info Patch Available [ 10102 ]
        Fix Version/s 10.10.0.0 [ 12321550 ]
        Resolution Fixed [ 1 ]
        Knut Anders Hatlen made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Gavin made changes -
        Workflow jira [ 12717518 ] Default workflow, editable Closed status [ 12802223 ]
        Mamta A. Satoor made changes -
        Labels derby_backport_reject_10_9

          People

          • Assignee:
            Knut Anders Hatlen
            Reporter:
            Knut Anders Hatlen
          • Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development