Revision: 3828
Author: [email protected]
Date: Tue Aug 3 09:38:48 2010
Log: Added a pooling listener to the client that will update the snapshot's
obsolete flag when a new snapshot is added. This is for use in loading a
project that has old snapshots that need to be marked obsolete due to
changed types.
http://code.google.com/p/power-architect/source/detail?r=3828
Modified:
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Tue Aug 3 08:39:01 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/ArchitectClientSideSession.java
Tue Aug 3 09:38:48 2010
@@ -71,6 +71,8 @@
import ca.sqlpower.enterprise.client.RevisionController;
import ca.sqlpower.enterprise.client.SPServerInfo;
import ca.sqlpower.enterprise.client.User;
+import ca.sqlpower.object.AbstractPoolingSPListener;
+import ca.sqlpower.object.SPChildEvent;
import ca.sqlpower.object.SPObjectSnapshot;
import ca.sqlpower.object.SPObjectUUIDComparator;
import ca.sqlpower.sql.DataSourceCollection;
@@ -153,7 +155,7 @@
String name, ProjectLocation projectLocation) throws SQLObjectException
{
super(context, name, new ArchitectSwingProject());
- getTargetDatabase().addSPListener(new
SPObjectSnapshotHierarchyListener(this));
+ setupSnapshots();
this.projectLocation = projectLocation;
this.isEnterpriseSession = true;
@@ -201,6 +203,36 @@
throw new AssertionError("Exception encountered while
verifying the server license:" + e.getMessage());
}
}
+
+ /**
+ * Helper method for the constructor of a client side session.
+ * <p>
+ * This method will attach listeners and update snapshots as necessary
on
+ * the project's load.
+ */
+ private void setupSnapshots() {
+ getTargetDatabase().addSPListener(new
SPObjectSnapshotHierarchyListener(this));
+
+ //This listener will update the obsolete flag on snapshots being
added
+ //to the workspace to keep old snapshot's obsolete flag correct
when
+ //they haven't been opened in some time but updates have occurred
to the types.
+ //While this will also check new snapshots being added to the
system doing
+ //the check doesn't hurt anything.
+ getWorkspace().addSPListener(new AbstractPoolingSPListener() {
+ @Override
+ public void childAddedImpl(SPChildEvent e) {
+ if (e.getChild() instanceof UserDefinedSQLTypeSnapshot) {
+ UserDefinedSQLTypeSnapshot snapshot =
(UserDefinedSQLTypeSnapshot) e.getChild();
+ if (!snapshot.isObsolete()) {
+ UserDefinedSQLType systemType =
findSystemTypeFromSnapshot(snapshot);
+ if
(!UserDefinedSQLType.areEqual(snapshot.getSPObject(), systemType)) {
+ snapshot.setObsolete(true);
+ }
+ }
+ }
+ }
+ });
+ }
// -