Revision: 3303
Author: [email protected]
Date: Wed Feb 17 14:19:51 2010
Log: Updated some of the profile classes to conform with the persisters. Setters and child methods now fire expected events and the annotations exist for the ColumnProfileResult. The tests for the ColumnProfileResult exist and pass as well.
An Architect specific new value maker exists for the new persister tests.
http://code.google.com/p/power-architect/source/detail?r=3303

Added:
 /trunk/regress/ca/sqlpower/architect/profile/ColumnProfileResultTest.java
 /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
Modified:
 /trunk/src/ca/sqlpower/architect/profile/AbstractProfileResult.java
 /trunk/src/ca/sqlpower/architect/profile/ColumnProfileResult.java
 /trunk/src/ca/sqlpower/architect/profile/TableProfileResult.java

=======================================
--- /dev/null
+++ /trunk/regress/ca/sqlpower/architect/profile/ColumnProfileResultTest.java Wed Feb 17 14:19:51 2010
@@ -0,0 +1,76 @@
+/*
+ * 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.profile;
+
+import ca.sqlpower.architect.enterprise.ArchitectPersisterSuperConverter;
+import ca.sqlpower.architect.util.ArchitectNewValueMaker;
+import ca.sqlpower.dao.session.SessionPersisterSuperConverter;
+import ca.sqlpower.object.PersistedSPObjectTest;
+import ca.sqlpower.object.SPObject;
+import ca.sqlpower.sql.DataSourceCollection;
+import ca.sqlpower.sql.SPDataSource;
+import ca.sqlpower.sqlobject.SQLColumn;
+import ca.sqlpower.sqlobject.SQLTable;
+import ca.sqlpower.testutil.GenericNewValueMaker;
+import ca.sqlpower.testutil.NewValueMaker;
+
+public class ColumnProfileResultTest extends PersistedSPObjectTest {
+
+    private ColumnProfileResult profile;
+
+    public ColumnProfileResultTest(String name) {
+        super(name);
+    }
+
+    @Override
+ public NewValueMaker createNewValueMaker(SPObject root, DataSourceCollection<SPDataSource> dsCollection) {
+        return new ArchitectNewValueMaker(root, dsCollection);
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+ NewValueMaker valueMaker = new GenericNewValueMaker(getRootObject()); + SQLColumn column = (SQLColumn) valueMaker.makeNewValue(SQLColumn.class, null, "column for testing");
+        SQLTable table = column.getParent();
+        ProfileSettings settings = new ProfileSettings();
+ TableProfileResult tableProfile = new TableProfileResult(table, settings);
+        getRootObject().addChild(tableProfile, 0);
+        profile = new ColumnProfileResult(column, tableProfile);
+        tableProfile.addColumnProfileResult(profile);
+    }
+
+    @Override
+    protected Class<? extends SPObject> getChildClassType() {
+        return ColumnValueCount.class;
+    }
+
+    @Override
+    public SPObject getSPObjectUnderTest() {
+        return profile;
+    }
+
+    @Override
+    public SessionPersisterSuperConverter getConverter() {
+ return new ArchitectPersisterSuperConverter(getPLIni(), getRootObject());
+    }
+
+}
=======================================
--- /dev/null
+++ /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java Wed Feb 17 14:19:51 2010
@@ -0,0 +1,62 @@
+/*
+ * 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.util;
+
+import ca.sqlpower.architect.profile.ColumnValueCount;
+import ca.sqlpower.architect.profile.ProfileSettings;
+import ca.sqlpower.architect.profile.TableProfileResult;
+import ca.sqlpower.object.SPObject;
+import ca.sqlpower.sql.DataSourceCollection;
+import ca.sqlpower.sql.SPDataSource;
+import ca.sqlpower.sqlobject.SQLTable;
+import ca.sqlpower.testutil.GenericNewValueMaker;
+
+public class ArchitectNewValueMaker extends GenericNewValueMaker {
+
+    public ArchitectNewValueMaker(SPObject root) {
+        super(root);
+    }
+
+ public ArchitectNewValueMaker(SPObject root, DataSourceCollection<SPDataSource> dsCollection) {
+        super(root, dsCollection);
+    }
+
+    @Override
+ public Object makeNewValue(Class<?> valueType, Object oldVal, String propName) {
+        if (valueType == ProfileSettings.class) {
+            ProfileSettings settings = new ProfileSettings();
+            getRootObject().addChild(settings, 0);
+            return settings;
+        } else if (valueType == TableProfileResult.class) {
+            TableProfileResult tpr = new TableProfileResult(
+                    (SQLTable) makeNewValue(SQLTable.class, null, ""),
+ (ProfileSettings) makeNewValue(ProfileSettings.class, null, ""));
+            getRootObject().addChild(tpr, 0);
+            return tpr;
+        } else if (valueType == ColumnValueCount.class) {
+ ColumnValueCount cvc = new ColumnValueCount(Integer.MAX_VALUE, 2, 42);
+            getRootObject().addChild(cvc, 0);
+            return cvc;
+        } else {
+            return super.makeNewValue(valueType, oldVal, propName);
+        }
+    }
+
+}
=======================================
--- /trunk/src/ca/sqlpower/architect/profile/AbstractProfileResult.java Thu Jan 28 12:23:55 2010 +++ /trunk/src/ca/sqlpower/architect/profile/AbstractProfileResult.java Wed Feb 17 14:19:51 2010
@@ -29,6 +29,9 @@
 import ca.sqlpower.object.ObjectDependentException;
 import ca.sqlpower.object.SPObject;
 import ca.sqlpower.object.SPObjectUtils;
+import ca.sqlpower.object.annotation.Accessor;
+import ca.sqlpower.object.annotation.Mutator;
+import ca.sqlpower.object.annotation.Transient;
 import ca.sqlpower.sqlobject.SQLCatalog;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLDatabase;
@@ -77,6 +80,7 @@
     /* (non-Javadoc)
* @see ca.sqlpower.architect.profile.ProfileResultInterface#getProfiledObject()
      */
+    @Accessor
     public T getProfiledObject() {
         return profiledObject;
     }
@@ -84,6 +88,7 @@
     /* (non-Javadoc)
* @see ca.sqlpower.architect.profile.ProfileResultInterface#getCreateStartTime()
      */
+    @Accessor
     public long getCreateStartTime() {
         return createStartTime;
     }
@@ -91,13 +96,17 @@
     /* (non-Javadoc)
* @see ca.sqlpower.architect.profile.ProfileResultInterface#setCreateStartTime(long)
      */
+    @Mutator
     public void setCreateStartTime(long createStartTime) {
+        long oldStartTime = this.createStartTime;
         this.createStartTime = createStartTime;
+ firePropertyChange("createStartTime", oldStartTime, createStartTime);
     }

     /* (non-Javadoc)
* @see ca.sqlpower.architect.profile.ProfileResultInterface#getTimeToCreate()
      */
+    @Transient @Accessor
     public long getTimeToCreate() {
         return createEndTime-createStartTime;
     }
@@ -105,13 +114,17 @@
     /* (non-Javadoc)
* @see ca.sqlpower.architect.profile.ProfileResultInterface#setCreateEndTime(long)
      */
+    @Mutator
     public void setCreateEndTime(long createEndTime) {
+        long oldEndTime = this.createEndTime;
         this.createEndTime = createEndTime;
+        firePropertyChange("createEndTime", oldEndTime, createEndTime);
     }

     /* (non-Javadoc)
* @see ca.sqlpower.architect.profile.ProfileResultInterface#getCreateEndTime()
      */
+    @Accessor
     public long getCreateEndTime() {
         return createEndTime;
     }
@@ -119,6 +132,7 @@
     /* (non-Javadoc)
* @see ca.sqlpower.architect.profile.ProfileResultInterface#getException()
      */
+    @Transient @Accessor
     public Exception getException() {
         return ex;
     }
@@ -127,8 +141,11 @@
      * If an exception is encountered while populating this profile result,
      * it should be stored here for later inspection by client code.
      */
+    @Transient @Mutator
     public void setException(Exception ex) {
+        Exception oldEx = this.ex;
         this.ex = ex;
+        firePropertyChange("exception", oldEx, ex);
     }

     /**
@@ -257,12 +274,16 @@
         return hash;
     }

+    @Accessor
     public ProfileSettings getSettings() {
         return settings;
     }

+    @Mutator
     public void setSettings(ProfileSettings settings) {
+        ProfileSettings oldSettings = this.settings;
         this.settings = settings;
+        firePropertyChange("settings", oldSettings, settings);
     }

     public void addProfileResultListener(ProfileResultListener listener) {
@@ -300,6 +321,7 @@
     public List<? extends SPObject> getDependencies() {
         List<SPObject> dependencies = new ArrayList<SPObject>();
         dependencies.add(profiledObject);
+        dependencies.add(settings);
         return dependencies;
     }

@@ -310,7 +332,7 @@
      * ProfileManagerImpl will when a child TableProfileResult is removed.
      */
     public void removeDependency(SPObject dependency) {
-        if (dependency == getDependencies().get(0)) {
+        if (getDependencies().contains(dependency)) {
             try {
                 getParent().removeChild(this);
             } catch (ObjectDependentException e) {
=======================================
--- /trunk/src/ca/sqlpower/architect/profile/ColumnProfileResult.java Fri Feb 12 07:43:48 2010 +++ /trunk/src/ca/sqlpower/architect/profile/ColumnProfileResult.java Wed Feb 17 14:19:51 2010
@@ -193,13 +193,28 @@

ColumnValueCount columnValueCount = new ColumnValueCount(value,count, per);
         if (!topTen.contains(columnValueCount)) {
-            topTen.add(columnValueCount);
+            addValueCount(columnValueCount);
logger.debug("Added Value Count: Value: " + value + " Count: " + count);
         }
     }

     public void addValueCount(ColumnValueCount value) {
+        addColumnValueCount(value, topTen.size());
+    }
+
+    private void addColumnValueCount(ColumnValueCount value, int index) {
         topTen.add(value);
+        fireChildAdded(ColumnValueCount.class, value, index);
+    }
+
+    @Override
+    protected void addChildImpl(SPObject child, int index) {
+        if (child instanceof ColumnValueCount) {
+            addColumnValueCount((ColumnValueCount) child, index);
+        } else {
+ throw new IllegalArgumentException("Cannot add child " + child + " to " + this);
+        }
+
     }

     @NonProperty
=======================================
--- /trunk/src/ca/sqlpower/architect/profile/TableProfileResult.java Thu Feb 11 11:47:13 2010 +++ /trunk/src/ca/sqlpower/architect/profile/TableProfileResult.java Wed Feb 17 14:19:51 2010
@@ -208,7 +208,23 @@
      * Adds a new column profile result to the end of the result list.
      */
     public void addColumnProfileResult(ColumnProfileResult profileResult) {
-        columnProfileResults.add(profileResult);
+        addColumnProfileResult(profileResult, columnProfileResults.size());
+    }
+
+    @Override
+    protected void addChildImpl(SPObject child, int index) {
+        if (child instanceof ColumnProfileResult) {
+            addColumnProfileResult((ColumnProfileResult) child, index);
+        } else {
+ throw new IllegalArgumentException("Cannot handle children of type " +
+                    child.getClass() + " for object " + child);
+        }
+    }
+
+ private void addColumnProfileResult(ColumnProfileResult child, int index) {
+        columnProfileResults.add(child);
+        child.setParent(this);
+        fireChildAdded(ColumnProfileResult.class, child, index);
     }

     @Override

Reply via email to