Author: jfuerth
Date: Fri Sep  5 15:44:22 2008
New Revision: 2704

Modified:
   trunk/src/ca/sqlpower/architect/SQLObject.java

Log:
Temporary "sticky tape and bubblegum" fix for bug 1640. Although this fix was based on a promising hunch, and it does make the symptom disappear, we can't prove that it is an effective fix, and we do not understand why it works (the hunch that led us to try this turned out to be false, even though the fix itself works).

If we did understand why this works (or we can come to understand it later), we have to refactor this code so the RelationshipManager is not a listener anymore, but it gets notified separately and explicitly when necessary.

Modified: trunk/src/ca/sqlpower/architect/SQLObject.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/SQLObject.java      (original)
+++ trunk/src/ca/sqlpower/architect/SQLObject.java      Fri Sep  5 15:44:22 2008
@@ -25,6 +25,7 @@

 import org.apache.log4j.Logger;

+import ca.sqlpower.architect.SQLRelationship.RelationshipManager;
 import ca.sqlpower.architect.undo.UndoCompoundEvent;
 import ca.sqlpower.architect.undo.UndoCompoundEventListener;
 import ca.sqlpower.architect.undo.UndoCompoundEvent.EventTypes;
@@ -342,10 +343,23 @@
                         (SQLObject[]) newChildren.toArray(new 
SQLObject[newChildren.size()]));
                synchronized(sqlObjectListeners) {
                    int count = 0;
+               
+ // XXX Notifying the RelationshipManager last is a workaround for an elusive bug + // we are still trying to nail down. This is not intended to be used long term, + // and is definitely not an example of good practice! See bug 1640 for details.
+               
for (SQLObjectListener l : new ArrayList<SQLObjectListener>(sqlObjectListeners)) {
-                               count++;
-                               l.dbChildrenInserted(e);
-                       }
+                if (!(l instanceof RelationshipManager)) {
+                    count++;
+                    l.dbChildrenInserted(e);
+                }
+            }
+ for (SQLObjectListener l : new ArrayList<SQLObjectListener>(sqlObjectListeners)) {
+                if (l instanceof RelationshipManager) {
+                    count++;
+                    l.dbChildrenInserted(e);
+                }
+            }
                        logger.debug(getClass().getName()+": notified "+count+" 
listeners");
                }
        }
@@ -411,10 +425,11 @@
                int count = 0;
                synchronized(sqlObjectListeners) {
SQLObjectListener[] listeners = sqlObjectListeners.toArray(new SQLObjectListener[0]);
-                       for(int i = listeners.length-1;i>=0;i--) {
-                               count++;
-                               listeners[i].dbObjectChanged(e);
-                       }
+//            for(int i = listeners.length-1;i>=0;i--) {
+                       for (int i = 0; i < listeners.length; i++) {
+                           listeners[i].dbObjectChanged(e);
+                           count++;
+            }
                }
if (logger.isDebugEnabled()) logger.debug("Notified "+count+" listeners.");
        }

Reply via email to