Revision: 3751
Author: [email protected]
Date: Fri Jul 16 13:23:39 2010
Log: Changed how profiles are saved to XML.

Changed the version to preview-06.
http://code.google.com/p/power-architect/source/detail?r=3751

Modified:
 /trunk/regress/ca/sqlpower/architect/profile/ColumnProfileResultTest.java
 /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java
 /trunk/src/main/java/ca/sqlpower/architect/ArchitectVersion.java
 /trunk/src/main/java/ca/sqlpower/architect/ProjectLoader.java
 /trunk/src/main/java/ca/sqlpower/architect/profile/ColumnProfileResult.java
/trunk/src/main/java/ca/sqlpower/architect/profile/LocalReservoirProfileCreator.java
 /trunk/src/main/java/ca/sqlpower/architect/profile/ProfileManagerImpl.java
/trunk/src/main/java/ca/sqlpower/architect/profile/RemoteDatabaseProfileCreator.java /trunk/src/main/java/ca/sqlpower/architect/profile/output/ProfileCSVFormat.java /trunk/src/main/java/ca/sqlpower/architect/profile/output/ProfileHTMLFormat.java /trunk/src/main/java/ca/sqlpower/architect/profile/output/ProfilePDFFormat.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/ProfileGraphPanel.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java /trunk/src/main/java/ca/sqlpower/architect/swingui/action/SaveProfileAction.java /trunk/src/main/java/ca/sqlpower/architect/swingui/table/ProfileTableModel.java

=======================================
--- /trunk/regress/ca/sqlpower/architect/profile/ColumnProfileResultTest.java Wed Feb 17 14:19:51 2010 +++ /trunk/regress/ca/sqlpower/architect/profile/ColumnProfileResultTest.java Fri Jul 16 13:23:39 2010
@@ -54,7 +54,7 @@
         ProfileSettings settings = new ProfileSettings();
TableProfileResult tableProfile = new TableProfileResult(table, settings);
         getRootObject().addChild(tableProfile, 0);
-        profile = new ColumnProfileResult(column, tableProfile);
+        profile = new ColumnProfileResult(column);
         tableProfile.addColumnProfileResult(profile);
     }

=======================================
--- /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java Tue Jul 13 09:45:23 2010 +++ /trunk/regress/ca/sqlpower/architect/util/ArchitectNewValueMaker.java Fri Jul 16 13:23:39 2010
@@ -103,7 +103,7 @@
         } else if (valueType == ColumnProfileResult.class) {
TableProfileResult tpr = (TableProfileResult) makeNewValue(TableProfileResult.class, null, "");
             ColumnProfileResult cpr = new ColumnProfileResult(
- (SQLColumn) makeNewValue(SQLColumn.class, null, ""), tpr);
+                    (SQLColumn) makeNewValue(SQLColumn.class, null, ""));
             tpr.addColumnProfileResult(cpr);
             return cpr;
         } else if (valueType == ColumnValueCount.class) {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectVersion.java Fri Jul 9 08:01:28 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectVersion.java Fri Jul 16 13:23:39 2010
@@ -64,7 +64,7 @@
* Full releases do not have a suffix. In that case, the suffix is the empty
      * string (not null).
      */
-    public static final String APP_VERSION_SUFFIX = "preview-05";
+    public static final String APP_VERSION_SUFFIX = "preview-06";

     /**
      * The normal readable version number, formatted as Major.Minor.Tiny.
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ProjectLoader.java Wed Jul 14 07:55:26 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ProjectLoader.java Fri Jul 16 13:23:39 2010
@@ -488,6 +488,11 @@
         d.addFactoryCreate("*/profiles", profileManagerFactory);
         d.addSetProperties("*/profiles");

+        /*
+         * Backward compatibility: the table and column profiles used to be
+ * stored as siblings to each other, with the parent of a column result
+         * being the last table result that was read.
+         */
ProfileResultFactory profileResultFactory = new ProfileResultFactory(); d.addFactoryCreate("*/profiles/profile-result", profileResultFactory);
         /*
@@ -497,18 +502,26 @@
          */
d.addRule("*/profiles/profile-result", new SetPropertiesRule(new String[] {"exception"}, new String[] {}));
         d.addSetNext("*/profiles/profile-result", "loadResult");
+
+ d.addFactoryCreate("*/profiles/table-profile-result", new TableProfileResultFactory()); + d.addRule("*/profiles/table-profile-result", new SetPropertiesRule(new String[] {"exception"}, new String[] {})); + d.addSetNext("*/profiles/table-profile-result", "addTableProfileResult");
+
+ d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result", new ColumnProfileResultFactory()); + d.addRule("*/profiles/table-profile-result/column-profile-result", new SetPropertiesRule(new String[] {"exception"}, new String[] {})); + d.addSetNext("*/profiles/table-profile-result/column-profile-result", "addColumnProfileResult");

ProfileResultValueFactory profileResultValueFactory = new ProfileResultValueFactory(); - d.addFactoryCreate("*/profiles/profile-result/avgValue", profileResultValueFactory );
-        d.addSetNext("*/profiles/profile-result/avgValue", "setAvgValue");
- d.addFactoryCreate("*/profiles/profile-result/minValue", profileResultValueFactory);
-        d.addSetNext("*/profiles/profile-result/minValue", "setMinValue");
- d.addFactoryCreate("*/profiles/profile-result/maxValue", profileResultValueFactory);
-        d.addSetNext("*/profiles/profile-result/maxValue", "setMaxValue");
+ d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result/avgValue", profileResultValueFactory ); + d.addSetNext("*/profiles/table-profile-result/column-profile-result/avgValue", "setAvgValue"); + d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result/minValue", profileResultValueFactory); + d.addSetNext("*/profiles/table-profile-result/column-profile-result/minValue", "setMinValue"); + d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result/maxValue", profileResultValueFactory); + d.addSetNext("*/profiles/table-profile-result/column-profile-result/maxValue", "setMaxValue");

ProfileResultTopNValueFactory topNValueFactory = new ProfileResultTopNValueFactory(); - d.addFactoryCreate("*/profiles/profile-result/topNvalue", topNValueFactory ); - d.addSetNext("*/profiles/profile-result/topNvalue", "addValueCount"); + d.addFactoryCreate("*/profiles/table-profile-result/column-profile-result/topNvalue", topNValueFactory ); + d.addSetNext("*/profiles/table-profile-result/column-profile-result/topNvalue", "addValueCount");

         FileFactory fileFactory = new FileFactory();
         d.addFactoryCreate("*/file", fileFactory);
@@ -834,12 +847,6 @@
             return cmap;
         }
     }
-
-    /**
- * The index most recently loaded from the project file. The SQLIndexColumnFactory
-     * has to know which index owns the index column in order to create it.
-     */
-    private SQLIndex currentIndex;

     /**
      * Creates a SQLIndex instance and adds it to the objectIdMap.
@@ -870,8 +877,6 @@
             }
             index.setType(attributes.getValue("index-type"));

-            currentIndex = index;
-
             LoadSQLObjectAttributes(index, attributes);

             return index;
@@ -953,6 +958,9 @@
         }
     }

+    /**
+     * This class is used for backwards compatibility with 0.9.16 and older
+     */
private class ProfileResultFactory extends AbstractObjectCreationFactory {

         /**
@@ -983,7 +991,7 @@
                 if (tableProfileResult == null) {
throw new IllegalArgumentException("Column result does not have a parent");
                 }
- ColumnProfileResult cpr = new ColumnProfileResult(c, tableProfileResult);
+                ColumnProfileResult cpr = new ColumnProfileResult(c);
                 tableProfileResult.addColumnProfileResult(cpr);
                 return cpr;
             } else {
@@ -991,7 +999,37 @@
             }
         }
     }
-
+
+ private class TableProfileResultFactory extends AbstractObjectCreationFactory {
+
+ public Object createObject(Attributes attributes) throws SQLObjectException {
+            String refid = attributes.getValue("ref-id");
+
+            if (refid == null) {
+ throw new SQLObjectException("Missing mandatory attribute \"ref-id\" in <table-profile-result> element");
+            }
+
+            SQLTable t = (SQLTable) sqlObjectLoadIdMap.get(refid);
+
+ return new TableProfileResult(t, session.getProfileManager().getDefaultProfileSettings());
+        }
+    }
+
+ private class ColumnProfileResultFactory extends AbstractObjectCreationFactory {
+
+ public Object createObject(Attributes attributes) throws SQLObjectException {
+            String refid = attributes.getValue("ref-id");
+
+            if (refid == null) {
+ throw new SQLObjectException("Missing mandatory attribute \"ref-id\" id <column-profile-result> element");
+            }
+
+            SQLColumn c = (SQLColumn) sqlObjectLoadIdMap.get(refid);
+
+            return new ColumnProfileResult(c);
+        }
+    }
+
private class ProfileResultValueFactory extends AbstractObjectCreationFactory {
         @Override
public Object createObject(Attributes attributes) throws SQLObjectException, ClassNotFoundException, InstantiationException, IllegalAccessException {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/ColumnProfileResult.java Fri Jul 16 07:18:35 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/ColumnProfileResult.java Fri Jul 16 13:23:39 2010
@@ -54,17 +54,13 @@
     private int nullCount;
private List<ColumnValueCount> topTen = new ArrayList<ColumnValueCount>();

-    private final TableProfileResult parentResult;
-
     /**
* This creates a column profile result which stores information about a profiled column.
      */
     @Constructor
- public ColumnProfileResult(@ConstructorParameter(propertyName="profiledObject") SQLColumn profiledObject, - @ConstructorParameter(propertyName="parentResult") TableProfileResult parentResult) { + public ColumnProfileResult(@ConstructorParameter(propertyName="profiledObject") SQLColumn profiledObject) {
         super(profiledObject);
         setName("New Column Profile");
-        this.parentResult = parentResult;
     }

     /**
@@ -80,7 +76,7 @@
         this.minLength = cprToCopy.minLength;
         this.minValue = cprToCopy.minValue;
         this.nullCount = cprToCopy.nullCount;
-        this.parentResult = cprToCopy.getParentResult();
+        setParent(cprToCopy.getParent());
         for (int i = 0; i < cprToCopy.getValueCount().size(); i++) {
             ColumnValueCount cvc = cprToCopy.getValueCount().get(i);
             this.addColumnValueCount(new ColumnValueCount(cvc), i);
@@ -209,7 +205,7 @@
     }

     public void addValueCount(Object value, int count) {
-        double per =  count/(double)parentResult.getRowCount();
+        double per =  count/(double)getParent().getRowCount();

         ColumnValueCount columnValueCount;
         if (value == ColumnValueCount.OTHER_VALUE_OBJECT) {
@@ -247,11 +243,6 @@
     public List<ColumnValueCount> getValueCount() {
         return topTen;
     }
-
-    @Accessor
-    public TableProfileResult getParentResult() {
-        return parentResult;
-    }

     @Override
     protected boolean removeChildImpl(SPObject child) {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/LocalReservoirProfileCreator.java Mon Jun 28 11:21:31 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/LocalReservoirProfileCreator.java Fri Jul 16 13:23:39 2010
@@ -120,7 +120,7 @@

// now the columns (notice we have already released the connection because it's no longer required)
         for (SQLColumn col : table.getColumns()) {
-            tpr.addColumnProfileResult(new ColumnProfileResult(col, tpr));
+            tpr.addColumnProfileResult(new ColumnProfileResult(col));
         }
         profileColumnsFromSample(tpr, sample, pm);
         return true;
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/ProfileManagerImpl.java Fri Jul 16 07:18:35 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/ProfileManagerImpl.java Fri Jul 16 13:23:39 2010
@@ -300,6 +300,11 @@
     public ArchitectProject getParent() {
         return (ArchitectProject) super.getParent();
     }
+
+    public void addTableProfileResult(TableProfileResult child) {
+        results.add(child);
+        fireProfilesAdded(Collections.singletonList(child));
+    }

     /**
* This is the method that everything which wants to add a profile result
@@ -460,10 +465,11 @@
* same hierarchy as they had when they were originally created, so we don't * need any more error-prone code to recreate what we already had and then * threw away? Beside reducing bugs, it would eliminate the need for this public - * method and accompanying docs that warn you against using it." If so, please
-     * apply to SQL Power at hr (@) sqlpower.ca.
+ * method and accompanying docs that warn you against using it." So was I. + * Though I fixed it, this method still has to hang around for backwards
+     * compatibility reasons.
      */
-    public void loadResult(ProfileResult pr) {
+    public void loadResult(ProfileResult<? extends SQLObject> pr) {
         if (pr instanceof TableProfileResult) {
             TableProfileResult tpr = (TableProfileResult) pr;
             addResults(Collections.singletonList(tpr));
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/RemoteDatabaseProfileCreator.java Mon Jun 28 11:21:31 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/RemoteDatabaseProfileCreator.java Fri Jul 16 13:23:39 2010
@@ -213,7 +213,7 @@
JDBCDataSourceType dsType = table.getParentDatabase().getDataSource().getParentType();
             createProfileFunctions(dsType);
             for (SQLColumn col : table.getColumns()) {
- ColumnProfileResult columnResult = new ColumnProfileResult(col, tpr); + ColumnProfileResult columnResult = new ColumnProfileResult(col);
                 tpr.addColumnProfileResult(columnResult);
                 doColumnProfile(columnResult, pm);
                 pm.setProgress(pm.getProgress() + 1);
@@ -642,7 +642,7 @@

TableProfileResult dummyParent = new TableProfileResult(col.getParent(), new ProfileSettings());
         dummyParent.setRowCount(1);
- ColumnProfileResult dummy = new ColumnProfileResult(col, dummyParent);
+        ColumnProfileResult dummy = new ColumnProfileResult(col);
         dummyParent.addColumnProfileResult(dummy);

         logger.debug("Discovering profile functions for column "+col);
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/output/ProfileCSVFormat.java Fri Jul 9 08:12:39 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/output/ProfileCSVFormat.java Fri Jul 16 13:23:39 2010
@@ -67,7 +67,7 @@

             SQLColumn c = (SQLColumn) result.getProfiledObject();
             SQLTable t = c.getParent();
- TableProfileResult tpr = ((ColumnProfileResult)result).getParentResult(); + TableProfileResult tpr = ((ColumnProfileResult)result).getParent();
             List<String> commonData = new ArrayList<String>();

             for ( ProfileColumn pc : columns ) {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/output/ProfileHTMLFormat.java Thu Jan 29 12:02:55 2009 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/output/ProfileHTMLFormat.java Fri Jul 16 13:23:39 2010
@@ -171,7 +171,7 @@
                 }
             } else if ( result instanceof ColumnProfileResult ) {
                 SQLColumn c = (SQLColumn) result.getProfiledObject();
- TableProfileResult tResult = ((ColumnProfileResult)result).getParentResult(); + TableProfileResult tResult = ((ColumnProfileResult)result).getParent();
                 double rowCount = (double) tResult.getRowCount();

                 outw.print("\n  <tr>");
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/profile/output/ProfilePDFFormat.java Mon Dec 21 08:27:43 2009 +++ /trunk/src/main/java/ca/sqlpower/architect/profile/output/ProfilePDFFormat.java Fri Jul 16 13:23:39 2010
@@ -197,7 +197,7 @@
                 ddlg = tableResult.getDDLGenerator();
             } else if ( result instanceof ColumnProfileResult ) {
final ColumnProfileResult columnResult = (ColumnProfileResult) result; - TableProfileResult tResult = columnResult.getParentResult();
+                TableProfileResult tResult = columnResult.getParent();
addBodyRow(tResult,columnResult, ddlg, pdfTable, bf, f, fsize, widths);
             }
         }
@@ -226,7 +226,7 @@
                 ddlg = tableResult.getDDLGenerator();
             } else if ( result instanceof ColumnProfileResult ) {
final ColumnProfileResult columnResult = (ColumnProfileResult) result; - TableProfileResult tResult = columnResult.getParentResult();
+                TableProfileResult tResult = columnResult.getParent();
addBodyRow(tResult,columnResult, ddlg, pdfTable, bf, f, fsize, widths);
             }
         }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ProfileGraphPanel.java Mon Dec 21 08:27:43 2009 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ProfileGraphPanel.java Fri Jul 16 13:23:39 2010
@@ -242,7 +242,7 @@
      * Subroutine of {...@link #displayProfile(ColumnProfileResult)}.
      */
     private void displayValidProfile(ColumnProfileResult cr) {
-        TableProfileResult tr = (TableProfileResult) cr.getParentResult();
+        TableProfileResult tr = (TableProfileResult) cr.getParent();
         rowCount = tr.getRowCount();
         rowCountDisplay.setText(Integer.toString(rowCount));

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Mon Jul 12 08:21:11 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Fri Jul 16 13:23:39 2010
@@ -1292,9 +1292,11 @@
                 prompter.promptUser();
                 continue;
             }
+            ioo.print(out, "<table-profile-result"); //$NON-NLS-1$
             printCommonItems(out, tableResult, profiledObjectId);
ioo.print(out, " rowCount=\"" + tableResult.getRowCount() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
-            ioo.niprintln(out, "/>"); //$NON-NLS-1$
+            ioo.niprintln(out, ">"); //$NON-NLS-1$
+            ioo.indent++;

List<ColumnProfileResult> columnProfileResults = tableResult.getColumnProfileResults();
             for (ColumnProfileResult cpr : columnProfileResults) {
@@ -1306,6 +1308,7 @@
                     prompter.promptUser();
                     continue;
                 }
+                ioo.print(out, "<column-profile-result");
                 printCommonItems(out, cpr, profiledColumnObjectId);
ioo.niprint(out, " avgLength=\"" + cpr.getAvgLength() + "\""); //$NON-NLS-1$ //$NON-NLS-2$

@@ -1356,16 +1359,17 @@
                 }
                 ioo.indent--;

-                ioo.println(out, "</profile-result>"); //$NON-NLS-1$
-            }
+                ioo.println(out, "</column-profile-result>"); //$NON-NLS-1$
+            }
+            ioo.indent--;
+            ioo.println(out, "</table-profile-result>");
         }
         ioo.println(out, "</profiles>"); //$NON-NLS-1$
         ioo.indent--;
     }

private void printCommonItems(PrintWriter out, ProfileResult<?> profileResult, String profiledObjectId) { - ioo.print(out, "<profile-result ref-id=\"" + profiledObjectId + "\"" + //$NON-NLS-1$ //$NON-NLS-2$ - " type=\"" + profileResult.getClass().getName() + "\"" + //$NON-NLS-1$ //$NON-NLS-2$ + ioo.print(out, "ref-id=\"" + profiledObjectId + "\"" + //$NON-NLS-1$ //$NON-NLS-2$ " createStartTime=\""+profileResult.getCreateStartTime()+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ " createEndTime=\""+profileResult.getCreateEndTime()+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ " exception=\""+(profileResult.getException() == null ? "false" : "true")+"\""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/action/SaveProfileAction.java Thu Jun 24 12:17:51 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/action/SaveProfileAction.java Fri Jul 16 13:23:39 2010
@@ -61,7 +61,7 @@
         }

         public void addColumnProfileResult(ColumnProfileResult cpr){
-            TableProfileResult tpr = cpr.getParentResult();
+            TableProfileResult tpr = cpr.getParent();
             if (!resultTree.containsKey(tpr)) {
                 resultTree.put(tpr, new TreeSet<ColumnProfileResult>());
             }
@@ -141,7 +141,7 @@
             for ( int i=0; i<selectedRows.length; i++ ) {
                 int rowid = selectedRows[i];
ColumnProfileResult result = viewTable.getColumnProfileResultForRow(rowid);
-                selectedTable.add(result.getParentResult());
+                selectedTable.add(result.getParent());
                 selectedColumn.add(result);
             }

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/table/ProfileTableModel.java Tue Jan 5 08:48:08 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/table/ProfileTableModel.java Fri Jul 16 13:23:39 2010
@@ -141,7 +141,7 @@
     private static Object getColumnValueFromProfile(ProfileColumn column,
              ColumnProfileResult columnProfile) {
         SQLColumn col = columnProfile.getProfiledObject();
-        int rowCount = columnProfile.getParentResult().getRowCount();
+        int rowCount = columnProfile.getParent().getRowCount();

         switch(column) {
         case DATABASE:

Reply via email to