Revision: 3784
Author: mo.jeff
Date: Thu Jul 22 14:31:50 2010
Log: * Added support for allowing UserDefinedSQLTypeSnapshots and DomainCategorySnapshots to be created from the client.

This is primarily to solve the issue where old revisions of server-based projects needed their types to maintain the state they were in at those revision times, since types are normally contained in the system workspace.

The creation currently occurs in the client, but I would really prefer it to be done on the server, but I haven't been able to figure out a way to do so within the server backend.

* The ArchitectClientSideSession's getters for types and domain categories need to merge the system types and categories with the snapshotted ones.

* SQLTypeTreeModel.compare threw exceptions if two objects with different parents were compared. However, since snapshotted types are typically parented by the project, while types are parented by the system workspace, this can no longer be the case.

* Added a boolean flag in UserDefinedSQLTypeSnapshot to mark whether or not the snapshot is being used to snapshot a domain. This makes it easier to support having separate snapshots of a type for the purpose of being referenced by a domain, and of the type itself.
http://code.google.com/p/power-architect/source/detail?r=3784

Modified:
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/SQLTypeTreeModel.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java Mon Jul 12 08:21:11 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java Thu Jul 22 14:31:50 2010
@@ -9,7 +9,9 @@
 import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.prefs.Preferences;
@@ -74,6 +76,7 @@
 import ca.sqlpower.sql.SpecificDataSourceCollection;
 import ca.sqlpower.sqlobject.SQLObjectException;
 import ca.sqlpower.sqlobject.UserDefinedSQLType;
+import ca.sqlpower.sqlobject.UserDefinedSQLTypeSnapshot;
 import ca.sqlpower.swingui.event.SessionLifecycleEvent;
 import ca.sqlpower.swingui.event.SessionLifecycleListener;
 import ca.sqlpower.util.SQLPowerUtils;
@@ -967,8 +970,64 @@
      */
     @Override
     public List<UserDefinedSQLType> getSQLTypes() {
-        return Collections.unmodifiableList(
- getSystemWorkspace().getChildren(UserDefinedSQLType.class)); + // The following was my attempt to merge the snapshot and system types lists together + // without making it O(mn), but the code is a bit lengthier than I'd like, so perhaps
+        // the added complexity may not be worth it?
+ List<UserDefinedSQLTypeSnapshot> typeSnapshots = getWorkspace().getChildren(UserDefinedSQLTypeSnapshot.class); + List<UserDefinedSQLType> systemTypes = getSystemWorkspace().getChildren(UserDefinedSQLType.class);
+
+        // Remove domain snapshots from the list
+        for (int i = typeSnapshots.size() - 1; i >= 0; i--) {
+            UserDefinedSQLTypeSnapshot snapshot = typeSnapshots.get(i);
+            if (snapshot.isDomainSnapshot()) {
+                typeSnapshots.remove(i);
+            }
+        }
+
+        // If there are no snapshots, just return the system types.
+ if (typeSnapshots.size() == 0) return Collections.unmodifiableList(systemTypes);
+
+        // Sort both lists by the UUIDs of the system types
+ Collections.sort(typeSnapshots, new Comparator<UserDefinedSQLTypeSnapshot>() { + public int compare(UserDefinedSQLTypeSnapshot o1, UserDefinedSQLTypeSnapshot o2) { + return o1.getOriginalUUID().compareTo(o2.getOriginalUUID());
+            }
+        });
+ Collections.sort(systemTypes, new Comparator<UserDefinedSQLType>() { + public int compare(UserDefinedSQLType o1, UserDefinedSQLType o2) {
+                return o1.getUUID().compareTo(o2.getUUID());
+            }
+        });
+
+        // Now go through the list of system types. If a snapshot type's
+ // original UUID matches, then replace the system type with the snapshot. + Iterator<UserDefinedSQLTypeSnapshot> snapshotIterator = typeSnapshots.iterator(); + UserDefinedSQLTypeSnapshot currentSnapshot = snapshotIterator.next();
+
+        for (int i = 0; i < systemTypes.size() ; i++) {
+            UserDefinedSQLType type = systemTypes.get(i);
+ int compareTo = currentSnapshot.getOriginalUUID().compareTo(type.getUUID());
+            if (compareTo <= 0) {
+                if (compareTo == 0) {
+                    systemTypes.set(i, currentSnapshot.getSPObject());
+                } else {
+                    systemTypes.add(i, currentSnapshot.getSPObject());
+                }
+ if (snapshotIterator.hasNext() && i != systemTypes.size() - 1) {
+                    currentSnapshot = snapshotIterator.next();
+                } else {
+                    break;
+                }
+            }
+        }
+
+ // If we've gone through all the system types, then append the remaining snapshot types
+        while (snapshotIterator.hasNext()) {
+            currentSnapshot = snapshotIterator.next();
+            systemTypes.add(currentSnapshot.getSPObject());
+        }
+
+        return Collections.unmodifiableList(systemTypes);
     }

     /**
@@ -977,8 +1036,56 @@
      */
     @Override
     public List<DomainCategory> getDomainCategories() {
-        return Collections.unmodifiableList(
-                getSystemWorkspace().getChildren(DomainCategory.class));
+ // The following was my attempt to merge the snapshot and system category lists together + // without making it O(nm), but the code is a bit lengthier than I'd like, so perhaps
+        // the added complexity may not be worth it?
+ List<DomainCategorySnapshot> categorySnapshots = getWorkspace().getChildren(DomainCategorySnapshot.class); + List<DomainCategory> systemCategories = getSystemWorkspace().getChildren(DomainCategory.class);
+
+        // If there are no snapshots, just return the system categories.
+ if (categorySnapshots.size() == 0) return Collections.unmodifiableList(systemCategories);
+
+        // Sort both lists by the UUIDs of the system categories
+ Collections.sort(categorySnapshots, new Comparator<DomainCategorySnapshot>() { + public int compare(DomainCategorySnapshot o1, DomainCategorySnapshot o2) { + return o1.getOriginalUUID().compareTo(o2.getOriginalUUID());
+            }
+        });
+ Collections.sort(systemCategories, new Comparator<DomainCategory>() {
+            public int compare(DomainCategory o1, DomainCategory o2) {
+                return o1.getUUID().compareTo(o2.getUUID());
+            }
+        });
+
+ // Now go through the list of system categories. If a snapshot category's + // original UUID matches, then replace the system category with the snapshot. + Iterator<DomainCategorySnapshot> snapshotIterator = categorySnapshots.iterator();
+        DomainCategorySnapshot currentSnapshot = snapshotIterator.next();
+
+        for (int i = 0; i < systemCategories.size() ; i++) {
+            DomainCategory type = systemCategories.get(i);
+ int compareTo = currentSnapshot.getOriginalUUID().compareTo(type.getUUID());
+            if (compareTo <= 0) {
+                if (compareTo == 0) {
+                    systemCategories.set(i, currentSnapshot.getSPObject());
+                } else {
+                    systemCategories.add(i, currentSnapshot.getSPObject());
+                }
+ if (snapshotIterator.hasNext() && i != systemCategories.size() - 1) {
+                    currentSnapshot = snapshotIterator.next();
+                } else {
+                    break;
+                }
+            }
+        }
+
+ // If we've gone through all the system types, then append the remaining snapshot categories
+        while (snapshotIterator.hasNext()) {
+            currentSnapshot = snapshotIterator.next();
+            systemCategories.add(currentSnapshot.getSPObject());
+        }
+
+        return Collections.unmodifiableList(systemCategories);
     }

     @Override
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java Thu Jul 8 13:04:18 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ColumnEditPanel.java Thu Jul 22 14:31:50 2010
@@ -68,7 +68,10 @@

 import ca.sqlpower.architect.ArchitectSession;
 import ca.sqlpower.architect.ddl.DDLUtils;
+import ca.sqlpower.architect.enterprise.DomainCategory;
+import ca.sqlpower.architect.enterprise.DomainCategorySnapshot;
 import ca.sqlpower.object.AbstractPoolingSPListener;
+import ca.sqlpower.object.ObjectDependentException;
 import ca.sqlpower.object.SPChildEvent;
 import ca.sqlpower.object.SPListener;
 import ca.sqlpower.sqlobject.SQLColumn;
@@ -76,8 +79,9 @@
 import ca.sqlpower.sqlobject.SQLObjectException;
 import ca.sqlpower.sqlobject.SQLObjectUtils;
 import ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider;
-import ca.sqlpower.sqlobject.UserDefinedSQLType;
import ca.sqlpower.sqlobject.SQLTypePhysicalPropertiesProvider.PropertyType;
+import ca.sqlpower.sqlobject.UserDefinedSQLType;
+import ca.sqlpower.sqlobject.UserDefinedSQLTypeSnapshot;
 import ca.sqlpower.swingui.ChangeListeningDataEntryPanel;
 import ca.sqlpower.swingui.DataEntryPanelChangeUtil;
 import ca.sqlpower.swingui.SPSUtils;
@@ -837,7 +841,39 @@
                 if (componentEnabledMap.get(colType).isSelected()) {
                     // Set upstream type on column
UserDefinedSQLType upstreamType = (UserDefinedSQLType) colType.getLastSelectedPathComponent(); - column.getUserDefinedSQLType().setUpstreamType(upstreamType);
+
+ if (upstreamType != null && session.isEnterpriseSession() && + !((upstreamType.getParent().equals(session.getWorkspace())) | | // not an already existing type snapshot + (upstreamType.getParent() instanceof DomainCategory && + upstreamType.getParent().getParent().equals(session.getWorkspace())))) // not an already existing domain snapshot
+                    {
+ boolean isDomainSnapshot = upstreamType.getParent() instanceof DomainCategory;
+                        UserDefinedSQLTypeSnapshot snapshot;
+                        if (upstreamType.getUpstreamType() != null) {
+ UserDefinedSQLType upUpStreamType = upstreamType.getUpstreamType(); + UserDefinedSQLTypeSnapshot upstreamSnapshot = new UserDefinedSQLTypeSnapshot(upUpStreamType, 0, isDomainSnapshot); + session.getWorkspace().addChild(upstreamSnapshot, 0); + session.getWorkspace().addChild(upstreamSnapshot.getSPObject(), 0); + snapshot = new UserDefinedSQLTypeSnapshot(upstreamType, 0, isDomainSnapshot, upstreamSnapshot);
+                        } else {
+ snapshot = new UserDefinedSQLTypeSnapshot(upstreamType, 0, isDomainSnapshot);
+                        }
+                       session.getWorkspace().addChild(snapshot, 0);
+ column.getUserDefinedSQLType().setUpstreamType(snapshot.getSPObject()); + if ((upstreamType.getParent() instanceof DomainCategory)) { + DomainCategory parent = (DomainCategory) upstreamType.getParent();
+                           DomainCategorySnapshot domainSnapshot =
+                               new DomainCategorySnapshot(parent, 0);
+ session.getWorkspace().addChild(domainSnapshot, 0); + session.getWorkspace().addChild(domainSnapshot.getSPObject(), 0); + domainSnapshot.getSPObject().addChild(snapshot.getSPObject(), 0);
+                       } else {
+ session.getWorkspace().addChild(snapshot.getSPObject(), 0);
+                       }
+
+                    } else {
+ column.getUserDefinedSQLType().setUpstreamType(upstreamType);
+                    }

                     // Set scale
                     if (typeOverrideMap.get(colScale).isSelected()) {
@@ -902,6 +938,10 @@
             }
         } catch (SQLObjectException e) {
             throw new RuntimeException(e);
+        } catch (IllegalArgumentException e) {
+            throw new RuntimeException(e);
+        } catch (ObjectDependentException e) {
+            throw new RuntimeException(e);
         } finally {
             compoundEditRoot.commit();
         }
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/SQLTypeTreeModel.java Mon May 17 15:44:33 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/SQLTypeTreeModel.java Thu Jul 22 14:31:50 2010
@@ -50,18 +50,11 @@
     /**
      * This {...@link Comparator} can compare {...@link UserDefinedSQLType} and
* {...@link DomainCategory} objects. {...@link UserDefinedSQLType}s always come - * after {...@link DomainCategory}s. Comparison between objects with different
-     * parents should never occur.
+     * after {...@link DomainCategory}s.
      */
private final Comparator<SPObject> typeComparator = new Comparator<SPObject>() {

         public int compare(SPObject spo1, SPObject spo2) {
-            if (spo1.getParent() != spo2.getParent()) {
-                throw new ClassCastException("Cannot compare " +
-                               spo1.getClass().getSimpleName() + " and " +
-                               DomainCategory.class.getSimpleName() + " objects 
with " +
-                               "different parents.");
-            }

if (spo1 instanceof UserDefinedSQLType && spo2 instanceof UserDefinedSQLType) { return Integer.signum(spo1.getName().compareToIgnoreCase(spo2.getName()));

Reply via email to