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/28 21:33:09 UTC

svn commit: r381773 - in /db/derby/code/branches/10.1/java/engine/org/apache/derby: iapi/jdbc/ impl/jdbc/ jdbc/

Author: djd
Date: Tue Feb 28 12:33:07 2006
New Revision: 381773

URL: http://svn.apache.org/viewcvs?rev=381773&view=rev
Log:
DERBY-1015 Add EngineConnection to create interface between network server and engine.
Integration of 379545 from trunk.

Added:
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java   (props changed)
      - copied unchanged from r379545, db/derby/code/trunk/java/engine/org/apache/derby/iapi/jdbc/EngineConnection.java
Modified:
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
    db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java?rev=381773&r1=381772&r2=381773&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection.java Tue Feb 28 12:33:07 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
@@ -370,7 +370,7 @@
 	  *
 	  *	@return	the current connection
 	  */
-	protected final Connection getRealConnection() throws SQLException {
+	final EngineConnection getRealConnection() throws SQLException {
 		if (isClosed)
 			throw Util.noCurrentConnection();
 
@@ -387,20 +387,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(); 
 	}
 
 	/**
@@ -410,7 +402,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();
 		}
@@ -466,9 +458,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.
+        }
 	}
 
 	/**
@@ -479,9 +477,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);
 	}
 
 	/**
@@ -492,9 +490,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();
 	}
             
     /**
@@ -528,4 +526,41 @@
     }
 
 	protected 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/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java?rev=381773&r1=381772&r2=381773&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnection30.java Tue Feb 28 12:33:07 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/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java?rev=381773&r1=381772&r2=381773&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/iapi/jdbc/BrokeredConnectionControl.java Tue Feb 28 12:33:07 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;
-
 }

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

Modified: db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java?rev=381773&r1=381772&r2=381773&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/impl/jdbc/EmbedConnection.java Tue Feb 28 12:33:07 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/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java?rev=381773&r1=381772&r2=381773&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedPooledConnection.java Tue Feb 28 12:33:07 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/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java
URL: http://svn.apache.org/viewcvs/db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java?rev=381773&r1=381772&r2=381773&view=diff
==============================================================================
--- db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java (original)
+++ db/derby/code/branches/10.1/java/engine/org/apache/derby/jdbc/EmbedXAConnection.java Tue Feb 28 12:33:07 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;