db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1061824 - in /db/derby/code/trunk/java: client/org/apache/derby/client/am/ engine/org/apache/derby/iapi/jdbc/ engine/org/apache/derby/impl/jdbc/ testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/
Date Fri, 21 Jan 2011 14:41:05 GMT
Author: rhillegas
Date: Fri Jan 21 14:41:04 2011
New Revision: 1061824

URL: http://svn.apache.org/viewvc?rev=1061824&view=rev
Log:
DERBY-4869: Implement Statement.closeOnCompletion(), new in JDBC 4.1.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41Statement.java
  (with props)
Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java?rev=1061824&r1=1061823&r2=1061824&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalStatementEntity.java
Fri Jan 21 14:41:04 2011
@@ -147,6 +147,19 @@ abstract class LogicalStatementEntity
     }
 
     /**
+     * Returns the associated physical statement.
+     *
+     * @return A statement.
+     * @throws SQLException if the logical statement has been closed
+     */
+    synchronized java.sql.Statement getPhysStmt()
+            throws SQLException
+    {
+        if ( hasCallableStmt ) { return getPhysCs(); }
+        else { return getPhysPs(); }
+    }
+
+    /**
      * Close the logical statement.
      *
      * @throws SQLException if closing the statement fails
@@ -205,4 +218,20 @@ abstract class LogicalStatementEntity
     synchronized boolean isLogicalEntityClosed() {
         return (physicalPs == null);
     }
+    
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    public  void    closeOnCompletion() throws SQLException
+    {
+        ((org.apache.derby.client.am.Statement) getPhysStmt()).closeOnCompletion();
+    }
+
+    public  boolean isCloseOnCompletion() throws SQLException
+    {
+        return ((org.apache.derby.client.am.Statement) getPhysStmt()).isCloseOnCompletion();
+    }
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java?rev=1061824&r1=1061823&r2=1061824&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ResultSet.java Fri Jan 21 14:41:04
2011
@@ -460,6 +460,8 @@ public abstract class ResultSet implemen
             statement_.closeX();
         }
 
+        statement_.closeMeOnCompletion();
+
         nullDataForGC();
     }
 

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java?rev=1061824&r1=1061823&r2=1061824&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Statement.java Fri Jan 21 14:41:04
2011
@@ -198,6 +198,9 @@ public class Statement implements java.s
     // PreparedStatement overrides this.
     protected boolean isPoolable = false;    
 
+    private boolean closeOnCompletion_ = false;
+    private boolean closingResultSets_ = false;
+    
     //---------------------constructors/finalizer/accessors--------------------
 
     private Statement() {
@@ -1936,24 +1939,35 @@ public class Statement implements java.s
      * from the commit and rollback listeners list in
      * <code>org.apache.derby.client.am.Connection</code>.
      */
-    final void markResultSetsClosed(boolean removeListener) {
-        if (resultSetList_ != null) {
-            for (int i = 0; i < resultSetList_.length; i++) {
-                if (resultSetList_[i] != null) {
-                    resultSetList_[i].markClosed(removeListener);
+    final void markResultSetsClosed(boolean removeListener)
+    {
+        try {
+            //
+            // This prevents us from accidentally closing ourself as part
+            // of cleaning up the previous operation. This flag short-circuits the logic
which enforces
+            // closeOnCompletion().
+            //
+            closingResultSets_ = true;
+            
+            if (resultSetList_ != null) {
+                for (int i = 0; i < resultSetList_.length; i++) {
+                    if (resultSetList_[i] != null) {
+                        resultSetList_[i].markClosed(removeListener);
+                    }
+                    resultSetList_[i] = null;
                 }
-                resultSetList_[i] = null;
             }
+            if (generatedKeysResultSet_ != null) {
+                generatedKeysResultSet_.markClosed(removeListener);
+            }
+            if (resultSet_ != null) {
+                resultSet_.markClosed(removeListener);
+            }
+            resultSet_ = null;
+            resultSetList_ = null;
+            generatedKeysResultSet_ = null;
         }
-        if (generatedKeysResultSet_ != null) {
-            generatedKeysResultSet_.markClosed(removeListener);
-        }
-        if (resultSet_ != null) {
-            resultSet_.markClosed(removeListener);
-        }
-        resultSet_ = null;
-        resultSetList_ = null;
-        generatedKeysResultSet_ = null;
+        finally { closingResultSets_ = false; }
     }
 
     private void flowExecute(int executeType, String sql) throws SqlException {
@@ -3034,4 +3048,62 @@ public class Statement implements java.s
     {
         return jdbc3FeatureNotSupported(true);
     }
+    
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    public  void    closeOnCompletion() throws SQLException
+    {
+        try { checkForClosedStatement(); }
+        catch (SqlException se) { throw se.getSQLException(); }
+        
+        closeOnCompletion_ = true;
+    }
+
+    public  boolean isCloseOnCompletion() throws SQLException
+    {
+        try { checkForClosedStatement(); }
+        catch (SqlException se) { throw se.getSQLException(); }
+        
+        return closeOnCompletion_;
+    }
+
+    //
+    // For tracking all of the ResultSets produced by this Statement so
+    // that the Statement can be cleaned up if closeOnCompletion() was invoked.
+    //
+    void    closeMeOnCompletion()
+    {
+        // If necessary, close the Statement after all of its dependent
+        // ResultSets have closed.
+        boolean active = ( (connection_ != null) && (!connection_.isClosed() ) );
+        if ( active && (!closingResultSets_) && closeOnCompletion_ )
+        {
+            try {
+                if ( isOpen( resultSet_ ) ) { return; }
+                if ( isOpen( generatedKeysResultSet_ ) ) { return; }
+
+                if ( resultSetList_ != null )
+                {
+                    int count = resultSetList_.length;
+                    for ( int i = 0; i < count; i++ )
+                    {
+                        if ( isOpen( resultSetList_[ i ] ) ) { return; }
+                    }
+                }
+
+                // if we got here, then the Statement has no open ResultSets left
+                close();
+            }
+            catch (SQLException se) {  se.printStackTrace( agent_.getLogWriter() ); }
+        }
+    }
+    private boolean isOpen( ResultSet rs ) throws SQLException
+    {
+        return ( (rs != null) && (!rs.isClosed()) );
+    }
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java?rev=1061824&r1=1061823&r2=1061824&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredStatement.java Fri
Jan 21 14:41:04 2011
@@ -584,4 +584,21 @@ public class BrokeredStatement implement
                                               "Statement");
         }
     }
+    
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    public  void    closeOnCompletion() throws SQLException
+    {
+        ((EngineStatement) getStatement()).closeOnCompletion();
+    }
+
+    public  boolean isCloseOnCompletion() throws SQLException
+    {
+        return ((EngineStatement) getStatement()).isCloseOnCompletion();
+    }
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java?rev=1061824&r1=1061823&r2=1061824&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineStatement.java Fri Jan
21 14:41:04 2011
@@ -46,4 +46,14 @@ public interface EngineStatement extends
      * @see java.sql.Statement#getResultSetHoldability()
      */ 
     public int getResultSetHoldability() throws SQLException;
+    
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    public  void    closeOnCompletion() throws SQLException;
+    public  boolean isCloseOnCompletion() throws SQLException;
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=1061824&r1=1061823&r2=1061824&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java Fri Jan
21 14:41:04 2011
@@ -622,6 +622,12 @@ public abstract class EmbedResultSet ext
 			// the idea is to release resources, so:
 			currentRow = null;
 
+            // to prevent infinite looping, tell our parent Statement
+            // that we have closed AFTER
+            // we have marked ourself as closed
+            if ( stmt != null) { stmt.closeMeOnCompletion(); }
+            if ( (owningStmt != null) && (owningStmt != stmt) ) { owningStmt.closeMeOnCompletion();
}
+            
 			// we hang on to theResults and messenger
 			// in case more calls come in on this resultSet
 		}

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java?rev=1061824&r1=1061823&r2=1061824&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java Fri Jan
21 14:41:04 2011
@@ -117,6 +117,9 @@ public class EmbedStatement extends Conn
 	// PreparedStatement overrides this.
 	protected boolean isPoolable = false;
 
+    private boolean closeOnCompletion = false;
+    private boolean closingResultSets = false;
+    
 	//
 	// constructor
 	//
@@ -309,7 +312,7 @@ public class EmbedStatement extends Conn
 		  //we first set the status
 		  active = false;
 
-		  //first, clear the resutl set
+		  // first, clear the result sets.
 		  clearResultSets();
 		  
 		  //next, release other resource
@@ -1064,6 +1067,7 @@ public class EmbedStatement extends Conn
 				// we only have the one resultset, so this is
 				// simply a close for us.
 				clearResultSets();
+                closeMeOnCompletion();
 				return false;
 			}
 
@@ -1440,8 +1444,22 @@ public class EmbedStatement extends Conn
 		Close and clear all result sets associated with this statement
 		from the last execution.
 	*/
-	void clearResultSets() throws SQLException {
+	void clearResultSets() throws SQLException
+    {
+        //
+        // Try not to let closeDependentResultSet() close this Statement
+        // when we are just cleaning up before the next operation.
+        //
+        try {
+            closingResultSets = true;
+            clearResultSetsMinion();
+        }
+        finally { closingResultSets = false; }
 
+    }
+    // don't call this directly. call clearResultSets() instead.
+    private void    clearResultSetsMinion() throws SQLException
+    {
 		SQLException sqle = null;
 
 		try {
@@ -1754,5 +1772,62 @@ public class EmbedStatement extends Conn
 
 		isPoolable = poolable;
 	}
+
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    public  void    closeOnCompletion() throws SQLException
+    {
+		// Assert the statement is still active (not closed)
+        checkStatus();
+        
+        closeOnCompletion = true;
+    }
+
+    public  boolean isCloseOnCompletion() throws SQLException
+    {
+		// Assert the statement is still active (not closed)
+        checkStatus();
+        
+        return closeOnCompletion;
+    }
+
+    //
+    // For tracking all of the ResultSets produced by this Statement so
+    // that the Statement can be cleaned up if closeOnCompletion() was invoked.
+    //
+    void    closeMeOnCompletion()
+    {
+        // If necessary, close the Statement after all of its dependent
+        // ResultSets have closed.
+        if ( active && (!closingResultSets) && closeOnCompletion )
+        {
+            try {
+                if ( isOpen( results ) ) { return; }
+                if ( autoGeneratedKeysResultSet != null ) { return; }
+
+                if ( dynamicResults != null )
+                {
+                    int count = dynamicResults.length;
+                    for ( int i = 0; i < count; i++ )
+                    {
+                        if ( isOpen( dynamicResults[ i ] ) ) { return; }
+                    }
+                }
+
+                // if we got here, then the Statement has no open ResultSets left
+                close();
+            }
+            catch (SQLException se) { Util.logSQLException( se ); }
+        }
+    }
+    private boolean isOpen( EmbedResultSet rs ) throws SQLException
+    {
+        return ( (rs != null) && (!rs.isClosed()) );
+    }
+    
 }
 

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java?rev=1061824&r1=1061823&r2=1061824&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/StatementJdbc20Test.java
Fri Jan 21 14:41:04 2011
@@ -23,6 +23,7 @@ package org.apache.derbyTesting.function
 
 import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.DriverManager;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.Statement;
@@ -44,6 +45,7 @@ import junit.framework.TestSuite;
 public class StatementJdbc20Test extends BaseJDBCTestCase {
 
     private static  final   String  METHOD_NOT_ALLOWED = "XJ016";
+    private static  final   String  CLOSED_STATEMENT = "XJ012";
     
     /**
      * Create a test with the given name.
@@ -90,6 +92,14 @@ public class StatementJdbc20Test extends
                  */
                 stmt.execute("create table tab1 (i int, s smallint, r real)");
                 stmt.executeUpdate("insert into tab1 values(1, 2, 3.1)");
+
+                stmt.execute
+                    (
+                     "create procedure dynamic_results() " +
+                     "language java parameter style java external name '" +
+                     StatementJdbc20Test.class.getName() + ".dynamicResults' " +
+                     "dynamic result sets 2"
+                     );
             }
         };
     }
@@ -290,5 +300,155 @@ public class StatementJdbc20Test extends
         }
     }
 
+    /**
+     * Test the closeOnCompletion() and isCloseOnCompletion() methods
+     * added by JDBC 4.1.
+     */
+    public void testCompletionClosure_jdbc4_1() throws Exception
+    {
+        vetClosure( false, false );
+        vetClosure( false, true );
+        vetClosure( true, false );
+        vetClosure( true, true );
+    }
+    private void vetClosure( boolean closeOnCompletion, boolean delayClosureCall ) throws
Exception
+    {
+        vetClosedSelect( closeOnCompletion, delayClosureCall );
+        vetClosedCall( closeOnCompletion, delayClosureCall );
+        vetClosedPS( closeOnCompletion, delayClosureCall );
+    }
+    private void vetClosedSelect( boolean closeOnCompletion, boolean delayClosureCall ) throws
Exception
+    {
+        Statement stmt = createStatement();
+        ResultSet rs;
+
+        println( "Verifying SELECT wrapper on " + stmt.getClass().getName() +
+                 " with closeOnCompletion = " + closeOnCompletion +
+                 " and delayClosureCall = " + delayClosureCall );
+        Wrapper41Statement  wrapper = new Wrapper41Statement( stmt );
+
+        if ( !delayClosureCall )
+        { setCloseOnCompletion( wrapper, closeOnCompletion ); }
+
+        rs = stmt.executeQuery( "select * from tab1" );
+
+        if ( delayClosureCall )
+        { setCloseOnCompletion( wrapper, closeOnCompletion ); }
+
+        rs.close();
+
+        assertEquals( closeOnCompletion, wrapper.isClosed() );
+
+        vetSuccessfulClosure( wrapper, closeOnCompletion );
+    }
+    private void vetClosedCall( boolean closeOnCompletion, boolean delayClosureCall ) throws
Exception
+    {
+        Statement stmt = createStatement();
+        ResultSet rs;
+
+        println( "Verifying CALL wrapper on " + stmt.getClass().getName() +
+                 " with closeOnCompletion = " + closeOnCompletion +
+                 " and delayClosureCall = " + delayClosureCall );
+        Wrapper41Statement  wrapper = new Wrapper41Statement( stmt );
+
+        if ( !delayClosureCall )
+        { setCloseOnCompletion( wrapper, closeOnCompletion ); }
+
+        assertTrue( stmt.execute( "call dynamic_results()" ) );
+
+        assertFalse( wrapper.isClosed() );
+
+        ResultSet   rs1 = stmt.getResultSet();
+
+        if ( delayClosureCall )
+        { setCloseOnCompletion( wrapper, closeOnCompletion ); }
+
+        assertTrue( stmt.getMoreResults() ); // implicitly closes rs1
+        assertFalse( wrapper.isClosed() );
+
+        ResultSet   rs2 = stmt.getResultSet();
+        rs2.close();
+        assertEquals( closeOnCompletion, wrapper.isClosed() );
+
+        vetSuccessfulClosure( wrapper, closeOnCompletion );
+    }
+    private void vetClosedPS( boolean closeOnCompletion, boolean delayClosureCall ) throws
Exception
+    {
+        PreparedStatement ps = getConnection().prepareStatement( "select * from tab1" );
+        ResultSet rs;
+
+        println( "Verifying PreparedStatement wrapper on " + ps.getClass().getName() +
+                 " with closeOnCompletion = " + closeOnCompletion +
+                 " and delayClosureCall = " + delayClosureCall );
+        Wrapper41Statement  wrapper = new Wrapper41Statement( ps );
+
+        if ( !delayClosureCall )
+        { setCloseOnCompletion( wrapper, closeOnCompletion ); }
+
+        rs = ps.executeQuery();
+
+        if ( delayClosureCall )
+        { setCloseOnCompletion( wrapper, closeOnCompletion ); }
+
+        rs.close();
+
+        assertEquals( closeOnCompletion, wrapper.isClosed() );
+
+        vetSuccessfulClosure( wrapper, closeOnCompletion );
+
+        if ( !wrapper.isClosed() ) { ps.close(); }
+    }
+    
+    private void    setCloseOnCompletion( Wrapper41Statement wrapper, boolean closeOnCompletion
)
+        throws Exception
+    {
+        assertFalse( wrapper.isCloseOnCompletion() );
+        if ( closeOnCompletion ) { wrapper.closeOnCompletion(); }
+        assertEquals( closeOnCompletion, wrapper.isCloseOnCompletion() );
+    }
+    private void    vetSuccessfulClosure
+        ( Wrapper41Statement wrapper, boolean closeOnCompletion )
+        throws Exception
+    {
+        if ( closeOnCompletion )
+        {
+            try {
+                wrapper.closeOnCompletion();
+                fail( "Expected closed statement failure." );
+            }
+            catch (SQLException se)
+            {
+                assertSQLState( CLOSED_STATEMENT, se );
+            }
+
+            try {
+                wrapper.isCloseOnCompletion();
+                fail( "Expected closed statement failure." );
+            }
+            catch (SQLException se)
+            {
+                assertSQLState( CLOSED_STATEMENT, se );
+            }
+        }
+    }
+    
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // PROCEDURES
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+
+    /**
+     * Stored procedure which returns 2 ResultSets.
+     */
+    public static void dynamicResults
+        ( ResultSet[] rs1, ResultSet[] rs2 )
+        throws SQLException
+    {
+        Connection c = DriverManager.getConnection("jdbc:default:connection");
+        rs1[0] = c.createStatement().executeQuery("VALUES(1)");
+        rs2[0] = c.createStatement().executeQuery("VALUES(2)");
+    }
 
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41Statement.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41Statement.java?rev=1061824&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41Statement.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41Statement.java
Fri Jan 21 14:41:04 2011
@@ -0,0 +1,113 @@
+/*
+ 
+   Derby - Class org.apache.derbyTesting.functionTests.tests.jdbcapi.Wrapper41Statement
+ 
+   Licensed to the Apache Software Foundation (ASF) under one or more
+   contributor license agreements.  See the NOTICE file distributed with
+   this work for additional information regarding copyright ownership.
+   The ASF licenses this file to you under the Apache License, Version 2.0
+   (the "License"); you may not use this file except in compliance with
+   the License.  You may obtain a copy of the License at
+ 
+      http://www.apache.org/licenses/LICENSE-2.0
+ 
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+ 
+ */
+
+package org.apache.derbyTesting.functionTests.tests.jdbcapi;
+
+import java.lang.reflect.Method;
+import java.sql.SQLException;
+
+import org.apache.derby.iapi.jdbc.EngineStatement;
+import org.apache.derby.client.am.LogicalPreparedStatement;
+
+/**
+ * A wrapper around the new Statement methods added by JDBC 4.1.
+ */
+public  class   Wrapper41Statement
+{
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // STATE
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    private EngineStatement     _engineStatement;
+    private org.apache.derby.client.am.Statement       _netStatement;
+    private LogicalPreparedStatement  _logicalStatement;
+    
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // CONSTRUCTORS
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    public Wrapper41Statement( Object wrapped ) throws Exception
+    {
+        if ( wrapped instanceof EngineStatement ) { _engineStatement = (EngineStatement)
wrapped; }
+        else if ( wrapped instanceof org.apache.derby.client.am.Statement ) { _netStatement
= (org.apache.derby.client.am.Statement) wrapped; }
+        else if ( wrapped instanceof LogicalPreparedStatement ) { _logicalStatement = (LogicalPreparedStatement)
wrapped; }
+        else { throw nothingWrapped(); }
+    }
+    
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // JDBC 4.1 BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    public  void    closeOnCompletion() throws SQLException
+    {
+        if ( _engineStatement != null ) { _engineStatement.closeOnCompletion(); }
+        else if ( _netStatement != null ) { _netStatement.closeOnCompletion(); }
+        else if ( _logicalStatement != null ) { _logicalStatement.closeOnCompletion(); }
+        else { throw nothingWrapped(); }
+    }
+
+    public  boolean isCloseOnCompletion() throws SQLException
+    {
+        if ( _engineStatement != null ) { return _engineStatement.isCloseOnCompletion();
}
+        else if ( _netStatement != null ) { return _netStatement.isCloseOnCompletion(); }
+        else if ( _logicalStatement != null ) { return _logicalStatement.isCloseOnCompletion();
}
+        else { throw nothingWrapped(); }
+    }
+
+
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // OTHER PUBLIC BEHAVIOR
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    public java.sql.Statement   getWrappedObject() throws SQLException
+    {
+        if ( _engineStatement != null ) { return _engineStatement; }
+        else if ( _netStatement != null ) { return _netStatement; }
+        else if ( _logicalStatement != null ) { return _logicalStatement; }
+        else { throw nothingWrapped(); }
+    }
+
+    public  boolean isClosed()  throws Exception
+    {
+        java.sql.Statement  stmt = getWrappedObject();
+        Method  method = stmt.getClass().getMethod( "isClosed", null );
+
+        return ((Boolean) method.invoke( stmt, null )).booleanValue();
+    }
+
+    ///////////////////////////////////////////////////////////////////////
+    //
+    // MINIONS
+    //
+    ///////////////////////////////////////////////////////////////////////
+
+    private SQLException nothingWrapped() { return new SQLException( "Nothing wrapped!" );
}
+
+}
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/Wrapper41Statement.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message