db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rhille...@apache.org
Subject svn commit: r1063723 - 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/jdbc4/
Date Wed, 26 Jan 2011 14:01:12 GMT
Author: rhillegas
Date: Wed Jan 26 14:01:12 2011
New Revision: 1063723

URL: http://svn.apache.org/viewvc?rev=1063723&view=rev
Log:
DERBY-4869: Add Connection.getSchema() and setSchema() per JDBC 4.1.

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
    db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java?rev=1063723&r1=1063722&r2=1063723&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/Connection.java Wed Jan 26
14:01:12 2011
@@ -2477,5 +2477,42 @@ public abstract class Connection
         markClosed( false );
     }
     
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    /**
+     * Get the name of the current schema.
+     */
+    public String   getSchema() throws SQLException
+	{
+        return getCurrentSchemaName();
+    }
+    
+    /**
+     * Set the default schema for the Connection.
+     */
+    public void   setSchema(  String schemaName ) throws SQLException
+	{
+        try {
+            checkForClosedConnection();
+        } catch (SqlException se) {
+            throw se.getSQLException();
+        }
+
+        java.sql.PreparedStatement   ps = null;
+
+        try {
+            ps = prepareStatement( "set schema ?" );
+            ps.setString( 1, schemaName );
+            ps.execute();
+        }
+        finally
+        {
+            if ( ps != null ) { ps.close(); }
+        }
+	}
 
 }

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection.java?rev=1063723&r1=1063722&r2=1063723&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection.java (original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/am/LogicalConnection.java Wed
Jan 26 14:01:12 2011
@@ -601,4 +601,38 @@ public class LogicalConnection implement
         }
     }
 
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    /**
+     * Get the name of the current schema.
+     */
+    public String   getSchema() throws SQLException
+	{
+		try {
+	        checkForNullPhysicalConnection();
+	        return physicalConnection_.getSchema();
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
+    }
+    
+    /**
+     * Set the default schema for the Connection.
+     */
+    public void   setSchema(  String schemaName ) throws SQLException
+	{
+		try {
+	        checkForNullPhysicalConnection();
+	        physicalConnection_.setSchema( schemaName );
+		} catch (SQLException sqle) {
+			notifyException(sqle);
+			throw sqle;
+		}
+    }
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java?rev=1063723&r1=1063722&r2=1063723&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java Wed
Jan 26 14:01:12 2011
@@ -668,4 +668,41 @@ public abstract class BrokeredConnection
             throws SQLException {
         getRealConnection().resetFromPool();
     }
+    
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    /**
+     * Get the name of the current schema.
+     */
+    public String   getSchema() throws SQLException
+    {
+    	try {
+            return getRealConnection().getSchema();
+    	}
+    	catch (SQLException se)
+    	{
+    		notifyException(se);
+    		throw se;
+    	}
+    }
+
+    /**
+     * Set the default schema for the Connection.
+     */
+    public void   setSchema(  String schemaName ) throws SQLException
+	{
+    	try {
+            getRealConnection().setSchema( schemaName );
+    	}
+    	catch (SQLException se)
+    	{
+    		notifyException(se);
+    		throw se;
+    	}
+    }
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java?rev=1063723&r1=1063722&r2=1063723&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java Wed Jan
26 14:01:12 2011
@@ -116,4 +116,21 @@ public interface EngineConnection extend
      * schema are reset.
      */
     public void resetFromPool() throws SQLException;
+    
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    /**
+     * Get the name of the current schema.
+     */
+    public String   getSchema() throws SQLException;
+
+    /**
+     * Set the default schema for the Connection.
+     */
+    public void   setSchema(  String schemaName ) throws SQLException;
+    
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=1063723&r1=1063722&r2=1063723&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Wed Jan
26 14:01:12 2011
@@ -3336,4 +3336,49 @@ public abstract class EmbedConnection im
         setInactive();
     }
         
+    ////////////////////////////////////////////////////////////////////
+    //
+    // INTRODUCED BY JDBC 4.1 IN JAVA 7
+    //
+    ////////////////////////////////////////////////////////////////////
+
+    /**
+     * Get the name of the current schema.
+     */
+    public String   getSchema() throws SQLException
+	{
+		checkIfClosed();
+
+		synchronized(getConnectionSynchronization())
+		{
+            setupContextStack();
+			try {
+                LanguageConnectionContext lcc = getLanguageConnection();
+                return lcc.getCurrentSchemaName();
+			} finally {
+				restoreContextStack();
+			}
+		}
+	}
+
+    /**
+     * Set the default schema for the Connection.
+     */
+    public void   setSchema(  String schemaName ) throws SQLException
+	{
+		checkIfClosed();
+
+        PreparedStatement   ps = null;
+
+        try {
+            ps = prepareStatement( "set schema ?" );
+            ps.setString( 1, schemaName );
+            ps.execute();
+        }
+        finally
+        {
+            if ( ps != null ) { ps.close(); }
+        }
+	}
+
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java?rev=1063723&r1=1063722&r2=1063723&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/ConnectionMethodsTest.java
Wed Jan 26 14:01:12 2011
@@ -129,7 +129,8 @@ public class ConnectionMethodsTest exten
                 s.execute("create table clobtable2(n int,clobcol CLOB)");
                 s.execute("create table blobtable2(n int,blobcol BLOB)");
                 s.execute("create table abort_table(a int)");
-
+                s.execute("create schema foo");
+                s.execute("create table foo.set_schema_table( a int )");
             }
         };
     }
@@ -559,4 +560,58 @@ public class ConnectionMethodsTest exten
         conn2.close();
     }
     
+    /**
+     * Test the JDBC 4.1 Connection.getSchema() and setSchema() methods.
+     */
+    public void testGetSetSchema() throws Exception
+    {
+        Connection  conn = getConnection();
+        println( "Testing get/setSchema() on a " + conn.getClass().getName() );
+        Wrapper41Conn   wrapper = new Wrapper41Conn( conn );
+
+        assertEquals( "APP", wrapper.getSchema() );
+        try {
+            prepareStatement( "select * from set_schema_table" );
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( "42X05", se );
+        }
+
+        wrapper.setSchema( "FOO" );
+        assertEquals( "FOO", wrapper.getSchema() );
+
+        prepareStatement( "select * from set_schema_table" );
+
+        try {
+            wrapper.setSchema( "foo" );
+            fail( "Should not have been able to change to a non-existent schema." );
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( "42Y07", se );
+        }
+
+        conn.close();
+        
+        try {
+            wrapper.setSchema( "APP" );
+            fail( "Should fail on a closed connection." );
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( CLOSED_CONNECTION, se );
+        }
+
+        try {
+            wrapper.getSchema();
+            fail( "Should fail on a closed connection." );
+        }
+        catch (SQLException se)
+        {
+            assertSQLState( CLOSED_CONNECTION, se );
+        }
+
+    }
+    
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java?rev=1063723&r1=1063722&r2=1063723&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/Wrapper41Conn.java
Wed Jan 26 14:01:12 2011
@@ -78,6 +78,24 @@ public  class   Wrapper41Conn
         else { throw nothingWrapped(); }
     }
 
+    public  String    getSchema() throws SQLException
+    {
+        if ( _embedded != null ) { return _embedded.getSchema(); }
+        else if ( _netclient != null ) { return _netclient.getSchema(); }
+        else if ( _brokeredConnection != null ) { return _brokeredConnection.getSchema();
}
+        else if ( _logicalConnection != null ) { return _logicalConnection.getSchema(); }
+        else { throw nothingWrapped(); }
+    }
+
+    public  void    setSchema( String schemaName ) throws SQLException
+    {
+        if ( _embedded != null ) { _embedded.setSchema( schemaName ); }
+        else if ( _netclient != null ) { _netclient.setSchema( schemaName ); }
+        else if ( _brokeredConnection != null ) { _brokeredConnection.setSchema( schemaName
); }
+        else if ( _logicalConnection != null ) { _logicalConnection.setSchema( schemaName
); }
+        else { throw nothingWrapped(); }
+    }
+
     ///////////////////////////////////////////////////////////////////////
     //
     // OTHER PUBLIC BEHAVIOR



Mime
View raw message