You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2006/02/21 18:54:55 UTC

svn commit: r379545 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/jdbc/ impl/jdbc/ jdbc/

Author: djd
Date: Tue Feb 21 09:54:52 2006
New Revision: 379545

URL: http://svn.apache.org/viewcvs?rev=379545&view=rev
Log:
DERBY-1015 (partial) Initial code for EngineConnection. Add the EngineConnection
interface with a set of initial methods, make EmbedConnection and BrokeredConnection
implement this interface. No uses of the interface added yet. Some of the initial
methods were moved from BrokeredConnectionControl which looked like a start on the
same approach but did not address the issue of a single api for embedded and brokered
connections.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java   (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java?rev=379545&r1=379544&r2=379545&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 Tue Feb 21 09:54:52 2006
@@ -43,7 +43,7 @@
  * This is a rudimentary connection that delegates
  * EVERYTHING to Connection.
  */
-public class BrokeredConnection implements Connection
+public class BrokeredConnection implements EngineConnection
 {
 	
 	// default for Derby
@@ -371,7 +371,7 @@
 	  *
 	  *	@return	the current connection
 	  */
-	final Connection getRealConnection() throws SQLException {
+	final EngineConnection getRealConnection() throws SQLException {
 		if (isClosed)
 			throw Util.noCurrentConnection();
 
@@ -388,20 +388,12 @@
 		with the state of this new handle.
 	*/
 	public void syncState() throws SQLException {
-		Connection conn = getRealConnection();
+		EngineConnection conn = getRealConnection();
 
 		stateIsolationLevel = conn.getTransactionIsolation();
 		stateReadOnly = conn.isReadOnly();
 		stateAutoCommit = conn.getAutoCommit();
-		// jdk13 does not have Connection.getHoldability method and hence using
-		// reflection to cover both jdk13 and higher jdks
-		try {
-			Method sh = conn.getClass().getMethod("getHoldability", null);
-			stateHoldability = ((Integer)sh.invoke(conn, null)).intValue();
-		} catch( Exception e)
-		{
-			throw PublicAPI.wrapStandardException( StandardException.plainWrapException( e));
-		}       
+        stateHoldability = conn.getHoldability(); 
 	}
 
 	/**
@@ -411,7 +403,7 @@
 		at the start and end of a global transaction.
 	*/
 	public void getIsolationUptoDate() throws SQLException {
-		if (control!=null && control.isIsolationLevelSetUsingSQLorJDBC()) {
+		if (control.isIsolationLevelSetUsingSQLorJDBC()) {
 			stateIsolationLevel = getRealConnection().getTransactionIsolation();
 			control.resetIsolationLevelFlag();
 		}
@@ -467,9 +459,15 @@
 	 *  @param drdaID  drdaID to be used for this connection
 	 *
 	 */
-	public void setDrdaID(String drdaID)
+	public final void setDrdaID(String drdaID)
 	{
-		control.setDrdaID(drdaID);
+        try {
+		    getRealConnection().setDrdaID(drdaID);
+        } catch (SQLException sqle)
+        {
+            // connection is closed, just ignore drdaId
+            // since connection cannot be used.
+        }
 	}
 
 	/**
@@ -480,9 +478,9 @@
 	 * See EmbedConnection#setPrepareIsolation
 	 * 
 	 */
-	public void setPrepareIsolation(int level) throws SQLException
+	public final void setPrepareIsolation(int level) throws SQLException
 	{
-		control.setPrepareIsolation(level);
+        getRealConnection().setPrepareIsolation(level);
 	}
 
 	/**
@@ -493,9 +491,9 @@
 	 * @return current prepare isolation level 
 	 * See EmbedConnection#getPrepareIsolation
 	 */
-	public int getPrepareIsolation() throws SQLException
+	public final int getPrepareIsolation() throws SQLException
 	{
-		return control.getPrepareIsolation();
+		return getRealConnection().getPrepareIsolation();
 	}
             
     /**
@@ -526,4 +524,41 @@
     }
 
 	int getJDBCLevel() { return 2;}
+
+    /*
+     * JDBC 3.0 methods that are exposed through EngineConnection.
+     */
+    
+    /**
+     * Prepare statement with explicit holdability.
+     */
+    public final PreparedStatement prepareStatement(String sql,
+            int resultSetType, int resultSetConcurrency,
+            int resultSetHoldability) throws SQLException {
+    	try {
+    		control.checkHoldCursors(resultSetHoldability);
+    		return control.wrapStatement(
+    			getRealConnection().prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability), sql, null);
+    	}
+    	catch (SQLException se)
+    	{
+    		notifyException(se);
+    		throw se;
+    	}
+    }
+
+    /**
+     * Get the holdability for statements created by this connection
+     * when holdability is not passed in.
+     */
+    public final int getHoldability() throws SQLException {
+    	try {
+    		return getRealConnection().getHoldability();
+    	}
+    	catch (SQLException se)
+    	{
+    		notifyException(se);
+    		throw se;
+    	}
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java?rev=379545&r1=379544&r2=379545&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java Tue Feb 21 09:54:52 2006
@@ -52,22 +52,6 @@
 			throw se;
 		}
 	}
-	public final PreparedStatement prepareStatement(String sql,
-                                          int resultSetType,
-                                          int resultSetConcurrency,
-                                          int resultSetHoldability)
-										  throws SQLException {
-		try {
-			control.checkHoldCursors(resultSetHoldability);
-			return control.wrapStatement(
-				getRealConnection().prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability), sql, null);
-		}
-		catch (SQLException se)
-		{
-			notifyException(se);
-			throw se;
-		}
-	}
 	public final CallableStatement prepareCall(String sql,
                                      int resultSetType,
                                      int resultSetConcurrency,
@@ -140,19 +124,6 @@
 		}
 	}
 
-
-	public final int getHoldability()
-		throws SQLException
-	{
-		try {
-			return getRealConnection().getHoldability();
-		}
-		catch (SQLException se)
-		{
-			notifyException(se);
-			throw se;
-		}
-	}
 
 	public final void setHoldability(int holdability)
 		throws SQLException

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java?rev=379545&r1=379544&r2=379545&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java Tue Feb 21 09:54:52 2006
@@ -20,7 +20,6 @@
 
 package org.apache.derby.iapi.jdbc;
 
-import java.sql.Connection;
 import java.sql.SQLException;
 import java.sql.Statement;
 import java.sql.PreparedStatement;
@@ -34,7 +33,7 @@
 	/**
 		Return the real JDBC connection for the brokered connection.
 	*/
-	public Connection	getRealConnection() throws SQLException;
+	public EngineConnection	getRealConnection() throws SQLException;
 
 	/**
 		Notify the control class that a SQLException was thrown
@@ -100,23 +99,4 @@
 		Optionally wrap a CallableStatement with an CallableStatement.
 	*/
 	public CallableStatement wrapStatement(CallableStatement realStatement, String sql) throws SQLException;
-
-	/** Set drdaID of underlying connection 
-	 * @param drdaID - drdaId of connection
-	 */
-	public void setDrdaID(String drdaID);	
-
-	/**
-	 *  Set the internal isolation level to use for preparing statements.
-	 *  used for Network Server
-	 *  @param level - isolation level for prepared statements 
-	 */
-	public void setPrepareIsolation(int level) throws SQLException;
-
-	/**
-	 *  Get the internal isolation level to use for preparing statements.
-	 *  @return prepare isolation level
-	 */
-	public int getPrepareIsolation() throws SQLException;
-
 }

Added: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java?rev=379545&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java Tue Feb 21 09:54:52 2006
@@ -0,0 +1,86 @@
+/*
+
+   Derby - Class org.apache.derby.iapi.jdbc.EngineConnection
+
+   Copyright 2006 The Apache Software Foundation or its licensors, as applicable.
+
+   Licensed 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.derby.iapi.jdbc;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+import org.apache.derby.iapi.reference.SQLState;
+import org.apache.derby.iapi.sql.execute.ExecutionContext;
+import org.apache.derby.impl.jdbc.Util;
+
+/**
+ * Additional methods the embedded engine exposes on its Connection object
+ * implementations. An internal api only, mainly for the network
+ * server. Allows consistent interaction between EmbedConnections
+ * and BrokeredConnections.
+ * 
+ */
+public interface EngineConnection extends Connection {
+
+    /**
+     * Set the DRDA identifier for this connection.
+     */
+    public void setDrdaID(String drdaID);
+
+    /** 
+     * Set the transaction isolation level that will be used for the 
+     * next prepare.  Used by network server to implement DB2 style 
+     * isolation levels.
+     * Note the passed in level using the Derby constants from
+     * ExecutionContext and not the JDBC constants from java.sql.Connection.
+     * @param level Isolation level to change to.  level is the DB2 level
+     *               specified in the package names which happen to correspond
+     *               to our internal levels. If 
+     *               level == ExecutionContext.UNSPECIFIED_ISOLATION,
+     *               the statement won't be prepared with an isolation level.
+     * 
+     * 
+     */
+    public void setPrepareIsolation(int level) throws SQLException;
+
+    /**
+     * Return prepare isolation 
+     */
+    public int getPrepareIsolation()
+        throws SQLException;
+
+    /**
+     * Prepare a statement with holdability.
+     * Identical to JDBC 3.0 method, to allow holdabilty
+     * to be supported in JDK 1.3 by the network server,
+     * e.g. when the client is jdk 1.4 or above.
+     * Can be removed once JDK 1.3 is no longer supported.
+     */
+    public PreparedStatement prepareStatement(String sql, int resultSetType,
+            int resultSetConcurrency, int resultSetHoldability)
+            throws SQLException;
+
+    /**
+     * Get the holdability of the connection. 
+     * Identical to JDBC 3.0 method, to allow holdabilty
+     * to be supported in JDK 1.3 by the network server,
+     * e.g. when the client is jdk 1.4 or above.
+     * Can be removed once JDK 1.3 is no longer supported.
+     */
+    public int getHoldability() throws SQLException;
+
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=379545&r1=379544&r2=379545&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 Tue Feb 21 09:54:52 2006
@@ -34,6 +34,7 @@
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
 import org.apache.derby.iapi.jdbc.AuthenticationService;
+import org.apache.derby.iapi.jdbc.EngineConnection;
 
 import org.apache.derby.iapi.db.Database;
 import org.apache.derby.iapi.error.StandardException;
@@ -86,7 +87,7 @@
  * @see TransactionResourceImpl
  *
  */
-public class EmbedConnection implements java.sql.Connection
+public class EmbedConnection implements EngineConnection
 {
 
 	private static final StandardException exceptionClose = StandardException.closeException();

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java?rev=379545&r1=379544&r2=379545&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java Tue Feb 21 09:54:52 2006
@@ -30,6 +30,7 @@
 import org.apache.derby.impl.jdbc.EmbedConnection;
 import org.apache.derby.iapi.jdbc.BrokeredConnection;
 import org.apache.derby.iapi.jdbc.BrokeredConnectionControl;
+import org.apache.derby.iapi.jdbc.EngineConnection;
 
 
 import java.sql.Connection;
@@ -278,7 +279,8 @@
 
 	// called by ConnectionHandle when it needs to forward things to the
 	// underlying connection
-	public synchronized Connection getRealConnection() throws SQLException
+	public synchronized EngineConnection getRealConnection()
+       throws SQLException
 	{
 		checkActive();
 
@@ -428,41 +430,6 @@
 	*/
 	public CallableStatement wrapStatement(CallableStatement cs, String sql) throws SQLException {
 		return cs;
-	}
-
-	/**
-	 * set DrdaId for this connection. 
-	 * Used by network server to identify connection.
-	 * @param  drdaID drda connection identifier
-	 */
-	public   void setDrdaID(String drdaID)
-	{
-		realConnection.setDrdaID(drdaID);
-	}
-
-	/**
-	 *  Set the internal isolation level to use for preparing statements.
-	 *  Subsequent prepares will use this isoalation level
-	 * @param level internal isolation level 
-	 *
-	 * @throws SQLException
-	 * @see BrokeredConnection#setPrepareIsolation
-	 * 
-	 */
-	public  void setPrepareIsolation(int level) throws SQLException
-	{
-		realConnection.setPrepareIsolation(level);
-	}
-	
-	/** 
-	 * Get prepare isolation level.
-	 * For network server this will be the isolation level at which statements
-	 * will be prepared.
-	 * @return isolation level
-	 */
-	public  int getPrepareIsolation() throws SQLException
-	{
-		return realConnection.getPrepareIsolation();
 	}
     
     /** 

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java?rev=379545&r1=379544&r2=379545&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java Tue Feb 21 09:54:52 2006
@@ -27,6 +27,7 @@
 import org.apache.derby.impl.jdbc.EmbedConnection;
 import org.apache.derby.impl.jdbc.TransactionResourceImpl;
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.jdbc.EngineConnection;
 import org.apache.derby.iapi.jdbc.ResourceAdapter;
 import org.apache.derby.iapi.jdbc.BrokeredConnection;
 
@@ -832,9 +833,9 @@
 		// do local work with conn
 		// need to create new connection here.
 	*/
-	public Connection getRealConnection() throws SQLException
+	public EngineConnection getRealConnection() throws SQLException
 	{
-		Connection rc = super.getRealConnection();
+        EngineConnection rc = super.getRealConnection();
 		if (rc != null)
 			return rc;