Revision: 3289
Author: [email protected]
Date: Fri Feb 12 07:43:48 2010
Log: Added annotations to the ProfileManagerImpl and the ColumnProfileResults to create persister helpers. Tests for these annotations are in the works but the current state of the persister helpers are blocking other people.

Also changed the ProfileManagerImpl to not require an entire session as it only needs its parent reference, which gets set by adding it to a project, and a user prompter. More cleanup on this will be done shortly.
http://code.google.com/p/power-architect/source/detail?r=3289

Modified:
 /trunk/regress/ca/sqlpower/architect/profile/TestProfileBase.java
/trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java
 /trunk/src/ca/sqlpower/architect/ArchitectProject.java
 /trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java
 /trunk/src/ca/sqlpower/architect/profile/ColumnProfileResult.java
 /trunk/src/ca/sqlpower/architect/profile/ProfileManagerImpl.java
 /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java

=======================================
--- /trunk/regress/ca/sqlpower/architect/profile/TestProfileBase.java Mon Jun 1 07:48:14 2009 +++ /trunk/regress/ca/sqlpower/architect/profile/TestProfileBase.java Fri Feb 12 07:43:48 2010
@@ -175,7 +175,9 @@
             assertNotNull(t2);
             assertNotNull(t3);

-            pm = new ProfileManagerImpl(session);
+            pm = new ProfileManagerImpl();
+            ((ProfileManagerImpl) pm).setUserPrompterFactory(session);
+            session.getWorkspace().setProfileManager(pm);
             pm.getDefaultProfileSettings().setFindingAvg(true);
             pm.getDefaultProfileSettings().setFindingMin(true);
             pm.getDefaultProfileSettings().setFindingMax(true);
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java Thu Feb 11 14:26:15 2010 +++ /trunk/regress/ca/sqlpower/architect/swingui/TestingArchitectSwingSession.java Fri Feb 12 07:43:48 2010
@@ -101,7 +101,8 @@
             }
         };
         this.delegateSession = new ArchitectSessionImpl(context, "test");
-        profileManager = new ProfileManagerImpl(this);
+        profileManager = new ProfileManagerImpl();
+        ((ProfileManagerImpl) profileManager).setUserPrompterFactory(this);
         project = new SwingUIProjectLoader(this);
         userSettings = context.getUserSettings();
         rootObject = new SQLObjectRoot();
=======================================
--- /trunk/src/ca/sqlpower/architect/ArchitectProject.java Thu Feb 11 14:16:30 2010 +++ /trunk/src/ca/sqlpower/architect/ArchitectProject.java Fri Feb 12 07:43:48 2010
@@ -48,7 +48,7 @@
* This class is the root object of an ArchitectSession. There is an ArchitectProject * for every ArchitectSession. The ArchitectProject, and all its children, will be
  * listened to and persisted to the JCR. This includes the SQL object tree,
- * the profile manager, forward engineering settings, and compare DM settings.
+ * the profile manager.
  *
  */

@@ -185,6 +185,7 @@
             fireChildRemoved(ProfileManager.class, oldManager, 0);
         }
         fireChildAdded(ProfileManager.class, manager, 0);
+        profileManager.setParent(this);
     }

     @Override
=======================================
--- /trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java Thu Feb 11 14:26:15 2010 +++ /trunk/src/ca/sqlpower/architect/ArchitectSessionImpl.java Fri Feb 12 07:43:48 2010
@@ -84,7 +84,9 @@
            this.context = context;
            this.project = new ArchitectProject();
            project.init(this);
-           this.project.setProfileManager(new ProfileManagerImpl(this));
+           ProfileManagerImpl manager = new ProfileManagerImpl();
+           manager.setUserPrompterFactory(this);
+           this.project.setProfileManager(manager);
            this.name = name;
         this.projectLoader = new ProjectLoader(this);
         this.isEnterpriseSession = false;
=======================================
--- /trunk/src/ca/sqlpower/architect/profile/ColumnProfileResult.java Thu Feb 11 11:47:13 2010 +++ /trunk/src/ca/sqlpower/architect/profile/ColumnProfileResult.java Fri Feb 12 07:43:48 2010
@@ -19,16 +19,29 @@
 package ca.sqlpower.architect.profile;

 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;

 import org.apache.log4j.Logger;

 import ca.sqlpower.object.SPObject;
+import ca.sqlpower.object.annotation.Accessor;
 import ca.sqlpower.object.annotation.Constructor;
 import ca.sqlpower.object.annotation.ConstructorParameter;
+import ca.sqlpower.object.annotation.Mutator;
+import ca.sqlpower.object.annotation.NonProperty;
 import ca.sqlpower.sqlobject.SQLColumn;

 public class ColumnProfileResult extends AbstractProfileResult<SQLColumn> {
+
+    /**
+     * Defines an absolute ordering of the child types of this class.
+     */
+    @SuppressWarnings("unchecked")
+    public static List<Class<? extends SPObject>> allowedChildTypes =
+ Collections.unmodifiableList(new ArrayList<Class<? extends SPObject>>(
+                Arrays.asList(ColumnValueCount.class)));

private static final Logger logger = Logger.getLogger(ColumnProfileResult.class);

@@ -54,72 +67,100 @@
         this.parentResult = parentResult;
     }

+    @Accessor
     public double getAvgLength() {
         return avgLength;
     }

+    @Mutator
     public void setAvgLength(double avgLength) {
+        double oldLength = this.avgLength;
         this.avgLength = avgLength;
+        firePropertyChange("avgLength", oldLength, avgLength);
     }

     /**
      * @return The average value as a Number object, or null if there were
      * 0 values.
      */
+    @Accessor
     public Object getAvgValue() {
         return avgValue;
     }

+    @Mutator
     public void setAvgValue(Object avgValue) {
+        Object oldVal = this.avgValue;
         this.avgValue = avgValue;
+        firePropertyChange("avgValue", oldVal, avgValue);
     }

+    @Accessor
     public int getDistinctValueCount() {
         return distinctValueCount;
     }

+    @Mutator
     public void setDistinctValueCount(int distinctValueCount) {
+        int oldVal = this.distinctValueCount;
         this.distinctValueCount = distinctValueCount;
+ firePropertyChange("distinctValueCount", oldVal, distinctValueCount);
     }

+    @Accessor
     public int getMaxLength() {
         return maxLength;
     }

+    @Mutator
     public void setMaxLength(int maxLength) {
+        int oldLength = this.maxLength;
         this.maxLength = maxLength;
+        firePropertyChange("maxLength", oldLength, maxLength);
     }

     /**
      * @return The minimum value as a Number object, or null if there were
      * 0 values.
      */
+    @Accessor
     public Object getMaxValue() {
         return maxValue;
     }

+    @Mutator
     public void setMaxValue(Object maxValue) {
+        Object oldVal = this.maxValue;
         this.maxValue = maxValue;
+        firePropertyChange("maxValue", oldVal, maxValue);
     }

+    @Accessor
     public int getMinLength() {
         return minLength;
     }

+    @Mutator
     public void setMinLength(int minLength) {
+        int oldLength = this.minLength;
         this.minLength = minLength;
+        firePropertyChange("minLength", oldLength, minLength);
     }

     /**
      * @return The minimum value as a Number object, or null if there were
      * 0 values.
      */
+    @Accessor
     public Object getMinValue() {
         return minValue;
     }

+    @Mutator
     public void setMinValue(Object minValue) {
+        Object oldVal = this.minValue;
         this.minValue = minValue;
+        firePropertyChange("minValue", oldVal, this.minValue);
     }

     @Override
@@ -135,12 +176,16 @@
         "; nullCount: "+getNullCount()+ "]";
     }

+    @Accessor
     public int getNullCount() {
         return nullCount;
     }

+    @Mutator
     public void setNullCount(int nullCount) {
+        int oldCount = this.nullCount;
         this.nullCount = nullCount;
+        firePropertyChange("nullCount", oldCount, nullCount);
     }

     public void addValueCount(Object value, int count) {
@@ -156,10 +201,13 @@
     public void addValueCount(ColumnValueCount value) {
         topTen.add(value);
     }
+
+    @NonProperty
     public List<ColumnValueCount> getValueCount() {
         return topTen;
     }

+    @Accessor
     public TableProfileResult getParentResult() {
         return parentResult;
     }
@@ -182,9 +230,7 @@
     }

     public List<Class<? extends SPObject>> getAllowedChildTypes() {
- List<Class<? extends SPObject>> types = new ArrayList<Class<? extends SPObject>>();
-        types.add(ColumnValueCount.class);
-        return types;
+        return allowedChildTypes;
     }

     public List<? extends SPObject> getChildren() {
=======================================
--- /trunk/src/ca/sqlpower/architect/profile/ProfileManagerImpl.java Thu Feb 11 11:47:13 2010 +++ /trunk/src/ca/sqlpower/architect/profile/ProfileManagerImpl.java Fri Feb 12 07:43:48 2010
@@ -31,13 +31,17 @@

 import org.apache.log4j.Logger;

+import ca.sqlpower.architect.ArchitectProject;
 import ca.sqlpower.architect.ArchitectSession;
 import ca.sqlpower.architect.profile.event.ProfileChangeEvent;
 import ca.sqlpower.architect.profile.event.ProfileChangeListener;
 import ca.sqlpower.object.AbstractSPObject;
 import ca.sqlpower.object.SPObject;
-import ca.sqlpower.object.annotation.Constructor;
-import ca.sqlpower.object.annotation.ConstructorParameter;
+import ca.sqlpower.object.annotation.Accessor;
+import ca.sqlpower.object.annotation.Mutator;
+import ca.sqlpower.object.annotation.NonBound;
+import ca.sqlpower.object.annotation.NonProperty;
+import ca.sqlpower.object.annotation.Transient;
 import ca.sqlpower.sqlobject.SQLDatabase;
 import ca.sqlpower.sqlobject.SQLObject;
 import ca.sqlpower.sqlobject.SQLObjectException;
@@ -45,6 +49,7 @@
 import ca.sqlpower.sqlobject.SQLObjectPreEventListener;
 import ca.sqlpower.sqlobject.SQLTable;
 import ca.sqlpower.util.UserPrompter;
+import ca.sqlpower.util.UserPrompterFactory;
 import ca.sqlpower.util.UserPrompter.UserPromptOptions;
 import ca.sqlpower.util.UserPrompter.UserPromptResponse;
 import ca.sqlpower.util.UserPrompterFactory.UserPromptType;
@@ -57,6 +62,14 @@
  */
public class ProfileManagerImpl extends AbstractSPObject implements ProfileManager {

+    /**
+     * Defines an absolute ordering of the child types of this class.
+     */
+    @SuppressWarnings("unchecked")
+    public static List<Class<? extends SPObject>> allowedChildTypes =
+ Collections.unmodifiableList(new ArrayList<Class<? extends SPObject>>( + Arrays.asList(ProfileSettings.class, TableProfileResult.class)));
+
     /**
      * Watches the session's root object, and reacts when SQLDatabase items
* are removed. In that case, it ensures there are no dangling references
@@ -102,8 +115,6 @@
     }

private static final Logger logger = Logger.getLogger(ProfileManagerImpl.class);
-
-

     /**
      * The current list of listeners who want to know when the contents
@@ -119,9 +130,9 @@
private final List<TableProfileResult> results = new ArrayList<TableProfileResult>();

     /**
-     * The session this manager is associated with.
+     * The user prompter for the profile manager.
      */
-    private final ArchitectSession session;
+    private UserPrompterFactory session;

     /**
      * The defaults that new profile results will be created with.
@@ -140,6 +151,11 @@
      */
private TableProfileCreator creator = new RemoteDatabaseProfileCreator(getDefaultProfileSettings());

+    /**
+     * Watches for database removals and updates the manager accordingly.
+     */
+ private final DatabaseRemovalWatcher databaseRemovalWatcher = new DatabaseRemovalWatcher();
+
     /**
      * A list of the different existing profile creators that can be used.
      */
@@ -180,13 +196,26 @@
         }
     }

-    @Constructor
- public ProfileManagerImpl(@ConstructorParameter(propertyName="session") ArchitectSession session) {
+    @Transient @Mutator
+    public void setUserPrompterFactory(ArchitectSession session) {
         this.session = session;
-        if (session != null && session.getRootObject() != null) {
- session.getRootObject().addSQLObjectPreEventListener(new DatabaseRemovalWatcher());
+    }
+
+    @Override @Mutator
+    public void setParent(SPObject parent) {
+        if (getParent() != null) {
+ ((ArchitectProject) getParent()).getRootObject().removeSQLObjectPreEventListener(databaseRemovalWatcher);
+        }
+        super.setParent(parent);
+ if (parent != null && ((ArchitectProject) parent).getRootObject() != null) { + ((ArchitectProject) parent).getRootObject().addSQLObjectPreEventListener(databaseRemovalWatcher);
         }
     }
+
+    @Override @Accessor
+    public ArchitectProject getParent() {
+        return (ArchitectProject) super.getParent();
+    }

     /**
* This is the method that everything which wants to add a profile result
@@ -254,12 +283,14 @@
     }

     /* docs inherited from interface */
+    @NonProperty
     public List<TableProfileResult> getResults() {
// this could be optimized by caching the current result list snapshot, but enh. return Collections.unmodifiableList(new ArrayList<TableProfileResult>(results));
     }

     /* docs inherited from interface */
+    @NonProperty
     public List<TableProfileResult> getResults(SQLTable t) {
List<TableProfileResult> someResults = new ArrayList<TableProfileResult>();
         for (TableProfileResult tpr : results) {
@@ -282,16 +313,19 @@
     }

     /* docs inherited from interface */
+    @NonProperty
     public ProfileSettings getDefaultProfileSettings() {
         return defaultProfileSettings;
     }

     /* docs inherited from interface */
+    @NonProperty
     public void setDefaultProfileSettings(ProfileSettings settings) {
         defaultProfileSettings = settings;
     }

     /* docs inherited from interface */
+    @NonBound
     public void setProcessingOrder(List<TableProfileResult> tpr) {

     }
@@ -370,14 +404,17 @@
         profileExecutor.shutdown();
     }

+    @NonBound
     public List<TableProfileCreator> getProfileCreators() {
         return Collections.unmodifiableList(profileCreators);
     }

+    @NonBound
     public TableProfileCreator getCreator() {
         return creator;
     }

+    @NonBound
     public void setCreator(TableProfileCreator tpc) {
         this.creator = tpc;
     }
@@ -409,13 +446,12 @@
         }
     }

+    @Transient @Accessor
     public List<Class<? extends SPObject>> getAllowedChildTypes() {
- List<Class<? extends SPObject>> types = new ArrayList<Class<? extends SPObject>>();
-        types.add(ProfileSettings.class);
-        types.add(TableProfileResult.class);
-        return types;
+        return allowedChildTypes;
     }

+    @NonProperty
     public List<? extends SPObject> getChildren() {
         List<SPObject> allChildren = new ArrayList<SPObject>();
         allChildren.add(defaultProfileSettings);
@@ -423,6 +459,7 @@
         return allChildren;
     }

+    @NonBound
     public List<? extends SPObject> getDependencies() {
         return Collections.emptyList();
     }
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Thu Feb 11 14:26:15 2010 +++ /trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java Fri Feb 12 07:43:48 2010
@@ -218,7 +218,9 @@
         this.context = context;
         this.delegateSession = delegateSession;
         this.olapRootObject = new OLAPRootObject(delegateSession);
- ((ArchitectSessionImpl)delegateSession).setProfileManager(new ProfileManagerImpl(this));
+        ProfileManagerImpl profileManager = new ProfileManagerImpl();
+        profileManager.setUserPrompterFactory(this);
+ ((ArchitectSessionImpl)delegateSession).setProfileManager(profileManager); ((ArchitectSessionImpl)delegateSession).setUserPrompterFactory(this);
         this.recent = new RecentMenu(this.getClass()) {
             @Override

Reply via email to