Revision: 3850
Author: mo.jeff
Date: Mon Aug  9 08:35:34 2010
Log: A little bit of refactoring so to help reduce the size of createSPObjectSnapshot()
http://code.google.com/p/power-architect/source/detail?r=3850

Modified:
/trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java Fri Aug 6 16:17:03 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java Mon Aug 9 08:35:34 2010
@@ -103,6 +103,7 @@
                } else if (e.getChild() instanceof SQLColumn) {
                        SQLColumn sqlColumn = (SQLColumn) e.getChild();
                        sqlColumn.getUserDefinedSQLType().addSPListener(this);
+ UserDefinedSQLType upstreamType = sqlColumn.getUserDefinedSQLType().getUpstreamType();
                }
        }

@@ -265,23 +266,7 @@
                 !(upstreamTypeParent instanceof DomainCategory &&
                     upstreamTypeParent.getParent().equals(collection))) {

- // Check if a snapshot for the upstreamType already exists. If so, just use that.
-            boolean snapshotExists = false;
-            List<UserDefinedSQLTypeSnapshot> typeSnapshots =
- session.getWorkspace().getSnapshotCollection().getChildren(UserDefinedSQLTypeSnapshot.class);
-            for (UserDefinedSQLTypeSnapshot typeSnapshot : typeSnapshots) {
- // If the snapshot is a domain snapshot, but the upstream type
-                // is not a domain, then move on to the next snapshot.
-                if (typeSnapshot.isDomainSnapshot() &&
- !(upstreamType.getParent() instanceof DomainCategory)) continue;
-
- if (upstreamType.getUUID().equals(typeSnapshot.getOriginalUUID())) {
-                    typeProxy.setUpstreamType(typeSnapshot.getSPObject());
- typeSnapshot.setSnapshotUseCount(typeSnapshot.getSnapshotUseCount() + 1);
-                    snapshotExists = true;
-                    break;
-                }
-            }
+ boolean snapshotExists = setUpstreamTypeToExistingSnapshot(typeProxy, upstreamType); if (snapshotExists) return; // If snapshot already existed, then nothing else needs to be done

             // Otherwise, we have to create a new snapshot
@@ -344,6 +329,36 @@
             }
         }
     }
+
+    /**
+     * If the upstreamType has an existing snapshot of it, then set the
+ * typeProxy's upstream type to the snapshot of that type instead of the + * original. This is to prevent multiple snapshots of a type to be created
+     * every time that type is used.
+     *
+     * @return True if an existing snapshot for the given upstream type was
+     *         found Otherwise, return false.
+     */
+ private boolean setUpstreamTypeToExistingSnapshot(UserDefinedSQLType typeProxy, UserDefinedSQLType upstreamType) { + // Check if a snapshot for the upstreamType already exists. If so, just use that.
+        boolean snapshotExists = false;
+        List<UserDefinedSQLTypeSnapshot> typeSnapshots =
+ session.getWorkspace().getSnapshotCollection().getChildren(UserDefinedSQLTypeSnapshot.class);
+        for (UserDefinedSQLTypeSnapshot typeSnapshot : typeSnapshots) {
+            // If the snapshot is a domain snapshot, but the upstream type
+            // is not a domain, then move on to the next snapshot.
+            if (typeSnapshot.isDomainSnapshot() &&
+ !(upstreamType.getParent() instanceof DomainCategory)) continue;
+
+ if (upstreamType.getUUID().equals(typeSnapshot.getOriginalUUID())) {
+                typeProxy.setUpstreamType(typeSnapshot.getSPObject());
+ typeSnapshot.setSnapshotUseCount(typeSnapshot.getSnapshotUseCount() + 1);
+                snapshotExists = true;
+                break;
+            }
+        }
+        return snapshotExists;
+    }

     @Override
     public void transactionStarted(TransactionEvent e) {

Reply via email to