Revision: 3841
Author: [email protected]
Date: Thu Aug 5 12:09:29 2010
Log: Added the undo manager's event listener to the snapshots in the
project. Now the snapshots will undo and redo correctly on the server.
To have the undo manager's listener attach correctly to just the snapshots
the snapshots were moved from being direct children of the project to
children inside a SnapshotCollection object under the project. This also
lets us maintain the snapshots easier.
http://code.google.com/p/power-architect/source/detail?r=3841
Added:
/trunk/src/main/java/ca/sqlpower/architect/SnapshotCollection.java
Modified:
/trunk/regress/ca/sqlpower/architect/SPObjectSnapshotHierarchyListenerTest.java
/trunk/src/main/java/ca/sqlpower/architect/ArchitectProject.java
/trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectSessionPersister.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/DataMoverPanel.java
/trunk/src/main/java/ca/sqlpower/architect/undo/ArchitectUndoManager.java
=======================================
--- /dev/null
+++ /trunk/src/main/java/ca/sqlpower/architect/SnapshotCollection.java Thu
Aug 5 12:09:29 2010
@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL Power Architect is free software; you can redistribute it and/or
modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SQL Power Architect is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package ca.sqlpower.architect;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import ca.sqlpower.architect.enterprise.DomainCategory;
+import ca.sqlpower.object.AbstractSPObject;
+import ca.sqlpower.object.SPObject;
+import ca.sqlpower.object.SPObjectSnapshot;
+import ca.sqlpower.object.annotation.NonProperty;
+import ca.sqlpower.sqlobject.UserDefinedSQLType;
+
+/**
+ * This object contains all of the {...@link SPObjectSnapshot}s and the
copies of
+ * the objects they represent. This is mainly for convenience to keep them
+ * grouped together.
+ */
+public class SnapshotCollection extends AbstractSPObject {
+
+ /**
+ * Defines an absolute ordering of the child types of this class.
+ *
+ * IMPORTANT!: When changing this, ensure you maintain the order
specified by {...@link #getChildren()}
+ */
+ @SuppressWarnings("unchecked")
+ public static final List<Class<? extends SPObject>> allowedChildTypes
= Collections
+ .unmodifiableList(new ArrayList<Class<? extends
SPObject>>(Arrays.asList(UserDefinedSQLType.class,
+ DomainCategory.class, SPObjectSnapshot.class)));
+
+ /**
+ * The list of all snapshots in our current system. This includes
types,
+ * domains, and domain category snapshots.
+ */
+ private final List<SPObjectSnapshot<?>> spobjectSnapshots = new
ArrayList<SPObjectSnapshot<?>>();
+
+ /**
+ * List of all copies of {...@link UserDefinedSQLType}s that existed at
some
+ * point in the system workspace and are in use in the project.
+ */
+ private final List<UserDefinedSQLType> udtSnapshots = new
ArrayList<UserDefinedSQLType>();
+
+ /**
+ * List of all copies of {...@link DomainCategory} that existed at some
point
+ * in the system workspace and are in use in the project.
+ */
+ private final List<DomainCategory> categorySnapshots = new
ArrayList<DomainCategory>();
+
+ public SnapshotCollection() {
+ setName("Default snapshot collection");
+ }
+
+ @Override
+ protected void addChildImpl(SPObject child, int index) {
+ if (child instanceof SPObjectSnapshot<?>) {
+ addSPObjectSnapshot((SPObjectSnapshot<?>) child, index);
+ } else if (child instanceof UserDefinedSQLType) {
+ addUDTSnapshot((UserDefinedSQLType) child, index);
+ } else if (child instanceof DomainCategory) {
+ addCategorySnapshot((DomainCategory) child, index);
+ }
+ }
+
+ public void addCategorySnapshot(DomainCategory domainCategory, int
index) {
+ categorySnapshots.add(index, domainCategory);
+ domainCategory.setParent(this);
+ fireChildAdded(DomainCategory.class, domainCategory, index);
+ }
+
+ public void addUDTSnapshot(UserDefinedSQLType sqlType, int index) {
+ udtSnapshots.add(index, sqlType);
+ sqlType.setParent(this);
+ fireChildAdded(UserDefinedSQLType.class, sqlType, index);
+ }
+
+ public boolean removeUDTSnapshot(UserDefinedSQLType child) {
+ int index = udtSnapshots.indexOf(child);
+ boolean removed = udtSnapshots.remove(child);
+ if (removed) {
+ fireChildRemoved(UserDefinedSQLType.class, child, index);
+ child.setParent(null);
+ }
+ return removed;
+ }
+
+ public boolean removeCategorySnapshot(DomainCategory child) {
+ int index = categorySnapshots.indexOf(child);
+ boolean removed = categorySnapshots.remove(child);
+ if (removed) {
+ fireChildRemoved(DomainCategory.class, child, index);
+ child.setParent(null);
+ }
+ return removed;
+ }
+
+ @Override
+ protected boolean removeChildImpl(SPObject child) {
+ if (child instanceof SPObjectSnapshot<?>) {
+ return removeSPObjectSnapshot((SPObjectSnapshot<?>) child);
+ } else if (child instanceof UserDefinedSQLType) {
+ return removeUDTSnapshot((UserDefinedSQLType) child);
+ } else if (child instanceof DomainCategory) {
+ return removeCategorySnapshot((DomainCategory) child);
+ }
+ return false;
+ }
+
+ @Override
+ public List<Class<? extends SPObject>> getAllowedChildTypes() {
+ return allowedChildTypes;
+ }
+
+ @Override
+ public List<? extends SPObject> getChildren() {
+ List<SPObject> children = new ArrayList<SPObject>();
+ children.addAll(udtSnapshots);
+ children.addAll(categorySnapshots);
+ children.addAll(spobjectSnapshots);
+ return Collections.unmodifiableList(children);
+ }
+
+ @Override
+ public List<? extends SPObject> getDependencies() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public void removeDependency(SPObject dependency) {
+ for (UserDefinedSQLType snapshot : udtSnapshots) {
+ snapshot.removeDependency(dependency);
+ }
+ for (DomainCategory category : categorySnapshots) {
+ category.removeDependency(dependency);
+ }
+ for (SPObjectSnapshot<?> snapshot : spobjectSnapshots) {
+ snapshot.removeDependency(dependency);
+ }
+ }
+
+ public boolean removeSPObjectSnapshot(SPObjectSnapshot<?> child) {
+ int index = spobjectSnapshots.indexOf(child);
+ boolean removed = spobjectSnapshots.remove(child);
+ if (removed) {
+ fireChildRemoved(SPObjectSnapshot.class, child, index);
+ child.setParent(null);
+ }
+ return removed;
+ }
+
+ protected void addSPObjectSnapshot(SPObjectSnapshot<?> child, int
index) {
+ spobjectSnapshots.add(index, child);
+ child.setParent(this);
+ fireChildAdded(SPObjectSnapshot.class, child, index);
+ }
+
+ @NonProperty
+ protected List<SPObjectSnapshot<?>> getSPObjectSnapshots() {
+ return Collections.unmodifiableList(spobjectSnapshots);
+ }
+}
=======================================
---
/trunk/regress/ca/sqlpower/architect/SPObjectSnapshotHierarchyListenerTest.java
Wed Aug 4 09:24:41 2010
+++
/trunk/regress/ca/sqlpower/architect/SPObjectSnapshotHierarchyListenerTest.java
Thu Aug 5 12:09:29 2010
@@ -115,10 +115,10 @@
col.getUserDefinedSQLType().setUpstreamType(systemType1);
table.addColumn(col);
- assertEquals(1,
session.getWorkspace().getSPObjectSnapshots().size());
+ assertEquals(1,
session.getWorkspace().getSnapshotCollection().getSPObjectSnapshots().size());
assertEquals(1,
session.getWorkspace().getChildren(UserDefinedSQLType.class).size());
assertTrue(session.getWorkspace().getChildren(UserDefinedSQLType.class).get(0)
==
-
session.getWorkspace().getSPObjectSnapshots().get(0).getSPObject());
+
session.getWorkspace().getSnapshotCollection().getSPObjectSnapshots().get(0).getSPObject());
}
/**
@@ -133,20 +133,20 @@
col.getUserDefinedSQLType().setUpstreamType(systemType1);
table.addColumn(col);
- assertEquals(1,
session.getWorkspace().getSPObjectSnapshots().size());
+ assertEquals(1,
session.getWorkspace().getSnapshotCollection().getSPObjectSnapshots().size());
assertEquals(1,
session.getWorkspace().getChildren(UserDefinedSQLType.class).size());
UserDefinedSQLType snapshotUDT =
session.getWorkspace().getChildren(UserDefinedSQLType.class).get(0);
- SPObjectSnapshot<?> snapshot =
session.getWorkspace().getSPObjectSnapshots().get(0);
+ SPObjectSnapshot<?> snapshot =
session.getWorkspace().getSnapshotCollection().getSPObjectSnapshots().get(0);
assertTrue(snapshotUDT == snapshot.getSPObject());
assertEquals(systemType1.getUUID(), snapshot.getOriginalUUID());
assertEquals(systemType1.getName(), snapshotUDT.getName());
col.getUserDefinedSQLType().setUpstreamType(systemType2);
- assertEquals(1,
session.getWorkspace().getSPObjectSnapshots().size());
+ assertEquals(1,
session.getWorkspace().getSnapshotCollection().getSPObjectSnapshots().size());
assertEquals(1,
session.getWorkspace().getChildren(UserDefinedSQLType.class).size());
snapshotUDT =
session.getWorkspace().getChildren(UserDefinedSQLType.class).get(0);
- snapshot = session.getWorkspace().getSPObjectSnapshots().get(0);
+ snapshot =
session.getWorkspace().getSnapshotCollection().getSPObjectSnapshots().get(0);
assertTrue(snapshotUDT == snapshot.getSPObject());
assertEquals(systemType2.getUUID(), snapshot.getOriginalUUID());
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectProject.java Tue
Aug 3 08:39:01 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectProject.java Thu
Aug 5 12:09:29 2010
@@ -33,15 +33,14 @@
import ca.sqlpower.object.AbstractSPObject;
import ca.sqlpower.object.ObjectDependentException;
import ca.sqlpower.object.SPObject;
-import ca.sqlpower.object.SPObjectSnapshot;
import ca.sqlpower.object.annotation.Accessor;
import ca.sqlpower.object.annotation.Constructor;
import ca.sqlpower.object.annotation.ConstructorParameter;
-import ca.sqlpower.object.annotation.ConstructorParameter.ParameterType;
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.object.annotation.ConstructorParameter.ParameterType;
import ca.sqlpower.sql.JDBCDataSource;
import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLObject;
@@ -71,7 +70,7 @@
@SuppressWarnings("unchecked")
public static final List<Class<? extends SPObject>> allowedChildTypes
= Collections
.unmodifiableList(new ArrayList<Class<? extends
SPObject>>(Arrays.asList(UserDefinedSQLType.class,
- DomainCategory.class, SPObjectSnapshot.class,
SQLObjectRoot.class, ProfileManager.class,
+ DomainCategory.class, SnapshotCollection.class,
SQLObjectRoot.class, ProfileManager.class,
ProjectSettings.class, User.class, Group.class,
BusinessDefinition.class,
FormulaMetricCalculation.class)));
@@ -87,11 +86,6 @@
private List<Group> groups = new ArrayList<Group>();
private final List<UserDefinedSQLType> sqlTypes = new
ArrayList<UserDefinedSQLType>();
- /**
- * The list of all snapshots in our current system. This includes
types,
- * domains, and domain category snapshots.
- */
- private final List<SPObjectSnapshot<?>> spobjectSnapshots = new
ArrayList<SPObjectSnapshot<?>>();
private final List<DomainCategory> domainCategories = new
ArrayList<DomainCategory>();
// Metadata children
@@ -101,6 +95,11 @@
// Metadata property
private String etlProcessDescription;
+ /**
+ * A collection of all of the snapshots in this project.
+ */
+ private final SnapshotCollection snapshotCollection;
+
/**
* The current integrity watcher on the project.
*/
@@ -116,11 +115,29 @@
* @throws SQLObjectException
*/
public ArchitectProject() throws SQLObjectException {
- this(new SQLObjectRoot(), null);
+ this(new SQLObjectRoot(), null, new SnapshotCollection());
SQLDatabase targetDatabase = new SQLDatabase();
targetDatabase.setPlayPenDatabase(true);
rootObject.addChild(targetDatabase, 0);
}
+
+ /**
+ * The init method for this project must be called immediately after
this
+ * object is constructed.
+ * <p>
+ * This will rely on the target database being added from the persist
calls
+ * that creates this project.
+ * <p>
+ * The profile manager will be set to null with this constructor so if
one
+ * is needed it should be set at sometime in the future before use.
+ *
+ * @param rootObject
+ * The root object that holds all of the source databases
for the
+ * current project.
+ */
+ public ArchitectProject(SQLObjectRoot root) throws SQLObjectException {
+ this(root, null, new SnapshotCollection());
+ }
/**
* The init method for this project must be called immediately after
this
@@ -132,22 +149,23 @@
* @param rootObject
* The root object that holds all of the source databases
for the
* current project.
- * @param olapRootObject
- * The root object of OLAP projects. All OLAP projects will
be
- * contained under this node.
- * @param kettleSettings
- * The settings to create Kettle jobs for this project.
* @param profileManager
* The default profile manager for this project. This may
be null
* if it is set later or the profile manager is not used.
+ * @param snapshotCollection
+ * An object that will hold all of the snapshots and copied
types
+ * and domains for the current project.
*/
@Constructor
public ArchitectProject(
@ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="rootObject") SQLObjectRoot rootObject,
- @ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="profileManager") ProfileManager profileManager)
+ @ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="profileManager") ProfileManager profileManager,
+ @ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="snapshotCollection") SnapshotCollection snapshotCollection)
throws SQLObjectException {
this.rootObject = rootObject;
rootObject.setParent(this);
+ this.snapshotCollection = snapshotCollection;
+ snapshotCollection.setParent(this);
projectSettings = new ProjectSettings();
projectSettings.setParent(this);
if (profileManager != null) {
@@ -258,8 +276,6 @@
return removeSQLType((UserDefinedSQLType) child);
} else if (child instanceof DomainCategory) {
return removeDomainCategory((DomainCategory) child);
- } else if (child instanceof SPObjectSnapshot<?>) {
- return removeSPObjectSnapshot((SPObjectSnapshot<?>) child);
} else if (child instanceof BusinessDefinition) {
return removeBusinessDefinition((BusinessDefinition) child);
} else if (child instanceof FormulaMetricCalculation) {
@@ -305,16 +321,6 @@
fireChildRemoved(DomainCategory.class, child, index);
child.setParent(null);
}
- return removed;
- }
-
- public boolean removeSPObjectSnapshot(SPObjectSnapshot<?> child) {
- int index = spobjectSnapshots.indexOf(child);
- boolean removed = spobjectSnapshots.remove(child);
- if (removed) {
- fireChildRemoved(SPObjectSnapshot.class, child, index);
- child.setParent(null);
- }
return removed;
}
@@ -369,7 +375,7 @@
// When changing this, ensure you maintain the order specified by
allowedChildTypes
allChildren.addAll(sqlTypes);
allChildren.addAll(domainCategories);
- allChildren.addAll(spobjectSnapshots);
+ allChildren.add(snapshotCollection);
allChildren.add(rootObject);
if (profileManager != null) {
allChildren.add(profileManager);
@@ -406,8 +412,6 @@
addSQLType((UserDefinedSQLType) child, index);
} else if (child instanceof DomainCategory) {
addDomainCategory((DomainCategory) child, index);
- } else if (child instanceof SPObjectSnapshot<?>) {
- addSPObjectSnapshot((SPObjectSnapshot<?>) child, index);
} else if (child instanceof BusinessDefinition) {
addBusinessDefinition((BusinessDefinition) child, index);
} else if (child instanceof FormulaMetricCalculation) {
@@ -435,22 +439,11 @@
sqlType.setParent(this);
fireChildAdded(UserDefinedSQLType.class, sqlType, index);
}
-
- protected void addSPObjectSnapshot(SPObjectSnapshot<?> child, int
index) {
- spobjectSnapshots.add(index, child);
- child.setParent(this);
- fireChildAdded(SPObjectSnapshot.class, child, index);
- }
@NonProperty
public List<UserDefinedSQLType> getSqlTypes() {
return Collections.unmodifiableList(sqlTypes);
}
-
- @NonProperty
- protected List<SPObjectSnapshot<?>> getSPObjectSnapshots() {
- return Collections.unmodifiableList(spobjectSnapshots);
- }
@NonProperty
public List<DomainCategory> getDomainCategories() {
@@ -520,5 +513,9 @@
this.etlProcessDescription = etlProcessDescription;
firePropertyChange("etlProcessDescription", oldDescription,
etlProcessDescription);
}
+
+ public SnapshotCollection getSnapshotCollection() {
+ return snapshotCollection;
+ }
}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java
Wed Aug 4 13:00:45 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/SPObjectSnapshotHierarchyListener.java
Thu Aug 5 12:09:29 2010
@@ -124,6 +124,9 @@
* Either the column is being removed or the type is
changing.
*/
private void cleanupSnapshot(UserDefinedSQLType typeRemoved) {
+
+ SnapshotCollection collection =
session.getWorkspace().getSnapshotCollection();
+
//The first type set will be from the system workspace and will not
//have a snapshot, then the snapshot will replace the one set from
the system.
if (typeRemoved.getParent() == session.getSystemWorkspace() ||
@@ -131,7 +134,7 @@
typeRemoved.getParent().getParent() ==
session.getSystemWorkspace())) return;
UserDefinedSQLTypeSnapshot udtSnapshot = null;
- for (SPObjectSnapshot<?> snapshot :
session.getWorkspace().getSPObjectSnapshots()) {
+ for (SPObjectSnapshot<?> snapshot :
collection.getSPObjectSnapshots()) {
if (snapshot.getSPObject().equals(typeRemoved)) {
udtSnapshot = (UserDefinedSQLTypeSnapshot) snapshot;
udtSnapshot.setSnapshotUseCount(udtSnapshot.getSnapshotUseCount() - 1);
@@ -143,7 +146,7 @@
" is a snapshot type but does not have a snapshot object in
the project.");
//If we are here the snapshot is no longer in use.
- session.getWorkspace().removeSPObjectSnapshot(udtSnapshot);
+ collection.removeSPObjectSnapshot(udtSnapshot);
try {
if (udtSnapshot.isDomainSnapshot()) {
DomainCategory cat = (DomainCategory)
udtSnapshot.getSPObject().getParent();
@@ -156,16 +159,16 @@
cleanupSnapshot(udtSnapshot.getSPObject().getUpstreamType());
if (cat.getChildren().size() == 0) {
- for (SPObjectSnapshot<?> snapshot :
session.getWorkspace().getSPObjectSnapshots()) {
+ for (SPObjectSnapshot<?> snapshot :
collection.getSPObjectSnapshots()) {
if (snapshot.getSPObject().equals(cat)) {
- session.getWorkspace().removeChild(snapshot);
- session.getWorkspace().removeChild(cat);
+ collection.removeChild(snapshot);
+ collection.removeChild(cat);
break;
}
}
}
} else {
-
session.getWorkspace().removeChild(udtSnapshot.getSPObject());
+ collection.removeChild(udtSnapshot.getSPObject());
}
} catch (Exception e) {
throw new RuntimeException(e);
@@ -187,38 +190,51 @@
* This type is a type that is a snapshot of a system type
used in a column.
*/
private void addUpdateListener(UserDefinedSQLType
upstreamSnapshotType) {
-
- SPObjectSnapshot<?> snapshot = null;
- for (SPObjectSnapshot<?> workspaceSnapshot :
session.getWorkspace().getSPObjectSnapshots()) {
- if (workspaceSnapshot.getSPObject() == upstreamSnapshotType) {
- snapshot = workspaceSnapshot;
- break;
- }
- }
-
- UserDefinedSQLType systemType =
session.findSystemTypeFromSnapshot(snapshot);
- SPObjectSnapshotUpdateListener udtSnapshotListener = new
SPObjectSnapshotUpdateListener(snapshot);
- SQLPowerUtils.listenToHierarchy(systemType, udtSnapshotListener);
- listenerMap.put(snapshot, udtSnapshotListener);
- if (systemType.getParent() instanceof DomainCategory) {
- DomainCategory category = (DomainCategory)
systemType.getParent();
- for (SPObjectSnapshot<?> categorySnapshot :
session.getWorkspace().getSPObjectSnapshots()) {
- if
(categorySnapshot.getOriginalUUID().equals(category.getUUID())) {
- SPObjectSnapshotUpdateListener
categorySnapshotListener = new
SPObjectSnapshotUpdateListener(categorySnapshot);
- category.addSPListener(categorySnapshotListener);
- listenerMap.put(categorySnapshot,
categorySnapshotListener);
+
+ SnapshotCollection collection =
session.getWorkspace().getSnapshotCollection();
+
+ //check if the upstream type is actually a system type. Happens on
undo.
+ SPObject upstreamTypeParent = upstreamSnapshotType.getParent();
+ if (upstreamTypeParent == null ||
upstreamTypeParent.equals(collection) ||
+ (upstreamTypeParent instanceof DomainCategory &&
+ upstreamTypeParent.getParent().equals(collection))) {
+
+ SPObjectSnapshot<?> snapshot = null;
+ for (SPObjectSnapshot<?> workspaceSnapshot :
collection.getSPObjectSnapshots()) {
+ if (workspaceSnapshot.getSPObject() ==
upstreamSnapshotType) {
+ snapshot = workspaceSnapshot;
break;
}
}
+
+ UserDefinedSQLType systemType =
session.findSystemTypeFromSnapshot(snapshot);
+ SPObjectSnapshotUpdateListener udtSnapshotListener = new
SPObjectSnapshotUpdateListener(snapshot);
+ SQLPowerUtils.listenToHierarchy(systemType,
udtSnapshotListener);
+ listenerMap.put(snapshot, udtSnapshotListener);
+ if (systemType.getParent() instanceof DomainCategory) {
+ DomainCategory category = (DomainCategory)
systemType.getParent();
+ for (SPObjectSnapshot<?> categorySnapshot :
collection.getSPObjectSnapshots()) {
+ if
(categorySnapshot.getOriginalUUID().equals(category.getUUID())) {
+ SPObjectSnapshotUpdateListener
categorySnapshotListener = new
SPObjectSnapshotUpdateListener(categorySnapshot);
+ category.addSPListener(categorySnapshotListener);
+ listenerMap.put(categorySnapshot,
categorySnapshotListener);
+ break;
+ }
+ }
+ }
}
}
private void createSPObjectSnapshot(UserDefinedSQLType typeProxy,
UserDefinedSQLType upstreamType) {
+ if (!typeProxy.isMagicEnabled()) return;
+
SPObject upstreamTypeParent = upstreamType.getParent();
-
- if (upstreamTypeParent != null
&& !upstreamTypeParent.equals(session.getWorkspace()) &&
+
+ SnapshotCollection collection =
session.getWorkspace().getSnapshotCollection();
+
+ if (upstreamTypeParent != null
&& !upstreamTypeParent.equals(collection) &&
!(upstreamTypeParent instanceof DomainCategory &&
-
upstreamTypeParent.getParent().equals(session.getWorkspace()))) {
+ upstreamTypeParent.getParent().equals(collection))) {
int systemRevision =
session.getSystemSession().getCurrentRevisionNumber();
boolean isDomainSnapshot = upstreamType.getParent() instanceof
DomainCategory;
@@ -233,7 +249,7 @@
UserDefinedSQLTypeSnapshot upstreamSnapshot = null;
boolean existingSnapshotFound = false;
- for (SPObjectSnapshot<?> workspaceSnapshot :
session.getWorkspace().getSPObjectSnapshots()) {
+ for (SPObjectSnapshot<?> workspaceSnapshot :
collection.getSPObjectSnapshots()) {
if
(workspaceSnapshot.getOriginalUUID().equals(upUpStreamType.getUUID()) &&
workspaceSnapshot instanceof
UserDefinedSQLTypeSnapshot) {
upstreamSnapshot = (UserDefinedSQLTypeSnapshot)
workspaceSnapshot;
@@ -244,8 +260,8 @@
}
if (!existingSnapshotFound) {
upstreamSnapshot = new
UserDefinedSQLTypeSnapshot(upUpStreamType, systemRevision,
isUpstreamDomainSnapshot);
- session.getWorkspace().addChild(upstreamSnapshot, 0);
-
session.getWorkspace().addChild(upstreamSnapshot.getSPObject(), 0);
+ collection.addChild(upstreamSnapshot, 0);
+ collection.addChild(upstreamSnapshot.getSPObject(), 0);
upstreamSnapshot.setSnapshotUseCount(1);
addUpdateListener(upstreamSnapshot.getSPObject());
}
@@ -253,24 +269,24 @@
} else {
snapshot = new UserDefinedSQLTypeSnapshot(upstreamType,
systemRevision, isDomainSnapshot);
}
- session.getWorkspace().addChild(snapshot, 0);
+ collection.addChild(snapshot, 0);
if ((upstreamType.getParent() instanceof DomainCategory)) {
DomainCategory parent = (DomainCategory)
upstreamType.getParent();
DomainCategorySnapshot domainSnapshot =
new DomainCategorySnapshot(parent, systemRevision);
- session.getWorkspace().addChild(domainSnapshot, 0);
-
session.getWorkspace().addChild(domainSnapshot.getSPObject(), 0);
+ collection.addChild(domainSnapshot, 0);
+ collection.addChild(domainSnapshot.getSPObject(), 0);
domainSnapshot.getSPObject().addChild(snapshot.getSPObject(), 0);
} else {
- session.getWorkspace().addChild(snapshot.getSPObject(), 0);
+ collection.addChild(snapshot.getSPObject(), 0);
}
typeProxy.setUpstreamType(snapshot.getSPObject());
snapshot.setSnapshotUseCount(1);
} else if (upstreamTypeParent != null &&
- (upstreamTypeParent.equals(session.getWorkspace()) ||
+ (upstreamTypeParent.equals(collection) ||
(upstreamTypeParent instanceof DomainCategory &&
-
upstreamTypeParent.getParent().equals(session.getWorkspace())))) {
- for (SPObjectSnapshot<?> snapshot :
session.getWorkspace().getSPObjectSnapshots()) {
+
upstreamTypeParent.getParent().equals(collection)))) {
+ for (SPObjectSnapshot<?> snapshot :
collection.getSPObjectSnapshots()) {
if (snapshot.getSPObject().equals(upstreamType)) {
UserDefinedSQLTypeSnapshot udtSnapshot =
(UserDefinedSQLTypeSnapshot) snapshot;
udtSnapshot.setSnapshotUseCount(udtSnapshot.getSnapshotUseCount() + 1);
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Wed Aug 4 13:00:45 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Thu Aug 5 12:09:29 2010
@@ -56,6 +56,7 @@
import ca.sqlpower.architect.ArchitectSessionContext;
import ca.sqlpower.architect.ArchitectSessionImpl;
import ca.sqlpower.architect.SPObjectSnapshotHierarchyListener;
+import ca.sqlpower.architect.SnapshotCollection;
import ca.sqlpower.architect.ddl.DDLGenerator;
import ca.sqlpower.architect.swingui.ArchitectSwingProject;
import ca.sqlpower.architect.swingui.ArchitectSwingSessionContext;
@@ -1095,9 +1096,11 @@
// 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?
+ SnapshotCollection collection =
getWorkspace().getSnapshotCollection();
+
List<UserDefinedSQLTypeSnapshot> typeSnapshots =
new ArrayList<UserDefinedSQLTypeSnapshot>(
-
getWorkspace().getChildren(UserDefinedSQLTypeSnapshot.class));
+
collection.getChildren(UserDefinedSQLTypeSnapshot.class));
List<UserDefinedSQLType> systemTypes =
new ArrayList<UserDefinedSQLType>(
getSystemWorkspace().getChildren(UserDefinedSQLType.class));
@@ -1164,8 +1167,10 @@
// 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?
+ SnapshotCollection collection =
getWorkspace().getSnapshotCollection();
+
List<UserDefinedSQLTypeSnapshot> typeSnapshots =
- new
ArrayList<UserDefinedSQLTypeSnapshot>(getWorkspace().getChildren(UserDefinedSQLTypeSnapshot.class));
+ new
ArrayList<UserDefinedSQLTypeSnapshot>(collection.getChildren(UserDefinedSQLTypeSnapshot.class));
List<DomainCategory> systemCategories =
new
ArrayList<DomainCategory>(getSystemWorkspace().getChildren(DomainCategory.class));
List<UserDefinedSQLTypeSnapshot> domainSnapshots = new
ArrayList<UserDefinedSQLTypeSnapshot>();
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectSessionPersister.java
Tue Jun 29 09:19:15 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectSessionPersister.java
Thu Aug 5 12:09:29 2010
@@ -22,6 +22,7 @@
import java.util.ArrayList;
import java.util.List;
+import ca.sqlpower.architect.SnapshotCollection;
import ca.sqlpower.architect.ddl.critic.CriticManager;
import ca.sqlpower.architect.etl.kettle.KettleSettings;
import ca.sqlpower.architect.olap.OLAPRootObject;
@@ -94,6 +95,14 @@
architectProject.getCriticManager().clear();
+ String snapshotCollectionUUID = (String)
AbstractSPPersisterHelper.findPropertyAndRemove(
+ pso.getUUID(), "snapshotCollection", persistedProperties);
+
+ PersistedSPObject snapshotCollectionSettings =
AbstractSPPersisterHelper.findPersistedSPObject(
+ pso.getUUID(), SnapshotCollection.class.getName(),
snapshotCollectionUUID, persistedObjects);
+ snapshotCollectionSettings.setLoaded(true);
+
architectProject.getSnapshotCollection().setUUID(snapshotCollectionUUID);
+
List<PersistedSPObject> databases = new
ArrayList<PersistedSPObject>();
for (PersistedSPObject o : persistedObjects) {
if
(o.getParentUUID().equals(architectProject.getRootObject().getUUID()) &&
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
Fri Jul 30 13:13:38 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectSwingProject.java
Thu Aug 5 12:09:29 2010
@@ -29,6 +29,7 @@
import ca.sqlpower.architect.ArchitectProject;
import ca.sqlpower.architect.ProjectSettings;
+import ca.sqlpower.architect.SnapshotCollection;
import ca.sqlpower.architect.ddl.critic.CriticManager;
import ca.sqlpower.architect.enterprise.BusinessDefinition;
import ca.sqlpower.architect.enterprise.DomainCategory;
@@ -44,14 +45,13 @@
import ca.sqlpower.object.SPChildEvent;
import ca.sqlpower.object.SPListener;
import ca.sqlpower.object.SPObject;
-import ca.sqlpower.object.SPObjectSnapshot;
import ca.sqlpower.object.annotation.Accessor;
import ca.sqlpower.object.annotation.Constructor;
import ca.sqlpower.object.annotation.ConstructorParameter;
-import ca.sqlpower.object.annotation.ConstructorParameter.ParameterType;
import ca.sqlpower.object.annotation.NonBound;
import ca.sqlpower.object.annotation.NonProperty;
import ca.sqlpower.object.annotation.Transient;
+import ca.sqlpower.object.annotation.ConstructorParameter.ParameterType;
import ca.sqlpower.sqlobject.SQLObject;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectRoot;
@@ -78,7 +78,7 @@
@SuppressWarnings("unchecked")
public static final List<Class<? extends SPObject>> allowedChildTypes
= Collections
.unmodifiableList(new ArrayList<Class<? extends
SPObject>>(Arrays.asList(UserDefinedSQLType.class,
- DomainCategory.class, SPObjectSnapshot.class,
SQLObjectRoot.class,
+ DomainCategory.class, SnapshotCollection.class,
SQLObjectRoot.class,
OLAPRootObject.class, PlayPenContentPane.class,
ProfileManager.class, ProjectSettings.class,
CriticManager.class, KettleSettings.class, User.class,
Group.class,
BusinessDefinition.class,
FormulaMetricCalculation.class)));
@@ -196,9 +196,10 @@
@ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="olapRootObject") OLAPRootObject olapRootObject,
@ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="kettleSettings") KettleSettings kettleSettings,
@ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="profileManager") ProfileManager profileManager,
- @ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="criticManager") CriticManager criticManager
+ @ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="criticManager") CriticManager criticManager,
+ @ConstructorParameter(parameterType=ParameterType.CHILD,
propertyName="snapshotCollection") SnapshotCollection snapshotCollection
) throws SQLObjectException {
- super(rootObject, profileManager);
+ super(rootObject, profileManager, snapshotCollection);
this.olapRootObject = olapRootObject;
olapRootObject.setParent(this);
this.kettleSettings = kettleSettings;
@@ -241,7 +242,7 @@
// When changing this, ensure you maintain the order specified by
allowedChildTypes
allChildren.addAll(getSqlTypes());
allChildren.addAll(getDomainCategories());
- allChildren.addAll(getSPObjectSnapshots());
+ allChildren.add(getSnapshotCollection());
allChildren.add(getRootObject());
allChildren.add(olapRootObject);
if (playPenContentPane != null) {
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java Tue Aug
3 08:39:01 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/DBTree.java Thu Aug
5 12:09:29 2010
@@ -146,7 +146,7 @@
public DBTree(final ArchitectSwingSession session) {
this.session = session;
if (session.isEnterpriseSession()) {
- treeModel = new DBTreeModel(session.getRootObject(), this,
session.getWorkspace());
+ treeModel = new DBTreeModel(session.getRootObject(), this,
session.getWorkspace().getSnapshotCollection());
} else {
treeModel = new DBTreeModel(session.getRootObject(), this);
}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/DataMoverPanel.java
Thu Jul 22 12:40:28 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/DataMoverPanel.java
Thu Aug 5 12:09:29 2010
@@ -197,7 +197,7 @@
try {
if (treeRoot == null) {
treeRoot = new SQLObjectRoot();
- ArchitectProject treeProject = new
ArchitectProject(treeRoot, null);
+ ArchitectProject treeProject = new
ArchitectProject(treeRoot);
treeProject.setSession(session);
treeRoot.begin("Setting up database trees in data mover
panel.");
} else {
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/undo/ArchitectUndoManager.java
Mon Jul 12 08:21:11 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/undo/ArchitectUndoManager.java
Thu Aug 5 12:09:29 2010
@@ -29,6 +29,7 @@
import ca.sqlpower.sqlobject.SQLObjectRoot;
import ca.sqlpower.sqlobject.undo.NotifyingUndoManager;
import ca.sqlpower.sqlobject.undo.SQLObjectUndoManager;
+import ca.sqlpower.util.SQLPowerUtils;
public class ArchitectUndoManager extends SQLObjectUndoManager implements
NotifyingUndoManager {
@@ -51,6 +52,7 @@
final ArchitectSwingProject workspace =
playPen.getSession().getWorkspace();
playPen.getContentPane().addSPListener(eventAdapter);
eventAdapter.attachToObject(playPen.getContentPane());
+ SQLPowerUtils.listenToHierarchy(workspace.getSnapshotCollection(),
eventAdapter);
workspace.addSPListener(new AbstractSPListener() {
/**