db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kahat...@apache.org
Subject svn commit: r566981 - in /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc: EmbedResultSet.java EmbedStatement.java
Date Fri, 17 Aug 2007 09:32:54 GMT
Author: kahatlen
Date: Fri Aug 17 02:32:53 2007
New Revision: 566981

URL: http://svn.apache.org/viewvc?view=rev&rev=566981
Log:
DERBY-3004: Get rid of the finalizer in EmbedResultSet

Moved code from EmbedResultSet.finalize() to EmbedStatement.finalize()
to make allocation and garbage collection of EmbedResultSet objects
cheaper (ResultSets are normally allocated more frequently than
Statements).

Modified:
    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/EmbedResultSet.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java?view=diff&rev=566981&r1=566980&r2=566981
==============================================================================
--- 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 Aug
17 02:32:53 2007
@@ -129,9 +129,10 @@
 	 for a single execution Activation. Ie.
 	 a ResultSet from a Statement.executeQuery().
 	 In this case the closing of this ResultSet will close
-	 the activation or the finalization of the ResultSet
+	 the activation or the finalization of the parent EmbedStatement
 	 without it being closed will mark the Activation as unused.
-	 c.f. EmbedPreparedStatement.finalize().
+	 @see EmbedStatement#finalize()
+	 @see EmbedPreparedStatement#finalize()
     */
 	Activation singleUseActivation;
 
@@ -291,21 +292,6 @@
 			maxFieldSize = 0;
 
 		order = conn.getResultSetOrderId();
-	}
-
-	/**
-		JDBC states that a ResultSet is closed when garbage collected.
-		We simply mark the activation as unused. Some later use
-		of the connection will clean everything up.
-
-		@exception Throwable Allows any exception to be thrown during finalize
-	*/
-	protected void finalize() throws Throwable {
-		super.finalize();
-
-		if (singleUseActivation != null) {
-			singleUseActivation.markUnused();
-		}		
 	}
 
 	private void checkNotOnInsertRow() throws SQLException {

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?view=diff&rev=566981&r1=566980&r2=566981
==============================================================================
--- 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 Aug
17 02:32:53 2007
@@ -76,7 +76,7 @@
     protected EngineStatement applicationStatement;
 
 	int updateCount = -1;
-	java.sql.ResultSet results;
+	EmbedResultSet results;
 	//for jdbc3.0 feature, where you can get a resultset of rows inserted
 	//for auto generated columns after an insert
 	private java.sql.ResultSet autoGeneratedKeysResultSet;
@@ -319,6 +319,28 @@
 		  batchStatements = null;
 	  }
 	}
+
+    /**
+     * Mark the statement and its single-use activation as unused. This method
+     * should be called from <code>EmbedPreparedStatement</code>'s finalizer
as
+     * well, even though prepared statements reuse activations, since
+     * <code>getGeneratedKeys()</code> uses a single-use activation regardless
+     * of statement type.
+     */
+    protected void finalize() throws Throwable {
+        super.finalize();
+
+        // We mark the activation as not being used and
+        // that is it.  We rely on the connection to sweep
+        // through the activations to find the ones that
+        // aren't in use, and to close them.  We cannot
+        // do a activation.close() here because there are
+        // synchronized methods under close that cannot
+        // be called during finalization.
+        if (results != null && results.singleUseActivation != null) {
+            results.singleUseActivation.markUnused();
+        }
+    }
 
 	// allow sub-classes to execute additional close
 	// logic while holding the synchronization.



Mime
View raw message