Author: thomasobrien95
Date: Tue Jan 6 08:54:58 2009
New Revision: 2903
Modified:
trunk/regress/ca/sqlpower/architect/swingui/TestPlayPen.java
trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
Log:
Fix for a bug Jonathan reported for 0.9.13 rc 1 via email.
When dragging and dropping from one session to another the
source columns on columns will be remembered. This will cause
exceptions when loading. The source columns are now removed
if they are d&d'd between sessions.
Modified: trunk/regress/ca/sqlpower/architect/swingui/TestPlayPen.java
==============================================================================
--- trunk/regress/ca/sqlpower/architect/swingui/TestPlayPen.java
(original)
+++ trunk/regress/ca/sqlpower/architect/swingui/TestPlayPen.java Tue Jan 6
08:54:58 2009
@@ -400,6 +400,35 @@
}
}
}
+
+ /**
+ * Test for bug in 0.9.13. If a column is dropped from one session
+ * to another the source will remain from the session it was dragged
+ * from. This can lead to problems with saving and loading.
+ */
+ public void testDnDAcrossSessionsRemovesSource() throws Exception {
+ SQLTable table = new SQLTable(ppdb, true);
+ SQLColumn column = new SQLColumn(table, "Test column", Types.VARCHAR,
10, 0);
+ table.addColumn(column);
+
+ final SQLTable sourceTable = new SQLTable(ppdb, true);
+ SQLColumn sourceColumn = new SQLColumn(sourceTable, "Source column",
Types.VARCHAR, 10, 0);
+ sourceTable.addColumn(sourceColumn);
+
+ column.setSourceColumn(sourceColumn);
+
+ TestingArchitectSwingSessionContext context = new
TestingArchitectSwingSessionContext();
+ final ArchitectSwingSession session = context.createSession(false);
+ final PlayPen newPP = new PlayPen(session);
+
+ newPP.importTableCopy(table, new Point(0, 0));
+
+ assertEquals(1, newPP.getTables().size());
+ assertEquals(1, newPP.getTables().get(0).getColumns().size());
+
assertFalse(session.getSourceDatabases().getDatabaseList().contains(sourceTable.getParentDatabase()));
+ assertNull(newPP.getTables().get(0).getColumn(0).getSourceColumn());
+
+ }
/**
* Returns a new value that is not equal to oldVal. The
Modified: trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/PlayPen.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/PlayPen.java Tue Jan 6
08:54:58 2009
@@ -1270,6 +1270,13 @@
*/
public synchronized TablePane importTableCopy(SQLTable source, Point
preferredLocation) throws ArchitectException {
SQLTable newTable = SQLTable.getDerivedInstance(source,
session.getTargetDatabase()); // adds newTable to db
+ for (int i = 0; i < newTable.getColumns().size(); i++) {
+ SQLColumn col = newTable.getColumn(i);
+ if (col.getSourceColumn() != null
+
&& !session.getSourceDatabases().getDatabaseList().contains(col.getSourceColumn().getParentTable().getParentDatabase()))
{
+ col.setSourceColumn(null);
+ }
+ }
String key = source.getName().toLowerCase();
boolean isAlreadyOnPlaypen = false;
int newSuffix = 0;