Revision: 3259
Author: thomasobrien95
Date: Thu Jan 28 15:27:58 2010
Log: Fix for a population error. The SwingUIProjectLoader was not saving
columns in tables because it was checking the top level populate flag
on the table which was being set to true if only part of the table was
populated. Now the folders populate flags are handled based on the
populate flags of the child types contained in the folder.
http://code.google.com/p/power-architect/source/detail?r=3259

Modified:
 /trunk/src/ca/sqlpower/architect/ProjectLoader.java
 /trunk/src/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
 /trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java

=======================================
--- /trunk/src/ca/sqlpower/architect/ProjectLoader.java Tue Jan 19 13:07:30 2010 +++ /trunk/src/ca/sqlpower/architect/ProjectLoader.java Thu Jan 28 15:27:58 2010
@@ -342,6 +342,8 @@
         d.addFactoryCreate("*/table", tableFactory);
         d.addSetProperties("*/table");
         d.addSetNext("*/table", "addChild");
+
+        d.addFactoryCreate("*/folder", new SQLFolderFactory());

         SQLColumnFactory columnFactory = new SQLColumnFactory();
         d.addFactoryCreate("*/column", columnFactory);
@@ -570,6 +572,31 @@
             return tab;
         }
     }
+
+    /**
+ * XXX Temporary factory for folders until the file format changes and the folders
+     * are removed permanently.
+     */
+    private class SQLFolderFactory extends AbstractObjectCreationFactory {
+        @Override
+ public Object createObject(Attributes attributes) throws Exception { + String type = attributes.getValue("type"); //1=col, 2=import, 3=export, 4=index + boolean isPopulated = Boolean.valueOf(attributes.getValue("populated"));
+
+            if (type.equals("1")) {
+                currentTable.setColumnsPopulated(isPopulated);
+            } else if (type.equals("2")) {
+                currentTable.setImportedKeysPopulated(isPopulated);
+            } else if (type.equals("3")) {
+                currentTable.setExportedKeysPopulated(isPopulated);
+            } else if (type.equals("4")) {
+                currentTable.setIndicesPopulated(isPopulated);
+            }
+
+            return currentTable;
+        }
+
+    }

     /**
      * Creates a SQLColumn instance and adds it to the
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Thu Jan 21 09:24:36 2010 +++ /trunk/src/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Thu Jan 28 15:27:58 2010
@@ -82,6 +82,10 @@
 import ca.sqlpower.sqlobject.SQLTable;
 import ca.sqlpower.util.ExceptionReport;
 import ca.sqlpower.util.SQLPowerUtils;
+import ca.sqlpower.util.UserPrompter;
+import ca.sqlpower.util.UserPrompter.UserPromptOptions;
+import ca.sqlpower.util.UserPrompter.UserPromptResponse;
+import ca.sqlpower.util.UserPrompterFactory.UserPromptType;
 import ca.sqlpower.xml.XMLHelper;

 /**
@@ -1113,13 +1117,29 @@
         List<TableProfileResult> tableResults = profmgr.getResults();

         for (TableProfileResult tableResult : tableResults) {
-            printCommonItems(out, tableResult);
+ String profiledObjectId = sqlObjectSaveIdMap.get(tableResult.getProfiledObject());
+            if (profiledObjectId == null) {
+ UserPrompter prompter = getSession().createUserPrompter("Cannot save profile for table " + + tableResult.getProfiledObject().getName() + ", skipping this profile and continuing save.", + UserPromptType.MESSAGE, UserPromptOptions.OK, UserPromptResponse.OK, null, "OK");
+                prompter.promptUser();
+                continue;
+            }
+            printCommonItems(out, tableResult, profiledObjectId);
ioo.print(out, " rowCount=\"" + tableResult.getRowCount() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
             ioo.niprintln(out, "/>"); //$NON-NLS-1$

List<ColumnProfileResult> columnProfileResults = tableResult.getColumnProfileResults();
             for (ColumnProfileResult cpr : columnProfileResults) {
-                printCommonItems(out, cpr);
+ String profiledColumnObjectId = sqlObjectSaveIdMap.get(cpr.getProfiledObject());
+                if (profiledColumnObjectId == null) {
+ UserPrompter prompter = getSession().createUserPrompter("Cannot save profile for column " + + cpr.getProfiledObject().getName() + ", skipping this profile and continuing save.", + UserPromptType.MESSAGE, UserPromptOptions.OK, UserPromptResponse.OK, null, "OK");
+                    prompter.promptUser();
+                    continue;
+                }
+                printCommonItems(out, cpr, profiledColumnObjectId);
ioo.niprint(out, " avgLength=\"" + cpr.getAvgLength() + "\""); //$NON-NLS-1$ //$NON-NLS-2$

ioo.niprint(out, " minLength=\"" + cpr.getMinLength() + "\""); //$NON-NLS-1$ //$NON-NLS-2$
@@ -1174,9 +1194,8 @@
         ioo.indent--;
     }

- private void printCommonItems(PrintWriter out, ProfileResult profileResult) {
-        SQLObject profiledObject = profileResult.getProfiledObject();
- ioo.print(out, "<profile-result ref-id=\""+sqlObjectSaveIdMap.get(profiledObject)+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ + 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$ " createStartTime=\""+profileResult.getCreateStartTime()+"\"" + //$NON-NLS-1$ //$NON-NLS-2$ " createEndTime=\""+profileResult.getCreateEndTime()+"\"" + //$NON-NLS-1$ //$NON-NLS-2$
@@ -1333,9 +1352,14 @@
ioo.niprint(out, key+"="+quote(value.toString())+" "); //$NON-NLS-1$ //$NON-NLS-2$
             }
         }
- if ( (!skipChildren) && o.allowsChildren() && (getSession().isSavingEntireSource() || o.isPopulated()) ) {
+        if ( (!skipChildren) && o.allowsChildren() ) {
             ioo.niprintln(out, ">"); //$NON-NLS-1$
-            Iterator children = o.getChildren().iterator();
+            Iterator children;
+            if (getSession().isSavingEntireSource()) {
+                children = o.getChildren().iterator();
+            } else {
+                children = o.getChildrenWithoutPopulating().iterator();
+            }
             ioo.indent++;

//XXX Adding the folders back into the saved file format. This way the save file version
@@ -1360,7 +1384,7 @@
table.isExportedKeysPopulated() + "\" name=\"Exported Keys\" " +
                     "physicalName=\"Exported Keys\" type=\"3\">";
indicesFolder = "<folder id=\"FOL" + id + "4\" populated=\"" + - table.isImportedKeysPopulated() + "\" name=\"Indices\" " +
+                    table.isIndicesPopulated() + "\" name=\"Indices\" " +
                     "physicalName=\"Indices\" type=\"4\">";
             }
             while (children.hasNext()) {
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java Mon Jan 25 09:01:33 2010 +++ /trunk/src/ca/sqlpower/architect/swingui/dbtree/DBTreeModel.java Thu Jan 28 15:27:58 2010
@@ -29,6 +29,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.Callable;

 import javax.swing.SwingUtilities;
 import javax.swing.event.TreeModelEvent;
@@ -67,6 +68,7 @@

            private final SQLTable parentTable;
         private final Class<? extends SQLObject> containingChildType;
+        private final Callable<Boolean> isPopulatedRunnable;

         /**
          * @param parentTable
@@ -75,11 +77,13 @@
          *            The type of child of the SQLTable this folder is to
          *            contain. Must be a valid type of child in the table.
          */
- public FolderNode(SQLTable parentTable, Class<? extends SQLObject> containingChildType) { + public FolderNode(SQLTable parentTable, Class<? extends SQLObject> containingChildType,
+                   Callable<Boolean> isPopulatedRunnable) {
                this.parentTable = parentTable;
if (!parentTable.getAllowedChildTypes().contains(containingChildType)) throw new IllegalArgumentException(containingChildType + " is not a valid child type of " + parentTable);
             this.containingChildType = containingChildType;
+            this.isPopulatedRunnable = isPopulatedRunnable;
            }

            public SQLTable getParentTable() {
@@ -167,7 +171,11 @@

         @Override
         public boolean isPopulated() {
-            return parentTable.isPopulated();
+            try {
+                return isPopulatedRunnable.call().booleanValue();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
         }

        }
@@ -545,17 +553,33 @@
* Creates all of the folders the given table should contain for its children
      * and adds them to the {...@link #foldersInTables} map.
      */
-    private void createFolders(SQLTable table) {
+    private void createFolders(final SQLTable table) {
         if (foldersInTables.get(table) == null) {
             List<FolderNode> folderList = new ArrayList<FolderNode>();
             foldersInTables.put(table, folderList);
- FolderNode SQLColumnFolder = new FolderNode(table, SQLColumn.class); + FolderNode SQLColumnFolder = new FolderNode(table, SQLColumn.class, new Callable<Boolean>() {
+                public Boolean call() throws Exception {
+                    return table.isColumnsPopulated();
+                }
+            });
             folderList.add(SQLColumnFolder);
- FolderNode SQLRelationshipFolder = new FolderNode(table, SQLRelationship.class); + FolderNode SQLRelationshipFolder = new FolderNode(table, SQLRelationship.class, new Callable<Boolean>() {
+                public Boolean call() throws Exception {
+                    return table.isExportedKeysPopulated();
+                }
+            });
             folderList.add(SQLRelationshipFolder);
- FolderNode SQLImportedKeys = new FolderNode(table, SQLImportedKey.class); + FolderNode SQLImportedKeys = new FolderNode(table, SQLImportedKey.class, new Callable<Boolean>() {
+                public Boolean call() throws Exception {
+                    return table.isImportedKeysPopulated();
+                }
+            });
             folderList.add(SQLImportedKeys);
- FolderNode SQLIndexFolder = new FolderNode(table, SQLIndex.class); + FolderNode SQLIndexFolder = new FolderNode(table, SQLIndex.class, new Callable<Boolean>() {
+                public Boolean call() throws Exception {
+                    return table.isIndicesPopulated();
+                }
+            });
             folderList.add(SQLIndexFolder);
         }
     }

Reply via email to