Author: thomasobrien95
Date: Tue Jan 13 12:09:25 2009
New Revision: 2917
Added:
trunk/src/ca/sqlpower/architect/SQLObjectHierarchyListener.java
Modified:
trunk/regress/ca/sqlpower/architect/SQLObjectTest.java
trunk/src/ca/sqlpower/architect/SQLObject.java
trunk/src/ca/sqlpower/architect/SQLTable.java
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Log:
Fix for bug 1744. The SQLObject was re-throwing an exception on
populate to allow the exception to be shown in an exception handler
to the user. The exception was causing properly functioning code to
not be executed, which was needed. A new listener in the swing
session listens for changes to a childInaccessibleReason change and
displays the exception to the user.
Modified: trunk/regress/ca/sqlpower/architect/SQLObjectTest.java
==============================================================================
--- trunk/regress/ca/sqlpower/architect/SQLObjectTest.java (original)
+++ trunk/regress/ca/sqlpower/architect/SQLObjectTest.java Tue Jan 13
12:09:25 2009
@@ -251,12 +251,7 @@
}
};
- try {
- o.populate();
- fail();
- } catch (Exception ex) {
- //should get here
- }
+ o.populate();
assertEquals(e, o.getChildrenInaccessibleReason());
Modified: trunk/src/ca/sqlpower/architect/SQLObject.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/SQLObject.java (original)
+++ trunk/src/ca/sqlpower/architect/SQLObject.java Tue Jan 13 12:09:25 2009
@@ -209,11 +209,9 @@
try {
populateImpl();
} catch (ArchitectException e) {
- childrenInaccessibleReason = e;
- throw e;
+ setChildrenInaccessibleReason(e);
} catch (RuntimeException e) {
- childrenInaccessibleReason = e;
- throw e;
+ setChildrenInaccessibleReason(e);
}
}
Added: trunk/src/ca/sqlpower/architect/SQLObjectHierarchyListener.java
==============================================================================
--- (empty file)
+++ trunk/src/ca/sqlpower/architect/SQLObjectHierarchyListener.java Tue Jan
13 12:09:25 2009
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2009, SQL Power Group Inc.
+ *
+ * This file is part of Power*Architect.
+ *
+ * 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.
+ *
+ * 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 org.apache.log4j.Logger;
+
+/**
+ * This hierarchy listener will add and remove itself to children added to
and
+ * removed from the object it is listening to. This class will not
automatically
+ * listen to the hierarchy of the object it is initially placed on,
+ * {...@link ArchitectUtils#listenToHierarchy(SQLObjectListener, SQLObject)}
can be
+ * used to do the initial connecting of this listener to a hierarchy.
+ * <p>
+ * This class is meant to be extended by listeners that wish to listen to
the
+ * hierarchy of SQLObjects.
+ */
+public class SQLObjectHierarchyListener implements SQLObjectListener {
+ private static final Logger logger =
Logger.getLogger(SQLObjectHierarchyListener.class);
+
+ public void dbChildrenInserted(SQLObjectEvent e) {
+ try {
+ SQLObject[] newEventSources = e.getChildren();
+ for (int i = 0; i < newEventSources.length; i++) {
+ ArchitectUtils.listenToHierarchy(this, newEventSources[i]);
+ logger.debug("Adding listener to " + newEventSources[i]
+ " of type " + newEventSources[i].getClass());
+ }
+ } catch (ArchitectException ex) {
+ logger.error("Error listening to added object", ex);
//$NON-NLS-1$
+ }
+ }
+
+ public void dbChildrenRemoved(SQLObjectEvent e) {
+ try {
+ SQLObject[] oldEventSources = e.getChildren();
+ for (int i = 0; i < oldEventSources.length; i++) {
+ ArchitectUtils.unlistenToHierarchy(this,
oldEventSources[i]);
+ logger.debug("Removing listener from " +
oldEventSources[i]);
+ }
+ } catch (ArchitectException ex) {
+ logger.error("Error unlistening to removed object", ex);
//$NON-NLS-1$
+ }
+ }
+
+ public void dbObjectChanged(SQLObjectEvent e) {
+ // Object changes do not affect hierarchy.
+ }
+
+}
Modified: trunk/src/ca/sqlpower/architect/SQLTable.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/SQLTable.java (original)
+++ trunk/src/ca/sqlpower/architect/SQLTable.java Tue Jan 13 12:09:25 2009
@@ -913,6 +913,15 @@
public void populateImpl() throws ArchitectException {
populate(null);
+ if (logger.isDebugEnabled()) {
+ List<SQLObject> hierarchy = new ArrayList<SQLObject>();
+ SQLObject parent = this;
+ while (parent != null) {
+ hierarchy.add(0, parent);
+ parent = parent.getParent();
+ }
+ logger.debug("Populating folder on " + getParent().getName() + "
for type " + type + " with ancestor path " + hierarchy);
+ }
}
public void populate(DatabaseMetaData dbmd) throws
ArchitectException {
Modified:
trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/ArchitectSwingSessionImpl.java
Tue Jan 13 12:09:25 2009
@@ -51,6 +51,7 @@
import ca.sqlpower.architect.SQLDatabase;
import ca.sqlpower.architect.SQLObject;
import ca.sqlpower.architect.SQLObjectEvent;
+import ca.sqlpower.architect.SQLObjectHierarchyListener;
import ca.sqlpower.architect.SQLObjectListener;
import ca.sqlpower.architect.SQLObjectRoot;
import ca.sqlpower.architect.UserPrompter;
@@ -159,6 +160,21 @@
* This will store the properties of the print panel.
*/
private final PrintSettings printSettings;
+
+ /**
+ * This listener will listen to the SQLObject hierarchy and display
exception windows when
+ * an object's children are not accessible.
+ */
+ private final SQLObjectListener childrenInaccessibleListener = new
SQLObjectHierarchyListener() {
+ @Override
+ public void dbObjectChanged(SQLObjectEvent e) {
+ super.dbObjectChanged(e);
+ logger.debug("Object " + e.getSource() + " changed in the
SQLObject hierarchy.");
+ if (e.getPropertyName().equals("childrenInaccessibleReason")
&& e.getNewValue() != null) {
+ SPSUtils.showExceptionDialogNoReport(frame, "Children of "
+ e.getSource() + " are inaccessible due to the following exception.",
(Throwable) e.getNewValue());
+ }
+ }
+ };
/**
* Creates a new swing session, including a new visible architect
frame, with
@@ -173,6 +189,7 @@
this.isNew = true;
this.context = context;
this.delegateSession = new ArchitectSessionImpl(context, name);
+ ArchitectUtils.listenToHierarchy(childrenInaccessibleListener,
getRootObject());
this.olapRootObject = new OLAPRootObject(delegateSession);
((ArchitectSessionImpl)delegateSession).setProfileManager(new
ProfileManagerImpl(this));
((ArchitectSessionImpl)delegateSession).setUserPrompterFactory(this);