db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r614536 - /db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
Date Wed, 23 Jan 2008 14:12:05 GMT
Author: kristwaa
Date: Wed Jan 23 06:12:02 2008
New Revision: 614536

URL: http://svn.apache.org/viewvc?rev=614536&view=rev
Log:
DERBY-3308: Broken synchronization for event handling in ClientPooledConnection40.
Patch file: derby-3308-1b-eventlisteners_synchronization.diff

Modified:
    db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java

Modified: db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java?rev=614536&r1=614535&r2=614536&view=diff
==============================================================================
--- db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
(original)
+++ db/derby/code/trunk/java/client/org/apache/derby/client/ClientPooledConnection40.java
Wed Jan 23 06:12:02 2008
@@ -23,7 +23,7 @@
 
 import java.sql.PreparedStatement;
 import java.sql.SQLException;
-import java.util.Vector;
+import java.util.ArrayList;
 import javax.sql.StatementEventListener;
 import javax.sql.StatementEvent;
 import org.apache.derby.jdbc.ClientBaseDataSource;
@@ -37,9 +37,11 @@
  */
 
 public class ClientPooledConnection40 extends ClientPooledConnection {
-    //using generics to avoid casting problems
-     protected final Vector<StatementEventListener> statementEventListeners = 
-             new Vector<StatementEventListener>();
+    
+    /** List of statement event listeners. */
+    //@GuardedBy("this")
+    private final ArrayList<StatementEventListener> statementEventListeners = 
+             new ArrayList<StatementEventListener>();
 
     public ClientPooledConnection40(ClientBaseDataSource ds,
         org.apache.derby.client.am.LogWriter logWriter,
@@ -71,11 +73,11 @@
      *                  interface and wants to be notified of Statement closed or 
      *                  or Statement error occurred events
      */
-    public void addStatementEventListener(StatementEventListener listener){
+    public synchronized void addStatementEventListener(StatementEventListener listener){
         if (logWriter_ != null) {
             logWriter_.traceEntry(this, "addStatementEventListener", listener);
         }
-        statementEventListeners.addElement(listener);
+        statementEventListeners.add(listener);
     }
     
     /**
@@ -87,11 +89,11 @@
      * @param listener The previously registered event listener that needs to be
      *                 removed from the list of components
      */
-    public void removeStatementEventListener(StatementEventListener listener){
+    public synchronized void removeStatementEventListener(StatementEventListener listener){
         if (logWriter_ != null) {
             logWriter_.traceEntry(this, "removeConnectionEventListener", listener);
         }
-        statementEventListeners.removeElement(listener);
+        statementEventListeners.remove(listener);
     }
     
     /**
@@ -102,15 +104,11 @@
      * @param statement The PreparedStatement that was closed
      *
      */
-    public void onStatementClose(PreparedStatement statement) {
+    public synchronized void onStatementClose(PreparedStatement statement) {
         if (!statementEventListeners.isEmpty()) {
             StatementEvent event = new StatementEvent(this,statement);
-            //synchronized block on statementEventListeners to make it thread
-            //safe
-            synchronized(statementEventListeners) {
-                for (StatementEventListener l : statementEventListeners) {
-                    l.statementClosed(event);
-                }
+            for (StatementEventListener l : statementEventListeners) {
+                l.statementClosed(event);
             }
         }
     }
@@ -125,16 +123,13 @@
      *                  caused the invalidation of the PreparedStatements
      *
      */
-    public void onStatementErrorOccurred(PreparedStatement statement,
-                    SQLException sqle) {
+    public synchronized void onStatementErrorOccurred(
+                                                    PreparedStatement statement,
+                                                    SQLException sqle) {
         if (!statementEventListeners.isEmpty()) {
             StatementEvent event = new StatementEvent(this,statement,sqle);
-            //synchronized block on statementEventListeners to make it thread
-            //safe
-            synchronized(statementEventListeners) {
-                for (StatementEventListener l : statementEventListeners) {
-                    l.statementErrorOccurred(event);
-                }
+            for (StatementEventListener l : statementEventListeners) {
+                l.statementErrorOccurred(event);
             }
         }
     }   



Mime
View raw message