Revision: 3580
Author: [email protected]
Date: Tue Jun  1 09:02:37 2010
Log: Fix for bug 2836. The OLAP objects should not fire a child added event if it set a property that is considered a child to null.
http://code.google.com/p/power-architect/source/detail?r=3580

Added:
 /trunk/regress/ca/sqlpower/architect/olap/CubeTest.java
Modified:
 /trunk/src/main/java/ca/sqlpower/architect/olap/MondrianModel.java
 /trunk/src/main/java/ca/sqlpower/architect/olap/xml-to-java-classes.xsl

=======================================
--- /dev/null
+++ /trunk/regress/ca/sqlpower/architect/olap/CubeTest.java Tue Jun 1 09:02:37 2010
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of Power*Architect.
+ *
+ * Power*Architect is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Power*Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect.olap;
+
+import junit.framework.TestCase;
+import ca.sqlpower.architect.olap.MondrianModel.Cube;
+import ca.sqlpower.architect.olap.MondrianModel.Relation;
+import ca.sqlpower.architect.olap.MondrianModel.Table;
+import ca.sqlpower.object.PersistedSPObjectTest.CountingSPListener;
+
+public class CubeTest extends TestCase {
+
+    /**
+ * Regression test for removing a child from an OLAP object that is a single + * child. For some cases, like the cube, there is a child object that the + * parent can only have one of, like the cube's fact child. When this child + * type is removed by calling remove or setting the child to null a child
+     * added event should not be fired.
+     */
+    public void testRemoveSingleChild() throws Exception {
+        Cube cube = new Cube();
+        Relation relation = new Table();
+        cube.setFact(relation);
+
+        CountingSPListener listener = new CountingSPListener();
+        cube.addSPListener(listener);
+
+        cube.removeChild(relation);
+
+        assertEquals(0, listener.getChildAddedCount());
+    }
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/olap/MondrianModel.java Tue Mar 23 13:58:01 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/olap/MondrianModel.java Tue Jun 1 09:02:37 2010
@@ -1200,8 +1200,8 @@
         fact = newval;
         if (fact != null) {
             fact.setParent(this);
-        }
-        fireChildAdded(Relation.class, fact, overallPosition);
+            fireChildAdded(Relation.class, fact, overallPosition);
+        }
        }

     /**  */
@@ -1790,8 +1790,8 @@
         cubeUsage = newval;
         if (cubeUsage != null) {
             cubeUsage.setParent(this);
-        }
-        fireChildAdded(CubeUsages.class, cubeUsage, overallPosition);
+            fireChildAdded(CubeUsages.class, cubeUsage, overallPosition);
+        }
        }

     /**  */
@@ -3865,8 +3865,8 @@
         relation = newval;
         if (relation != null) {
             relation.setParent(this);
-        }
-        fireChildAdded(RelationOrJoin.class, relation, overallPosition);
+ fireChildAdded(RelationOrJoin.class, relation, overallPosition);
+        }
        }

     /**  */
@@ -4650,8 +4650,8 @@
         keyExp = newval;
         if (keyExp != null) {
             keyExp.setParent(this);
-        }
-        fireChildAdded(KeyExpression.class, keyExp, overallPosition);
+            fireChildAdded(KeyExpression.class, keyExp, overallPosition);
+        }
        }

     /**
@@ -4678,8 +4678,8 @@
         nameExp = newval;
         if (nameExp != null) {
             nameExp.setParent(this);
-        }
-        fireChildAdded(NameExpression.class, nameExp, overallPosition);
+            fireChildAdded(NameExpression.class, nameExp, overallPosition);
+        }
        }

     /**
@@ -4705,8 +4705,8 @@
         ordinalExp = newval;
         if (ordinalExp != null) {
             ordinalExp.setParent(this);
-        }
- fireChildAdded(OrdinalExpression.class, ordinalExp, overallPosition); + fireChildAdded(OrdinalExpression.class, ordinalExp, overallPosition);
+        }
        }

     /**
@@ -4733,8 +4733,8 @@
         parentExp = newval;
         if (parentExp != null) {
             parentExp.setParent(this);
-        }
-        fireChildAdded(ParentExpression.class, parentExp, overallPosition);
+ fireChildAdded(ParentExpression.class, parentExp, overallPosition);
+        }
        }

     /**  */
@@ -4758,8 +4758,8 @@
         closure = newval;
         if (closure != null) {
             closure.setParent(this);
-        }
-        fireChildAdded(Closure.class, closure, overallPosition);
+            fireChildAdded(Closure.class, closure, overallPosition);
+        }
        }

     /**  */
@@ -5118,8 +5118,8 @@
         table = newval;
         if (table != null) {
             table.setParent(this);
-        }
-        fireChildAdded(Table.class, table, overallPosition);
+            fireChildAdded(Table.class, table, overallPosition);
+        }
        }


@@ -5767,8 +5767,8 @@
         measureExp = newval;
         if (measureExp != null) {
             measureExp.setParent(this);
-        }
- fireChildAdded(MeasureExpression.class, measureExp, overallPosition); + fireChildAdded(MeasureExpression.class, measureExp, overallPosition);
+        }
        }

     /**  */
@@ -6180,8 +6180,8 @@
         formulaElement = newval;
         if (formulaElement != null) {
             formulaElement.setParent(this);
-        }
-        fireChildAdded(Formula.class, formulaElement, overallPosition);
+            fireChildAdded(Formula.class, formulaElement, overallPosition);
+        }
        }

     /**  */
@@ -6725,8 +6725,8 @@
         formulaElement = newval;
         if (formulaElement != null) {
             formulaElement.setParent(this);
-        }
-        fireChildAdded(Formula.class, formulaElement, overallPosition);
+            fireChildAdded(Formula.class, formulaElement, overallPosition);
+        }
        }


@@ -7942,8 +7942,8 @@
         left = newval;
         if (left != null) {
             left.setParent(this);
-        }
-        fireChildAdded(RelationOrJoin.class, left, overallPosition);
+            fireChildAdded(RelationOrJoin.class, left, overallPosition);
+        }
        }

     /**  */
@@ -7967,8 +7967,8 @@
         right = newval;
         if (right != null) {
             right.setParent(this);
-        }
-        fireChildAdded(RelationOrJoin.class, right, overallPosition);
+            fireChildAdded(RelationOrJoin.class, right, overallPosition);
+        }
        }


@@ -8241,8 +8241,8 @@
         filter = newval;
         if (filter != null) {
             filter.setParent(this);
-        }
-        fireChildAdded(SQL.class, filter, overallPosition);
+            fireChildAdded(SQL.class, filter, overallPosition);
+        }
        }

     /**  */
@@ -8605,8 +8605,8 @@
         columnDefs = newval;
         if (columnDefs != null) {
             columnDefs.setParent(this);
-        }
-        fireChildAdded(ColumnDefs.class, columnDefs, overallPosition);
+            fireChildAdded(ColumnDefs.class, columnDefs, overallPosition);
+        }
        }

     /**  */
@@ -8630,8 +8630,8 @@
         rows = newval;
         if (rows != null) {
             rows.setParent(this);
-        }
-        fireChildAdded(Rows.class, rows, overallPosition);
+            fireChildAdded(Rows.class, rows, overallPosition);
+        }
        }


@@ -9781,8 +9781,8 @@
         factcount = newval;
         if (factcount != null) {
             factcount.setParent(this);
-        }
-        fireChildAdded(AggFactCount.class, factcount, overallPosition);
+            fireChildAdded(AggFactCount.class, factcount, overallPosition);
+        }
        }

     /**  */
@@ -13019,8 +13019,8 @@
         union = newval;
         if (union != null) {
             union.setParent(this);
-        }
-        fireChildAdded(Union.class, union, overallPosition);
+            fireChildAdded(Union.class, union, overallPosition);
+        }
        }


=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/olap/xml-to-java-classes.xsl Tue Mar 23 13:58:01 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/olap/xml-to-java-classes.xsl Tue Jun 1 09:02:37 2010
@@ -310,8 +310,8 @@
         <xsl:value-of select="@name"/> = newval;
         if (<xsl:value-of select="@name"/> != null) {
             <xsl:value-of select="@name"/>.setParent(this);
-        }
- fireChildAdded(<xsl:call-template name="attribute-type"/>.class, <xsl:value-of select="@name"/>, overallPosition); + fireChildAdded(<xsl:call-template name="attribute-type"/>.class, <xsl:value-of select="@name"/>, overallPosition);
+        }
        }
 </xsl:template>

Reply via email to