Revision: 4026
Author: [email protected]
Date: Mon Dec 6 10:49:00 2010
Log: Fixed the exception by checking for missing data types and domain
categories and removing the listener according to what has not been removed.
http://code.google.com/p/power-architect/source/detail?r=4026
Modified:
/trunk/src/main/java/ca/sqlpower/architect/enterprise/SPObjectSnapshotHierarchyListener.java
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/enterprise/SPObjectSnapshotHierarchyListener.java
Wed Dec 1 12:50:47 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/enterprise/SPObjectSnapshotHierarchyListener.java
Mon Dec 6 10:49:00 2010
@@ -237,6 +237,7 @@
//If we are here the snapshot is no longer in use.
collection.removeSPObjectSnapshot(udtSnapshot);
+ SPObjectSnapshot<?> categorySnapshot = null;
try {
if (udtSnapshot.isDomainSnapshot()) {
DomainCategory cat = (DomainCategory)
udtSnapshot.getSPObject().getParent();
@@ -248,15 +249,16 @@
cleanupSnapshot(udtSnapshot.getSPObject().getUpstreamType());
- if (cat.getChildren().size() == 0) {
- for (SPObjectSnapshot<?> snapshot :
collection.getSPObjectSnapshots()) {
- if (snapshot.getSPObject().equals(cat)) {
- collection.removeChild(snapshot);
- collection.removeChild(cat);
- break;
- }
+ for (SPObjectSnapshot<?> snapshot :
collection.getSPObjectSnapshots()) {
+ if (snapshot.getSPObject().equals(cat)) {
+ categorySnapshot = snapshot;
+ break;
}
}
+ if (cat.getChildren().size() == 0) {
+ collection.removeChild(categorySnapshot);
+ collection.removeChild(cat);
+ }
} else {
collection.removeChild(udtSnapshot.getSPObject());
}
@@ -264,9 +266,21 @@
throw new RuntimeException(e);
}
- //find its upstream type and remove its listener.
+ //find its upstream type and remove its listener. Note that the
system type
+ //may have been removed but the snapshot may have existed until this
point.
UserDefinedSQLType systemType =
session.findSystemTypeFromSnapshot(udtSnapshot);
- SQLPowerUtils.unlistenToHierarchy(systemType,
listenerMap.get(udtSnapshot));
+ if (systemType != null) {
+ SQLPowerUtils.unlistenToHierarchy(systemType,
listenerMap.get(udtSnapshot));
+ } else if (categorySnapshot != null) {
+ UserDefinedSQLType systemCategory =
session.findSystemTypeFromSnapshot(categorySnapshot);
+ if (systemCategory != null) {
+ SQLPowerUtils.unlistenToHierarchy(systemCategory,
listenerMap.get(udtSnapshot));
+ } else {
+
SQLPowerUtils.unlistenToHierarchy(session.getSystemWorkspace(),
listenerMap.get(udtSnapshot));
+ }
+ } else {
+ SQLPowerUtils.unlistenToHierarchy(session.getSystemWorkspace(),
listenerMap.get(udtSnapshot));
+ }
//handle domain categories and domain's upstream type as well.
}