Revision: 3768
Author: [email protected]
Date: Wed Jul 21 07:59:07 2010
Log: Changed the set of columns that are passed to SQLColumn.assignTypes so
that the original columns aren't modified.
Changed one test so that it won't call main() unnecessarily, and when it
does, it won't show a GUI.
http://code.google.com/p/power-architect/source/detail?r=3768
Modified:
/trunk/regress/ca/sqlpower/architect/swingui/TestArchitectFrame.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestArchitectFrame.java
Mon Mar 29 12:48:38 2010
+++ /trunk/regress/ca/sqlpower/architect/swingui/TestArchitectFrame.java
Wed Jul 21 07:59:07 2010
@@ -27,9 +27,6 @@
public class TestArchitectFrame extends TestCase {
- private ArchitectFrame af;
- private ArchitectSwingSession session;
-
private final String testData =
"<?xml version='1.0'?>" +
"<architect-project version='0.1'>" +
@@ -126,20 +123,14 @@
@Override
protected void setUp() throws Exception {
super.setUp();
- TestingArchitectSwingSessionContext context = new
TestingArchitectSwingSessionContext();
- session = context.createSession();
- af = session.getArchitectFrame();
-
- File tmp = File.createTempFile("Architect", "Test");
-
- FileWriter fw = new FileWriter(tmp);
- fw.write(testData);
- fw.close();
-
- ArchitectFrame.main(new String[]{tmp.getAbsolutePath()});
+
}
- public void testAutoLayoutAction() {
+ public void testAutoLayoutAction() throws Exception {
+ TestingArchitectSwingSessionContext context = new
TestingArchitectSwingSessionContext();
+ ArchitectSwingSession session = context.createSession();
+ ArchitectFrame af = session.getArchitectFrame();
+
assertNotNull(af.getAutoLayoutAction());
assertSame(session.getPlayPen(),
af.getAutoLayoutAction().getPlayPen());
@@ -150,6 +141,14 @@
* Regression test for 1336. Loading a file from the command prompt
should be remembered.
*/
public void testFileLoadFromCMDPrompt() throws Exception {
+ File tmp = File.createTempFile("Architect", "Test");
+
+ FileWriter fw = new FileWriter(tmp);
+ fw.write(testData);
+ fw.close();
+
+ ArchitectFrame.main(new String[]{"-headless",
tmp.getAbsolutePath()});
+
Preferences prefs =
Preferences.userNodeForPackage(ArchitectSwingSessionImpl.class);
String recentFile = prefs.get("recentFile0", null);
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
Thu Jul 15 15:05:37 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/ArchitectFrame.java
Wed Jul 21 07:59:07 2010
@@ -1344,26 +1344,33 @@
// unless you like being attacked by screaming
monkeys, that is.
ArchitectSwingSessionContext context =
ASUtils.getContext();
+ boolean headless = false;
final List<ArchitectSwingSession> sessions = new
ArrayList<ArchitectSwingSession>();
if (args.length > 0) {
for (int i = 0; i < args.length; i++) {
- File openFile = new File(args[i]);
- InputStream in = new BufferedInputStream(new
FileInputStream(openFile));
- ArchitectSwingSession session =
context.createSession(in);
-
session.getRecentMenu().putRecentFileName(openFile.getAbsolutePath());
- session.getProjectLoader().setFile(openFile);
- sessions.add(session);
+ if (args[i].equalsIgnoreCase("-headless")) {
+ headless = true;
+ } else {
+ File openFile = new File(args[i]);
+ InputStream in = new
BufferedInputStream(new FileInputStream(openFile));
+ ArchitectSwingSession session =
context.createSession(in);
+
session.getRecentMenu().putRecentFileName(openFile.getAbsolutePath());
+
session.getProjectLoader().setFile(openFile);
+ sessions.add(session);
+ }
}
} else {
sessions.add(context.createSession());
}
- ArchitectFrame frame = new ArchitectFrame(context,
null);
- frame.init(sessions.get(0));
- for (int i = 1; i < sessions.size(); i++) {
- frame.addSession(sessions.get(i));
- frame.setCurrentSession(sessions.get(i));
- }
- frame.setCurrentSession(sessions.get(0));
+ if (!headless) {
+ ArchitectFrame frame = new ArchitectFrame(context,
null);
+ frame.init(sessions.get(0));
+ for (int i = 1; i < sessions.size(); i++) {
+ frame.addSession(sessions.get(i));
+ frame.setCurrentSession(sessions.get(i));
+ }
+ frame.setCurrentSession(sessions.get(0));
+ }
} catch (Exception e) {
e.printStackTrace();
//We wish we had a parent component to direct the
dialog to
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java Fri
Jul 16 07:18:35 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/TablePane.java Wed
Jul 21 07:59:07 2010
@@ -42,7 +42,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.Map.Entry;
import javax.swing.Icon;
import javax.swing.JCheckBoxMenuItem;
@@ -89,6 +88,7 @@
import ca.sqlpower.util.TransactionEvent;
import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
public class TablePane extends ContainerPane<SQLTable, SQLColumn> {
@@ -530,6 +530,8 @@
} else if (insertionPoint < getModel().getPkSize()) {
newColumnsInPk = true;
}
+
+ ListMultimap<String, SQLColumn> newColumns =
ArrayListMultimap.create();
for (int i = items.size()-1; i >= 0; i--) {
SQLObject someData = items.get(i);
@@ -537,7 +539,9 @@
logger.debug("insertObjects: got item of
type "+someData.getClass().getName()); //$NON-NLS-1$
if (someData instanceof SQLTable) {
SQLTable table = (SQLTable) someData;
- getModel().inherit(insertionPoint, table,
duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource());
+ newColumns.putAll(
+
table.getParentDatabase().getDataSource().getParentType().getName(),
+ getModel().inherit(insertionPoint, table,
duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource()));
for (SQLColumn column : table.getColumns()) {
SQLColumn targetCol =
getModel().getColumnByName(column.getName());
ASUtils.correctSourceColumn(column, duplicateProperties,
targetCol, getPlayPen().getSession().getDBTree());
@@ -573,12 +577,16 @@
} else {
// importing column from a source database
- getModel().inherit(insertionPoint, col, newColumnsInPk,
duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource());
+ newColumns.put(
+
col.getParent().getParentDatabase().getDataSource().getParentType().getName(),
+ getModel().inherit(insertionPoint, col,
newColumnsInPk, duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource()));
if (logger.isDebugEnabled())
logger.debug("Inherited "+col.getName()+" to table with precision " +
col.getPrecision()); //$NON-NLS-1$ //$NON-NLS-2$
}
} else {
- getModel().inherit(insertionPoint, col, newColumnsInPk,
duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource());
+ newColumns.put(
+
col.getParent().getParentDatabase().getDataSource().getParentType().getName(),
+ getModel().inherit(insertionPoint, col, newColumnsInPk,
duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource()));
if (logger.isDebugEnabled())
logger.debug("Inherited "+col.getName()+" to table with precision " +
col.getPrecision()); //$NON-NLS-1$ //$NON-NLS-2$
ASUtils.correctSourceColumn(col, duplicateProperties,
getModel().getColumnByName(col.getName()),
getPlayPen().getSession().getDBTree());
}
@@ -586,6 +594,11 @@
return false;
}
}
+
+ DataSourceCollection<SPDataSource> dsCollection =
getModel().getParentDatabase().getDataSource().getParentCollection();
+ for (String platform : newColumns.keySet()) {
+ SQLColumn.assignTypes(newColumns.get(platform), dsCollection,
platform, getPlayPen().getSession());
+ }
return true;
}
@@ -830,40 +843,25 @@
}
try {
- ArrayListMultimap<String, SQLColumn> droppedColumns =
ArrayListMultimap.create();
+ ArrayList<SQLColumn> droppedColumns = new
ArrayList<SQLColumn>();
for (SQLObject o : droppedItems) {
if (o instanceof SQLColumn) {
- String fromDataSource;
- SQLTable parent = ((SQLColumn) o).getParent();
- if (parent != null) {
- fromDataSource =
parent.getParentDatabase().getDataSource().getParentType().getName();
- } else {
- fromDataSource = null;
- }
- droppedColumns.put(fromDataSource, (SQLColumn) o);
+ droppedColumns.add((SQLColumn) o);
} else if (o instanceof SQLTable) {
- droppedColumns.putAll(((SQLTable)
o).getParentDatabase().getDataSource().getParentType().getName(),
((SQLTable) o).getChildren(SQLColumn.class));
+ droppedColumns.addAll(((SQLTable)
o).getChildren(SQLColumn.class));
}
}
for (int i = 0; i < importedKeys.size(); i++) {
// Not dealing with self-referencing tables right now.
if
(importedKeys.get(i).getPkTable().equals(importedKeys.get(i).getFkTable()))
continue;
- for (Entry<String, SQLColumn> entry :
droppedColumns.entries()) {
- if
(importedKeys.get(i).containsFkColumn(entry.getValue())) {
+ for (SQLColumn droppedColumn : droppedColumns) {
+ if
(importedKeys.get(i).containsFkColumn(droppedColumn)) {
importedKeys.get(i).setIdentifying(newColumnsInPk);
break;
}
}
}
-
- DataSourceCollection<SPDataSource> dsCollection =
getModel().getParentDatabase().getDataSource().getParentCollection();
-
- // Note that it is safe to assign types to previously
assigned
- // columns, they will be ignored.
- for (String platform : droppedColumns.keySet()) {
- SQLColumn.assignTypes(droppedColumns.get(platform),
dsCollection, platform, getPlayPen().getSession());
- }
ArchitectProject project = this.getParent().getParent();
success = false;