db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r618639 - /db/derby/code/branches/10.2/java/client/org/apache/derby/client/ClientPooledConnection40.java
Date Tue, 05 Feb 2008 13:15:57 GMT
Author: kristwaa
Date: Tue Feb  5 05:15:55 2008
New Revision: 618639

URL: http://svn.apache.org/viewvc?rev=618639&view=rev
Log:
DERBY-3308: Broken synchronization for event handling in ClientPooledConnection40. Merged
revision 614536 from trunk (10.4).

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

Modified: db/derby/code/branches/10.2/java/client/org/apache/derby/client/ClientPooledConnection40.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.2/java/client/org/apache/derby/client/ClientPooledConnection40.java?rev=618639&r1=618638&r2=618639&view=diff
==============================================================================
--- db/derby/code/branches/10.2/java/client/org/apache/derby/client/ClientPooledConnection40.java
(original)
+++ db/derby/code/branches/10.2/java/client/org/apache/derby/client/ClientPooledConnection40.java
Tue Feb  5 05:15:55 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,
@@ -76,11 +78,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);
     }
     
     /**
@@ -92,11 +94,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);
     }
     
     /**
@@ -107,15 +109,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);
             }
         }
     }
@@ -130,16 +128,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