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/03/13 16:29:50 UTC

svn commit: r385570 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc: EmbedPreparedStatement.java EmbedResultSet.java EmbedStatement.java

Author: djd
Date: Mon Mar 13 07:29:49 2006
New Revision: 385570

URL: http://svn.apache.org/viewcvs?rev=385570&view=rev
Log:
DERBY-1095 (partial) Clean up close methods on EmbedResultSet, mark the ResultSet
as closed (isClosed=true) once it discovers its Connection is closed.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java?rev=385570&r1=385569&r2=385570&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedPreparedStatement.java Mon Mar 13 07:29:49 2006
@@ -200,7 +200,7 @@
 
 		@exception SQLException	thrown on failure
 	 */
-	protected void closeActions() throws SQLException {
+	void closeActions() throws SQLException {
 
 		//we release the resource for preparedStatement
 		preparedStatement = null;

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?rev=385570&r1=385569&r2=385570&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 Mon Mar 13 07:29:49 2006
@@ -102,7 +102,17 @@
 	//deleteRow & updateRow make rowData null so that ResultSet is not positioned on deleted/updated row.
 	private DataValueDescriptor[] rowData;
 	protected boolean wasNull;
-	protected boolean isClosed;
+    
+    /**
+     * Set if this ResultSet is definitely closed.
+     * If the connection has been closed, or the database
+     *  or system shutdown but the ResultSet has not been
+     *  closed explictly then this may be false. Once
+     *  this object detects the connection is closed
+     *  isClosed will be set to true.
+     */
+    boolean isClosed;
+    
 	private boolean isOnInsertRow;
 	private ExecRow currentRowBeforeInsert;
 	private ExecRow insertRow = null;
@@ -3966,7 +3976,7 @@
 	 * Documented behaviour for streams is that they are implicitly closed on
 	 * the next get*() method call.
 	 */
-	protected final void closeCurrentStream() {
+	private final void closeCurrentStream() {
 
 		if (currentStream != null) {
 			try {
@@ -3995,20 +4005,33 @@
 	 *
 	 * @exception SQLException		Thrown if this ResultSet is closed.
 	 */
-	protected final void checkIfClosed(String operation) throws SQLException {
+	final void checkIfClosed(String operation) throws SQLException {
 		if (isClosed) {
 			throw newSQLException(SQLState.LANG_RESULT_SET_NOT_OPEN, operation);
 		}
 	}
 
-	protected final void checkExecIfClosed(String operation) throws SQLException {
+    /**
+     * Throw an exception if this ResultSet is closed or its
+     * Connection has been closed. If the ResultSet has not
+     * been explictly closed but the Connection is closed,
+     * then this ResultSet will be marked as closed.
+     */
+	final void checkExecIfClosed(String operation) throws SQLException {
 		
 		checkIfClosed(operation);
 
 		java.sql.Connection appConn = getEmbedConnection().getApplicationConnection();
 
-		if ((appConn == null) || appConn.isClosed())
+        // Currently disconnected, i.e. a detached gobal transaction
+        if (appConn == null)
+            throw Util.noCurrentConnection();
+            
+		if (appConn.isClosed()) {
+            closeCurrentStream();
+            isClosed = true;
 			throw Util.noCurrentConnection();
+        }
 	}
     
 	/**
@@ -4045,7 +4068,7 @@
 	/*
 	 * close result set if we have a transaction level error 
 	 */
-	protected final SQLException closeOnTransactionError(Throwable thrownException) throws SQLException
+	final SQLException closeOnTransactionError(Throwable thrownException) throws SQLException
 	{
 		SQLException sqle = handleException(thrownException);
 		if (thrownException instanceof StandardException)

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java
URL: http://svn.apache.org/viewcvs/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java?rev=385570&r1=385569&r2=385570&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 Mon Mar 13 07:29:49 2006
@@ -275,7 +275,7 @@
 
 	// allow sub-classes to execute additional close
 	// logic while holding the synchronization.
-	protected void closeActions() throws SQLException {
+	void closeActions() throws SQLException {
 	}
 
     //----------------------------------------------------------------------
@@ -939,8 +939,10 @@
 		checkStatus();
 
     	java.sql.Connection appConn = getEmbedConnection().getApplicationConnection();
-		if ((appConn != applicationConnection) || (appConn == null))
+		if ((appConn != applicationConnection) || (appConn == null)) {
+
 			throw Util.noCurrentConnection();
+        }
 		return appConn;
     }
 
@@ -995,8 +997,7 @@
 
 
 				try {
-					if (!lrs.isClosed)
-						lrs.close();
+					lrs.close();
 				} catch (SQLException sqle) {
 					if (se == null)
 						se = sqle;
@@ -1241,7 +1242,7 @@
 
 	//check the status of this statement, if it has already been closed,
     //we throw an exception, need to be called by every public method
-    protected final void checkStatus() throws SQLException {
+    final void checkStatus() throws SQLException {
 
 		if (!active)
 			throw newSQLException(SQLState.ALREADY_CLOSED, "Statement");
@@ -1261,7 +1262,7 @@
 		// getConnection() checks if the Statement is closed
 		if (!getConnection().isClosed())
 			return;
-	
+              	
 		throw Util.noCurrentConnection();
 	}
 
@@ -1305,8 +1306,7 @@
 					continue;
 
 				try {
-					if (!lrs.isClosed)
-						lrs.close();
+					lrs.close();
 				} catch (SQLException sdynamic) {
 					if (sqle == null)
 						sqle = sdynamic;