Revision: 3271
Author: [email protected]
Date: Mon Feb 8 10:12:47 2010
Log: NEW - bug 2713: Dragging a column into the primary key of a self
referencing table throws IOOBE
http://trillian.sqlpower.ca/bugzilla/show_bug.cgi?id=2713
Updated based on a library change. The SQLIndex that is the primary key of
a table is now always the same index and the positions of columns is
tracked by this index instead of values in the columns that need to be
normalized. This reduces the intermediate steps of modifying a table to
reduce complexity.
http://code.google.com/p/power-architect/source/detail?r=3271
Added:
/trunk/build_examples
/trunk/build_examples/ca
/trunk/build_examples/ca/sqlpower
/trunk/build_examples/ca/sqlpower/architect
/trunk/build_examples/ca/sqlpower/architect/example
/trunk/build_examples/ca/sqlpower/architect/example/ProjectCreator.class
Modified:
/trunk/example_code/ca/sqlpower/architect/example/ProjectCreator.java
/trunk/regress/ca/sqlpower/architect/ddl/GenericDDLGeneratorTest.java
/trunk/regress/ca/sqlpower/architect/diff/CompareSQLTest.java
/trunk/regress/ca/sqlpower/architect/diff/SQLIndexComparatorTest.java
/trunk/regress/ca/sqlpower/architect/diff/SQLRelationshipComparatorTest.java
/trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
/trunk/regress/ca/sqlpower/architect/swingui/TestPlayPen.java
/trunk/regress/ca/sqlpower/architect/swingui/TestRelationship.java
/trunk/regress/ca/sqlpower/architect/swingui/TestSwingUIProject.java
/trunk/regress/ca/sqlpower/architect/swingui/TestTableEditPane.java
/trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java
/trunk/regress/ca/sqlpower/architect/swingui/action/TestCreateRelationshipAction.java
/trunk/regress/ca/sqlpower/architect/swingui/dbtree/TestDBTreeModel.java
/trunk/regress/ca/sqlpower/architect/undo/TestArchitectUndoManager.java
/trunk/src/ca/sqlpower/architect/ProjectLoader.java
/trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
/trunk/src/ca/sqlpower/architect/ddl/SQLServerDDLGenerator.java
/trunk/src/ca/sqlpower/architect/diff/CompareSQL.java
/trunk/src/ca/sqlpower/architect/swingui/BasicTablePaneUI.java
/trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java
/trunk/src/ca/sqlpower/architect/swingui/DataMoverPanel.java
/trunk/src/ca/sqlpower/architect/swingui/IndexColumnTable.java
/trunk/src/ca/sqlpower/architect/swingui/IndexEditPanel.java
/trunk/src/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
/trunk/src/ca/sqlpower/architect/swingui/TablePane.java
/trunk/src/ca/sqlpower/architect/swingui/action/DeleteSelectedAction.java
=======================================
--- /dev/null
+++
/trunk/build_examples/ca/sqlpower/architect/example/ProjectCreator.class
Mon Feb 8 10:12:47 2010
Binary file, no diff available.
=======================================
--- /trunk/example_code/ca/sqlpower/architect/example/ProjectCreator.java
Fri Jan 15 15:02:04 2010
+++ /trunk/example_code/ca/sqlpower/architect/example/ProjectCreator.java
Mon Feb 8 10:12:47 2010
@@ -125,7 +125,7 @@
// make person_id a primary key
col.setNullable(DatabaseMetaData.columnNoNulls);
- col.setPrimaryKeySeq(0);
+ person.addToPK(col);
col = new SQLColumn(person, "name", Types.VARCHAR, 100, 0);
person.addColumn(col);
@@ -135,7 +135,7 @@
// make address_id a primary key
col.setNullable(DatabaseMetaData.columnNoNulls);
- col.setPrimaryKeySeq(0);
+ person.addToPK(col);
// make a foreign key that maps person.person_id to
address.person_id
SQLRelationship rel = new SQLRelationship();
=======================================
--- /trunk/regress/ca/sqlpower/architect/ddl/GenericDDLGeneratorTest.java
Thu Jul 23 14:49:49 2009
+++ /trunk/regress/ca/sqlpower/architect/ddl/GenericDDLGeneratorTest.java
Mon Feb 8 10:12:47 2010
@@ -83,17 +83,17 @@
tbl.setPhysicalName("test_table");
SQLColumn col1 = new SQLColumn(tbl, "N_TEST",
SQLType.NVARCHAR, "NVARCHAR", 1000, 0, 0, "",
- null, null, false);
+ null, false);
assertEquals("NVARCHAR(1000)", ddl.getColumnDataTypeName(col1));
assertEquals("NVARCHAR(1000)", ddl.columnType(col1));
SQLColumn col2 = new SQLColumn(tbl, "N_CHARTEST",
SQLType.NCHAR, "NCHAR", 1000, 0, 0, "",
- null, null, false);
+ null, false);
assertEquals("NCHAR(1000)", ddl.getColumnDataTypeName(col2));
assertEquals("NCHAR(1000)", ddl.columnType(col2));
SQLColumn col3 = new SQLColumn(tbl, "N_CLOB_TEST",
SQLType.NCLOB, "NCLOB", 1000, 0, 0, "",
- null, null, false);
+ null, false);
assertEquals("NCLOB", ddl.getColumnDataTypeName(col3));
assertEquals("NCLOB", ddl.columnType(col3));
=======================================
--- /trunk/regress/ca/sqlpower/architect/diff/CompareSQLTest.java Thu Jan
29 12:02:55 2009
+++ /trunk/regress/ca/sqlpower/architect/diff/CompareSQLTest.java Mon Feb
8 10:12:47 2010
@@ -376,7 +376,7 @@
SQLTable newTable2L = makeTable(6);
SQLRelationship relationL = new SQLRelationship();
//This is done because the architect requires imported key to be in the
primary key
- newTable1L.getColumn(0).setPrimaryKeySeq(1);
+ newTable1L.addToPK(newTable1L.getColumn(0));
relationL.addMapping(newTable1L.getColumn(0), newTable2L.getColumn(2));
// this is the difference
relationL.setName("relation1");
relationL.attachRelationship(newTable1L,newTable2L,false);
@@ -389,7 +389,7 @@
SQLTable newTable1R = makeTable(4);
SQLTable newTable2R = makeTable(6);
SQLRelationship relationR = new SQLRelationship();
- newTable1R.getColumn(0).setPrimaryKeySeq(1);
+ newTable1R.addToPK(newTable1R.getColumn(0));
relationR.addMapping(newTable1R.getColumn(0),
newTable2R.getColumn(1));
relationR.setName("relation1");
@@ -428,7 +428,7 @@
SQLTable t1 = makeTable(4);
list1.add(t1);
SQLColumn c = t1.getColumn(2);
- c.setPrimaryKeySeq(new Integer(0));
+ t1.addToPK(c);
List<SQLTable> list2 = new ArrayList<SQLTable>();
SQLTable t2 = makeTable(4);
@@ -471,7 +471,7 @@
SQLTable t1 = makeTable(4);
list1.add(t1);
SQLColumn c = t1.getColumn(3);
- c.setPrimaryKeySeq(new Integer(0));
+ t1.addToPK(c);
List<SQLTable> list2 = new ArrayList<SQLTable>();
SQLTable t2 = makeTable(4);
@@ -520,7 +520,7 @@
SQLTable t2 = makeTable(4);
list2.add(t2);
SQLColumn c = t2.getColumn(3);
- c.setPrimaryKeySeq(new Integer(0));
+ t2.addToPK(c);
CompareSQL sqlComparator = new CompareSQL(list1, list2);
List<DiffChunk<SQLObject>> diffs =
sqlComparator.generateTableDiffs();
@@ -561,7 +561,7 @@
SQLTable t2 = makeTable(4);
list2.add(t2);
SQLColumn c = t2.getColumn(3);
- c.setPrimaryKeySeq(new Integer(0));
+ t2.addToPK(c);
CompareSQL sqlComparator = new CompareSQL(list1, list2);
List<DiffChunk<SQLObject>> diffs =
sqlComparator.generateTableDiffs();
@@ -598,13 +598,13 @@
SQLTable t1 = makeTable(4);
list1.add(t1);
SQLColumn c1 = t1.getColumn(3);
- c1.setPrimaryKeySeq(new Integer(0));
+ t1.addToPK(c1);
List<SQLTable> list2 = new ArrayList<SQLTable>();
SQLTable t2 = makeTable(4);
list2.add(t2);
SQLColumn c2 = t2.getColumn(2);
- c2.setPrimaryKeySeq(new Integer(0));
+ t2.addToPK(c2);
CompareSQL sqlComparator = new CompareSQL(list1, list2);
List<DiffChunk<SQLObject>> diffs =
sqlComparator.generateTableDiffs();
=======================================
--- /trunk/regress/ca/sqlpower/architect/diff/SQLIndexComparatorTest.java
Tue Dec 22 07:34:32 2009
+++ /trunk/regress/ca/sqlpower/architect/diff/SQLIndexComparatorTest.java
Mon Feb 8 10:12:47 2010
@@ -24,10 +24,12 @@
import java.util.TreeSet;
import junit.framework.TestCase;
+import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLIndex;
import ca.sqlpower.sqlobject.SQLObject;
+import ca.sqlpower.sqlobject.SQLTable;
import ca.sqlpower.sqlobject.SQLIndex.AscendDescend;
import ca.sqlpower.sqlobject.SQLIndex.Column;
@@ -117,6 +119,7 @@
public void testCompareByPrimaryKeyIndex() throws SQLObjectException {
SQLIndex ind1 = new SQLIndex();
SQLIndex ind2 = new SQLIndex();
+ SQLDatabase db = new SQLDatabase();
SQLColumn col = new SQLColumn();
col.setName("cool_col");
@@ -126,14 +129,22 @@
assertEquals("Should compare as same.", 0,
indComparator.compare(ind1, ind2));
- ind1.setPrimaryKeyIndex(true);
- assertTrue("Should compare as source > target.",
indComparator.compare(ind1, ind2) > 0);
-
- ind2.setPrimaryKeyIndex(true);
- assertEquals("PrimaryKeyIndex should be same.", 0,
indComparator.compare(ind1, ind2));
-
- ind1.setPrimaryKeyIndex(false);
- assertTrue("Should compare as source < target.",
indComparator.compare(ind1, ind2) < 0);
+ SQLIndex ind3 = new SQLIndex();
+ SQLTable table1 = new SQLTable(db, true, ind3);
+ table1.addColumn(col);
+ ind3.addIndexColumn(col, AscendDescend.UNSPECIFIED);
+ assertTrue("Should compare as source > target.",
indComparator.compare(ind3, ind1) > 0);
+
+ SQLColumn col2 = new SQLColumn();
+ col2.setName("cool_col");
+
+ SQLIndex ind4 = new SQLIndex();
+ SQLTable table2 = new SQLTable(db, true, ind4);
+ table2.addColumn(col2);
+ ind4.addIndexColumn(col2, AscendDescend.UNSPECIFIED);
+ assertEquals("PrimaryKeyIndex should be same.", 0,
indComparator.compare(ind3, ind4));
+
+ assertTrue("Should compare as source < target.",
indComparator.compare(ind1, ind4) < 0);
}
/**
=======================================
---
/trunk/regress/ca/sqlpower/architect/diff/SQLRelationshipComparatorTest.java
Thu Jan 29 12:02:55 2009
+++
/trunk/regress/ca/sqlpower/architect/diff/SQLRelationshipComparatorTest.java
Mon Feb 8 10:12:47 2010
@@ -43,7 +43,7 @@
table1L = makeTable(1);
table2L = makeTable(3);
left= new SQLRelationship();
- table1L.getColumn(0).setPrimaryKeySeq(1);
+ table1L.addToPK(table1L.getColumn(0));
left.addMapping(table1L.getColumn(0),table2L.getColumn(1));
}
@@ -56,7 +56,7 @@
SQLTable table1R = makeTable(1);
SQLTable table2R = makeTable(3);
SQLRelationship right = new SQLRelationship();
- table1R.getColumn(0).setPrimaryKeySeq(1);
+ table1R.addToPK(table1R.getColumn(0));
right.addMapping(table1R.getColumn(0),table2R.getColumn(1));
assertEquals("Should be same relationship",
0,relComparator.compare(left,right));
}
@@ -66,7 +66,7 @@
SQLTable table1R = makeTable(1);
SQLTable table2R = makeTable(3);
SQLRelationship right = new SQLRelationship();
- table1R.getColumn(0).setPrimaryKeySeq(1);
+ table1R.addToPK(table1R.getColumn(0));
right.addMapping(table1R.getColumn(0),table2R.getColumn(0));//Different
mapping here
assertNotSame("Shouldn't be same relationship",
0,relComparator.compare(left,right));
}
@@ -75,7 +75,7 @@
SQLTable table1R = makeTable(1);
SQLTable table2R = makeTable(3);
SQLRelationship right = new SQLRelationship();
- table1R.getColumn(0).setPrimaryKeySeq(1);
+ table1R.addToPK(table1R.getColumn(0));
right.addMapping(table1R.getColumn(0),table2R.getColumn(1));
right.addMapping(table1R.getColumn(0),table2R.getColumn(2));
assertNotSame("Shouldn't be same relationship",
0,relComparator.compare(left,right));
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
Mon Dec 21 08:27:43 2009
+++ /trunk/regress/ca/sqlpower/architect/swingui/TestColumnEditPanel.java
Mon Feb 8 10:12:47 2010
@@ -53,11 +53,11 @@
col2.setPhysicalName("Physical Name 2");
col2.setAutoIncrement(false);
col2.setNullable(DatabaseMetaData.columnNoNulls);
- col2.setPrimaryKeySeq(0);
table.addColumn(col1);
table.addColumn(col2);
table.addColumn(col3);
table2.addColumn(col4);
+ table.addToPK(col2);
TestingArchitectSwingSessionContext context = new
TestingArchitectSwingSessionContext();
session = context.createSession();
panel = new ColumnEditPanel(col2, session);
@@ -77,8 +77,8 @@
public void testSetComponentsToColumnValues() throws SQLObjectException
{
assertEquals(2, table.getColumnIndex(col3));
- assertEquals("The column we plan to edit should not be in PK",
- null, col3.getPrimaryKeySeq());
+ assertFalse("The column we plan to edit should not be in PK",
+ col3.isPrimaryKey());
panel = new ColumnEditPanel(col3, session);
@@ -128,7 +128,10 @@
assertTrue(col2.isDefinitelyNullable());
}
- public void testDiscardChanges() {
+ public void testDiscardChanges() throws Exception {
+ table.moveAfterPK(col2);
+ assertFalse(col2.isPrimaryKey());
+
panel.getColPhysicalName().setText("CHANGED");
panel.getColLogicalName().setText("Easier Use Column Name");
panel.getColPrec().setValue(new Integer(1234));
@@ -155,8 +158,8 @@
SQLColumn c2 = new SQLColumn(table,"PKColumn 2",1,2,3);
table.addColumn(c1);
table.addColumn(c2);
- c1.setPrimaryKeySeq(0);
- c2.setPrimaryKeySeq(1);
+ table.addToPK(c1);
+ table.addToPK(c2);
assertEquals(5, table.getColumns().size());
assertTrue(c1.isPrimaryKey());
assertTrue(c2.isPrimaryKey());
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestPlayPen.java Mon Dec
21 08:27:43 2009
+++ /trunk/regress/ca/sqlpower/architect/swingui/TestPlayPen.java Mon Feb
8 10:12:47 2010
@@ -122,7 +122,7 @@
SQLTable sourceParentTable = new SQLTable(sourceDB, true);
sourceParentTable.setName("parent");
sourceParentTable.addColumn(new SQLColumn(sourceParentTable, "key",
Types.BOOLEAN, 1, 0));
- sourceParentTable.getColumn(0).setPrimaryKeySeq(0);
+ sourceParentTable.addToPK(sourceParentTable.getColumn(0));
sourceDB.addChild(sourceParentTable);
SQLTable sourceChildTable = new SQLTable(sourceDB, true);
@@ -172,7 +172,7 @@
table.setName("self_ref");
SQLColumn pkCol = new SQLColumn(table, "key", Types.INTEGER, 10,
0);
table.addColumn(pkCol);
- table.getColumn(0).setPrimaryKeySeq(0);
+ table.addToPK(table.getColumn(0));
SQLColumn fkCol = new SQLColumn(table, "self_ref_column",
Types.INTEGER, 10, 0);
table.addColumn(fkCol);
@@ -214,7 +214,7 @@
table.setName("self_ref");
SQLColumn pkCol = new SQLColumn(table, "key", Types.INTEGER, 10,
0);
table.addColumn(pkCol);
- table.getColumn(0).setPrimaryKeySeq(0);
+ table.addToPK(table.getColumn(0));
SQLColumn fkCol = new SQLColumn(table, "self_ref_column",
Types.INTEGER, 10, 0);
table.addColumn(fkCol);
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestRelationship.java Tue
Apr 7 15:02:18 2009
+++ /trunk/regress/ca/sqlpower/architect/swingui/TestRelationship.java Mon
Feb 8 10:12:47 2010
@@ -39,7 +39,7 @@
SQLTable t1 = new SQLTable(session.getTargetDatabase(), true);
t1.addColumn(new SQLColumn(t1, "pkcol_1", Types.INTEGER, 10,0));
t1.addColumn(new SQLColumn(t1, "fkcol_1", Types.INTEGER, 10,0));
- t1.getColumnByName("pkcol_1").setPrimaryKeySeq(0);
+ t1.addToPK(t1.getColumnByName("pkcol_1"));
session.getTargetDatabase().addChild(t1);
pp.addTablePane(tp1 = new TablePane(t1, pp.getContentPane()), new
Point(0,0));
@@ -92,7 +92,7 @@
pkTable.setName("pkTable");
pkTable.addColumn(new SQLColumn(pkTable, "PKTableCol1",
Types.INTEGER, 1, 0));
pkTable.addColumn(new SQLColumn(pkTable, "PKTableCol2",
Types.INTEGER, 1, 0));
- pkTable.getColumn(0).setPrimaryKeySeq(0);
+ pkTable.addToPK(pkTable.getColumn(0));
db.addChild(pkTable);
fkTable.setName("child");
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestSwingUIProject.java
Tue Jan 19 13:07:30 2010
+++ /trunk/regress/ca/sqlpower/architect/swingui/TestSwingUIProject.java
Mon Feb 8 10:12:47 2010
@@ -110,6 +110,11 @@
public List<? extends SQLObject> getChildren() {
return stubs;
}
+
+ @Override
+ public List<? extends SQLObject> getChildrenWithoutPopulating() {
+ return stubs;
+ }
}
@@ -267,17 +272,20 @@
SQLDatabase target = session.getTargetDatabase();
- SQLTable t1 = (SQLTable) target.getChild(0);
+ SQLTable t1 = (SQLTable) target.getChildByName("mm_project");
assertEquals(1, t1.getPkSize());
- assertEquals(new Integer(0), t1.getColumn(0).getPrimaryKeySeq());
- assertNull(t1.getColumn(1).getPrimaryKeySeq());
+ assertEquals(t1.getPrimaryKeyIndex().getChild(0).getColumn(),
t1.getColumn(0));
+ assertTrue(t1.getColumn(0).isPrimaryKey());
+ assertFalse(t1.getColumn(1).isPrimaryKey());
}
private void subroutineForTestSaveLoadPK(SQLTable t) throws
SQLObjectException {
assertEquals(2, t.getPkSize());
- assertEquals(new Integer(0), t.getColumn(0).getPrimaryKeySeq());
- assertEquals(new Integer(1), t.getColumn(1).getPrimaryKeySeq());
- assertEquals(null, t.getColumn(2).getPrimaryKeySeq());
+ assertTrue(t.getColumn(0).isPrimaryKey());
+ assertEquals(t.getPrimaryKeyIndex().getChild(0).getColumn(),
t.getColumn(0));
+ assertTrue(t.getColumn(1).isPrimaryKey());
+ assertEquals(t.getPrimaryKeyIndex().getChild(1).getColumn(),
t.getColumn(1));
+ assertFalse(t.getColumn(2).isPrimaryKey());
assertFalse(t.getColumn(0).isDefinitelyNullable());
assertFalse(t.getColumn(1).isDefinitelyNullable());
assertTrue(t.getColumn(0).isPrimaryKey());
@@ -295,8 +303,8 @@
t.addColumn(new SQLColumn(t, "pk1", Types.CHAR, 10, 0));
t.addColumn(new SQLColumn(t, "pk2", Types.CHAR, 10, 0));
t.addColumn(new SQLColumn(t, "nonpk", Types.CHAR, 10, 0));
- t.getColumn(0).setPrimaryKeySeq(0);
- t.getColumn(1).setPrimaryKeySeq(1);
+ t.addToPK(t.getColumn(0));
+ t.addToPK(t.getColumn(1));
target.addChild(t);
subroutineForTestSaveLoadPK(t);
@@ -717,7 +725,7 @@
target.addChild(new Column(col, AscendDescend.UNSPECIFIED));
ppdb.addChild(table);
table.addChild(target);
- col.setPrimaryKeySeq(0);
+ table.addToPK(col);
Set<String> propertiesToIgnore = getPropertiesToIgnore();
propertiesToIgnore.add("undoEventListeners");
@@ -798,7 +806,7 @@
// grab the second database in the dbtree's model (the first is
the play pen)
ppdb = (SQLDatabase) session2.getTargetDatabase();
- index = (SQLIndex) ((SQLTable)
ppdb.getTableByName(tableName)).getIndices().get(0);
+ index = (SQLIndex) ((SQLTable)
ppdb.getTableByName(tableName)).getChildByName(index.getName());
Map<String, Object> newDescription =
ca.sqlpower.testutil.TestUtils.getAllInterestingProperties(index,
propertiesToIgnore);
@@ -811,13 +819,12 @@
testLoad();
SQLDatabase ppdb = session.getTargetDatabase();
- SQLTable table = new SQLTable(ppdb, true);
+ SQLIndex index = new SQLIndex("tasty index", false, null, null,
null);
+ SQLTable table = new SQLTable(ppdb, true, index);
SQLColumn col = new SQLColumn(table,"col",1,0,0);
table.setName(tableName);
table.addColumn(col);
- SQLIndex index = new SQLIndex("tasty index", false, null, null,
null);
SQLIndex.Column indexCol = new Column(col,
AscendDescend.DESCENDING);
- index.setPrimaryKeyIndex(true);
ppdb.addChild(table);
table.addChild(index);
@@ -828,7 +835,7 @@
index.addChild(indexCol);
assertEquals(1, table.getIndices().size());
assertSame(index, table.getPrimaryKeyIndex());
- col.setPrimaryKeySeq(new Integer(0));
+ table.addToPK(col);
assertEquals(1, table.getIndices().size());
assertSame(index, table.getPrimaryKeyIndex());
@@ -875,7 +882,7 @@
index.addIndexColumn(col, AscendDescend.DESCENDING);
ppdb.addChild(table);
table.addChild(index);
- col.setPrimaryKeySeq(new Integer(0));
+ table.addToPK(col);
Set<String> propertiesToIgnore = getPropertiesToIgnore();
propertiesToIgnore.add("undoEventListeners");
@@ -925,7 +932,7 @@
SQLIndex origIndex1 = new SQLIndex("tasty index", false,
null, "HASH", null);
origIndex1.addIndexColumn(col, AscendDescend.DESCENDING);
table.addChild(origIndex1);
- col.setPrimaryKeySeq(new Integer(0));
+ table.addToPK(col);
// second index references same column as first index, so
// origIndex1.getChild(0).equals(origIndex2.getChild(0)) even
though
@@ -1238,7 +1245,9 @@
assertTrue(
"Index " + idx + " wasn't listening to columns
folder!",
idx.getChildCount() == 0);
- assertFalse(t.getIndices().contains(idx));
+ if (!idx.isPrimaryKeyIndex()) {
+ assertFalse(t.getIndices().contains(idx));
+ }
}
}
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestTableEditPane.java Mon
Dec 21 08:27:43 2009
+++ /trunk/regress/ca/sqlpower/architect/swingui/TestTableEditPane.java Mon
Feb 8 10:12:47 2010
@@ -39,7 +39,7 @@
SQLColumn pk1 = new SQLColumn(t, "PKColumn1", Types.INTEGER,
10,0);
t.addColumn(pk1,0);
- pk1.setPrimaryKeySeq(1);
+ t.addToPK(pk1);
tep = new TableEditPanel(session, t);
}
=======================================
--- /trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java Mon Dec
21 08:27:43 2009
+++ /trunk/regress/ca/sqlpower/architect/swingui/TestTablePane.java Mon
Feb 8 10:12:47 2010
@@ -60,9 +60,9 @@
pp = session.getPlayPen();
tp = new TablePane(t, pp.getContentPane());
- pk1.setPrimaryKeySeq(1);
- pk2.setPrimaryKeySeq(2);
- pk3.setPrimaryKeySeq(3);
+ t.addToPK(pk1);
+ t.addToPK(pk2);
+ t.addToPK(pk3);
assertEquals(3, t.getPkSize());
@@ -101,14 +101,14 @@
SQLColumn newcol = new SQLColumn(t, "newcol", Types.INTEGER, 10, 0);
t.addColumn(newcol, 0);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+ assertTrue("Column should start in primary key",
newcol.isPrimaryKey());
List<SQLObject> movecolList = new ArrayList<SQLObject>();
movecolList.add(newcol);
tp.insertObjects(movecolList, TablePane.COLUMN_INDEX_START_OF_NON_PK,
true);
assertEquals(3, t.getColumnIndex(newcol));
- assertNull("Column should have moved out of primary key",
newcol.getPrimaryKeySeq());
+ assertFalse("Column should have moved out of primary key",
newcol.isPrimaryKey());
}
/** This tests for a regression we found in March 2006 (bug 1057) */
@@ -116,14 +116,14 @@
SQLColumn newcol = new SQLColumn(t, "newcol", Types.INTEGER, 10, 0);
t.addColumn(newcol, 0);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+ assertTrue("Column should start in primary key",
newcol.isPrimaryKey());
List<SQLObject> movecolList = new ArrayList<SQLObject>();
movecolList.add(newcol);
tp.insertObjects(movecolList, 4, true);
assertEquals(3, t.getColumnIndex(newcol));
- assertNull("Column should have moved out of primary key",
newcol.getPrimaryKeySeq());
+ assertFalse("Column should have moved out of primary key",
newcol.isPrimaryKey());
}
public void testInsertNewColumnAboveFirstNonPKColumn() throws Exception
{
@@ -131,15 +131,15 @@
t2.setName("Another Test Table");
SQLColumn newcol = new SQLColumn(t2, "newcol", Types.INTEGER, 10,
0);
t2.addColumn(newcol, 0);
- newcol.setPrimaryKeySeq(1);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+ t2.addToPK(newcol);
+ assertTrue("Column should start in primary key",
newcol.isPrimaryKey());
List<SQLObject> movecolList = new ArrayList<SQLObject>();
movecolList.add(newcol);
tp.insertObjects(movecolList, 3, true);
assertEquals(3, t.getColumnIndex(newcol));
- assertNull("Column should not be in primary key",
newcol.getPrimaryKeySeq());
+ assertFalse("Column should not be in primary key",
newcol.isPrimaryKey());
}
/** This tests for a real regression (the column was ending up at index 2
instead of 3) */
@@ -148,15 +148,15 @@
t2.setName("Another Test Table");
SQLColumn newcol = new SQLColumn(t2, "newcol", Types.INTEGER, 10,
0);
t2.addColumn(newcol, 0);
- newcol.setPrimaryKeySeq(1);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+ t2.addToPK(newcol);
+ assertTrue("Column should start in primary key",
newcol.isPrimaryKey());
List<SQLObject> movecolList = new ArrayList<SQLObject>();
movecolList.add(newcol);
tp.insertObjects(movecolList, TablePane.COLUMN_INDEX_END_OF_PK,
true);
assertEquals(3, t.getColumnIndex(newcol));
- assertNotNull("Column should be in primary key",
newcol.getPrimaryKeySeq());
+ assertTrue("Column should be in primary key",
newcol.isPrimaryKey());
}
/** This tests for a regression we found in March 2006 (bug 1057) */
@@ -164,7 +164,7 @@
SQLColumn newcol = new SQLColumn(t, "newcol", Types.INTEGER,
10, 0);
t.addColumn(newcol, 0);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+ assertTrue("Column should start in primary key",
newcol.isPrimaryKey());
List<SQLColumn> oldColumns = new
ArrayList<SQLColumn>(t.getColumns());
@@ -178,11 +178,11 @@
assertEquals(1, newColumns.size());
final SQLColumn copyCol = newColumns.get(0);
assertEquals(4, t.getColumnIndex(copyCol));
- assertNull("Column should have moved out of primary key",
copyCol.getPrimaryKeySeq());
+ assertFalse("Column should have moved out of primary key",
copyCol.isPrimaryKey());
//assert column copied still exists
assertEquals(0, t.getColumnIndex(newcol));
- assertNotNull("Column copied should stay in primary key",
newcol.getPrimaryKeySeq());
+ assertTrue("Column copied should stay in primary key",
newcol.isPrimaryKey());
}
/** This tests for a regression we found in March 2006 (bug 1057) */
@@ -190,7 +190,7 @@
SQLColumn newcol = new SQLColumn(t, "newcol", Types.INTEGER,
10, 0);
t.addColumn(newcol, 0);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+ assertTrue("Column should start in primary key",
newcol.isPrimaryKey());
List<SQLColumn> oldColumns = new
ArrayList<SQLColumn>(t.getColumns());
@@ -204,11 +204,11 @@
assertEquals(1, newColumns.size());
SQLColumn copyColumn = newColumns.get(0);
assertEquals(4, t.getColumnIndex(copyColumn));
- assertNull("Column copied should be out of primary key",
copyColumn.getPrimaryKeySeq());
+ assertFalse("Column copied should be out of primary key",
copyColumn.isPrimaryKey());
//column copied should not be changed
assertEquals(0, t.getColumnIndex(newcol));
- assertNotNull("Column should stay in primary key",
newcol.getPrimaryKeySeq());
+ assertTrue("Column should stay in primary key",
newcol.isPrimaryKey());
}
public void testInsertNewColumnAboveFirstNonPKColumnByCopy() throws
SQLObjectException {
@@ -216,8 +216,8 @@
t2.setName("Another Test Table");
SQLColumn newcol = new SQLColumn(t2, "newcol", Types.INTEGER,
10, 0);
t2.addColumn(newcol, 0);
- newcol.setPrimaryKeySeq(1);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+ t2.addToPK(newcol);
+ assertTrue("Column should start in primary key",
newcol.isPrimaryKey());
List<SQLColumn> oldColumns = new
ArrayList<SQLColumn>(t.getColumns());
@@ -231,10 +231,10 @@
assertEquals(1, newColumns.size());
SQLColumn copyCol = newColumns.get(0);
assertEquals(3, t.getColumnIndex(copyCol));
- assertNull("Copy column should not bein in the primary key",
copyCol.getPrimaryKeySeq());
+ assertFalse("Copy column should not bein in the primary key",
copyCol.isPrimaryKey());
assertEquals(0, t2.getColumnIndex(newcol));
- assertNotNull("Column should still be in primary key",
newcol.getPrimaryKeySeq());
+ assertTrue("Column should still be in primary key",
newcol.isPrimaryKey());
}
/** This tests for a real regression (the column was ending up at index 2
instead of 3) */
@@ -243,8 +243,8 @@
t2.setName("Another Test Table");
SQLColumn newcol = new SQLColumn(t2, "newcol", Types.INTEGER,
10, 0);
t2.addColumn(newcol, 0);
- newcol.setPrimaryKeySeq(1);
- assertNotNull("Column should start in primary key",
newcol.getPrimaryKeySeq());
+ t2.addToPK(newcol);
+ assertTrue("Column should start in primary key",
newcol.isPrimaryKey());
List<SQLColumn> oldColumns = new
ArrayList<SQLColumn>(t.getColumns());
@@ -259,11 +259,11 @@
SQLColumn copyCol = newColumns.get(0);
assertEquals(3, t.getColumnIndex(copyCol));
- assertNotNull("Copy column should be in primary key",
copyCol.getPrimaryKeySeq());
+ assertTrue("Copy column should be in primary key",
copyCol.isPrimaryKey());
//Assert column copied is unmodified.
assertEquals(0, t2.getColumnIndex(newcol));
- assertNotNull("Column should still be in primary key",
newcol.getPrimaryKeySeq());
+ assertTrue("Column should still be in primary key",
newcol.isPrimaryKey());
}
public void testImportTableFromPlaypenByCopy() throws
SQLObjectException {
@@ -392,7 +392,7 @@
tp.selectItem(0);
// this was throwing an exception
- t.getColumn(0).setPrimaryKeySeq(0);
+ t.addToPK(t.getColumn(0));
}
/**
=======================================
---
/trunk/regress/ca/sqlpower/architect/swingui/action/TestCreateRelationshipAction.java
Fri May 22 13:36:14 2009
+++
/trunk/regress/ca/sqlpower/architect/swingui/action/TestCreateRelationshipAction.java
Mon Feb 8 10:12:47 2010
@@ -52,9 +52,9 @@
pp.addTablePane(tp2,new Point(1,1));
pkTable.addColumn(new SQLColumn());
pkTable.addColumn(new SQLColumn());
- pkTable.getColumn(0).setPrimaryKeySeq(1);
+ pkTable.addToPK(pkTable.getColumn(0));
pkTable.getColumn(0).setName("pk1");
- pkTable.getColumn(1).setPrimaryKeySeq(1);
+ pkTable.addToPK(pkTable.getColumn(1));
pkTable.getColumn(1).setName("pk2");
@@ -69,8 +69,8 @@
assertEquals("Wrong number of relationships
created",1,pp.getRelationships().size());
assertEquals("Did the relationship create the columns in the
fkTable",2,fkTable.getColumns().size());
List<SQLColumn> columns = fkTable.getColumns();
- assertNotNull("Is the first column a key
column?",columns.get(0).getPrimaryKeySeq());
- assertNotNull("Is the second column a key
column?",columns.get(1).getPrimaryKeySeq());
+ assertTrue("Is the first column a key
column?",columns.get(0).isPrimaryKey());
+ assertTrue("Is the second column a key
column?",columns.get(1).isPrimaryKey());
assertEquals("Is the first column
pk1?","pk1",columns.get(0).getName());
assertEquals("Is the second column
pk2?","pk2",columns.get(1).getName());
@@ -84,8 +84,8 @@
assertEquals("Wrong number of relationships
created",1,pp.getRelationships().size());
assertEquals("Did the relationship create the columns in the
fkTable",2,fkTable.getColumns().size());
List<SQLColumn> columns = fkTable.getColumns();
- assertNull("Is the first column a key
column?",columns.get(0).getPrimaryKeySeq());
- assertNull("Is the second column a key
column?",columns.get(1).getPrimaryKeySeq());
+ assertFalse("Is the first column a key
column?",columns.get(0).isPrimaryKey());
+ assertFalse("Is the second column a key
column?",columns.get(1).isPrimaryKey());
assertEquals("Is the first column
pk1?","pk1",columns.get(0).getName());
assertEquals("Is the second column
pk2?","pk2",columns.get(1).getName());
@@ -100,8 +100,8 @@
assertEquals("Did the relationship create the columns in the
fkTable",2,fkTable.getColumns().size());
List<SQLColumn> columns = fkTable.getColumns();
assertEquals("Do we only have two columns in the fk
table",2,columns.size());
- assertNotNull("Is the first column a key
column?",columns.get(0).getPrimaryKeySeq());
- assertNotNull("Is the second column a key
column?",columns.get(1).getPrimaryKeySeq());
+ assertTrue("Is the first column a key
column?",columns.get(0).isPrimaryKey());
+ assertTrue("Is the second column a key
column?",columns.get(1).isPrimaryKey());
assertEquals("Is the first column
pk1?","pk1",columns.get(0).getName());
assertEquals("Is the second column
pk2?","pk2",columns.get(1).getName());
=======================================
---
/trunk/regress/ca/sqlpower/architect/swingui/dbtree/TestDBTreeModel.java
Mon Dec 21 08:27:43 2009
+++
/trunk/regress/ca/sqlpower/architect/swingui/dbtree/TestDBTreeModel.java
Mon Feb 8 10:12:47 2010
@@ -119,7 +119,7 @@
treeRoot.addChild(db);
db.addChild(t);
t.addColumn(c);
- c.setPrimaryKeySeq(0);
+ t.addToPK(c);
SQLRelationship r = new SQLRelationship();
r.setName("my relationship is cooler than your silly columnmnm");
=======================================
--- /trunk/regress/ca/sqlpower/architect/undo/TestArchitectUndoManager.java
Mon Dec 21 08:27:43 2009
+++ /trunk/regress/ca/sqlpower/architect/undo/TestArchitectUndoManager.java
Mon Feb 8 10:12:47 2010
@@ -152,10 +152,10 @@
pp.getPlayPenContentPane().addPropertyChangeListener("connectionPoints",
undoManager.getEventAdapter());
pkTable.addColumn(new SQLColumn());
pkTable.addColumn(new SQLColumn());
- pkTable.getColumn(0).setPrimaryKeySeq(1);
+ pkTable.addToPK(pkTable.getColumn(0));
pkTable.getColumn(0).setName("pk1");
pkTable.getColumn(0).setType(Types.INTEGER);
- pkTable.getColumn(1).setPrimaryKeySeq(1);
+ pkTable.addToPK(pkTable.getColumn(1));
pkTable.getColumn(1).setName("pk2");
pkTable.getColumn(1).setType(Types.INTEGER);
db.addChild(pkTable);
@@ -431,8 +431,8 @@
CreateRelationshipAction.doCreateRelationship(pkTable, fkTable,
pp, false);
assertEquals("Wrong number of relationships created", 1,
pp.getRelationships().size());
assertEquals("Did the relationship create the columns in the
fkTable", 2, fkTable.getColumns().size());
- assertNull("First column should not be in PK",
fkTable.getColumns().get(0).getPrimaryKeySeq());
- assertNull("Second column should not be in PK",
fkTable.getColumns().get(1).getPrimaryKeySeq());
+ assertFalse("First column should not be in PK",
fkTable.getColumns().get(0).isPrimaryKey());
+ assertFalse("Second column should not be in PK",
fkTable.getColumns().get(1).isPrimaryKey());
assertEquals("first column should be called 'pk1'", "pk1",
fkTable.getColumns().get(0).getName());
assertEquals("second column should be called 'pk2'", "pk2",
fkTable.getColumns().get(1).getName());
@@ -466,11 +466,11 @@
assertEquals("Wrong number of columns in the fkTable", 2,
columns.size());
assertEquals("Is the first column pk1?", "pk1",
columns.get(0).getName());
- assertNull("Is the first column a key column?",
columns.get(0).getPrimaryKeySeq());
+ assertFalse("Is the first column a key column?",
columns.get(0).isPrimaryKey());
assertEquals("redo left incorrect reference count on pk1", 1,
columns.get(0).getReferenceCount());
assertEquals("Is the second column pk2?", "pk2",
columns.get(1).getName());
- assertNull("Is the second column a key column?",
columns.get(1).getPrimaryKeySeq());
+ assertFalse("Is the second column a key column?",
columns.get(1).isPrimaryKey());
assertEquals("redo left incorrect reference count on pk2", 1,
columns.get(1).getReferenceCount());
}
=======================================
--- /trunk/src/ca/sqlpower/architect/ProjectLoader.java Fri Jan 29 08:23:36
2010
+++ /trunk/src/ca/sqlpower/architect/ProjectLoader.java Mon Feb 8 10:12:47
2010
@@ -57,6 +57,7 @@
import ca.sqlpower.sqlobject.SQLIndex;
import ca.sqlpower.sqlobject.SQLObject;
import ca.sqlpower.sqlobject.SQLObjectException;
+import ca.sqlpower.sqlobject.SQLObjectRuntimeException;
import ca.sqlpower.sqlobject.SQLRelationship;
import ca.sqlpower.sqlobject.SQLSchema;
import ca.sqlpower.sqlobject.SQLTable;
@@ -265,13 +266,12 @@
logger.debug("number of children found in indices
folder: " + table.getIndices().size());
for (SQLIndex index : table.getIndices()) {
if
(sqlObjectLoadIdMap.get(table.getName()+"."+index.getName()) != null) {
- index.setPrimaryKeyIndex(true);
+
table.getPrimaryKeyIndex().updateToMatch(index);
break;
}
}
}
logger.debug("Table ["+table.getName()+"]2 index folder
contents: "+table.getIndices());
- table.normalizePrimaryKey();
logger.debug("Table ["+table.getName()+"]3 index folder
contents: "+table.getIndices());
if (logger.isDebugEnabled()) {
@@ -718,6 +718,16 @@
public Object createObject(Attributes attributes) {
SQLIndex index = new SQLIndex();
logger.debug("Loading index: "+attributes.getValue("name"));
+
+ String pkIndex = attributes.getValue("primaryKeyIndex");
+ if (Boolean.valueOf(pkIndex)) {
+ try {
+ index = currentTable.getPrimaryKeyIndex();
+ } catch (SQLObjectException e) {
+ throw new SQLObjectRuntimeException(e);
+ }
+ }
+
String id = attributes.getValue("id");
if (id != null) {
sqlObjectLoadIdMap.put(id, index);
=======================================
--- /trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Fri Feb
5 10:47:31 2010
+++ /trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Mon Feb
8 10:12:47 2010
@@ -818,7 +818,7 @@
}
SQLIndex pk = t.getPrimaryKeyIndex();
- if (pk != null) {
+ if (pk.getChildCount() > 0) {
print(",\n");
print(" ");
writePKConstraintClause(pk);
=======================================
--- /trunk/src/ca/sqlpower/architect/ddl/SQLServerDDLGenerator.java Fri
Feb 5 10:47:31 2010
+++ /trunk/src/ca/sqlpower/architect/ddl/SQLServerDDLGenerator.java Mon
Feb 8 10:12:47 2010
@@ -28,14 +28,14 @@
import org.apache.log4j.Logger;
-import ca.sqlpower.sqlobject.SQLObjectException;
-import ca.sqlpower.sqlobject.SQLObjectRuntimeException;
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLIndex;
+import ca.sqlpower.sqlobject.SQLObjectException;
+import ca.sqlpower.sqlobject.SQLObjectRuntimeException;
import ca.sqlpower.sqlobject.SQLRelationship;
import ca.sqlpower.sqlobject.SQLTable;
-import ca.sqlpower.sqlobject.SQLRelationship.Deferrability;
import ca.sqlpower.sqlobject.SQLType;
+import ca.sqlpower.sqlobject.SQLRelationship.Deferrability;
/**
* The base class for version-specific SQL Server DDL generators. This
class is
@@ -506,11 +506,11 @@
try {
SQLIndex pk = t.getPrimaryKeyIndex();
print("\nALTER TABLE " + toQualifiedName(t.getName())
- + " DROP " + pk.getPhysicalName());
+ + " DROP " + pk.getPhysicalName());
+ endStatement(DDLStatement.StatementType.DROP, t);
} catch (SQLObjectException e) {
throw new SQLObjectRuntimeException(e);
}
- endStatement(DDLStatement.StatementType.DROP, t);
}
@Override
=======================================
--- /trunk/src/ca/sqlpower/architect/diff/CompareSQL.java Mon Dec 21
08:27:43 2009
+++ /trunk/src/ca/sqlpower/architect/diff/CompareSQL.java Mon Feb 8
10:12:47 2010
@@ -666,7 +666,7 @@
}
if ( keyChangeFlag ) {
- if (sourceTable.getPrimaryKeyIndex() != null) {
+ if (sourceTable.getPkSize() > 0) {
diffs.add(new DiffChunk<SQLObject>(sourceTable,
DiffType.DROP_KEY));
}
diffs.add(new DiffChunk<SQLObject>(targetTable,
DiffType.KEY_CHANGED));
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/BasicTablePaneUI.java Mon Apr
6 08:10:44 2009
+++ /trunk/src/ca/sqlpower/architect/swingui/BasicTablePaneUI.java Mon Feb
8 10:12:47 2010
@@ -213,7 +213,7 @@
continue;
}
// draws the line in the table that separates primary keys from
others
- if (col.getPrimaryKeySeq() == null &&
stillNeedPKLine) {
+ if (!col.isPrimaryKey() && stillNeedPKLine) {
stillNeedPKLine = false;
currentColor = null;
y += PK_GAP;
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java Mon Dec
21 08:27:43 2009
+++ /trunk/src/ca/sqlpower/architect/swingui/ColumnEditPanel.java Mon Feb
8 10:12:47 2010
@@ -691,10 +691,10 @@
}
if (componentEnabledMap.get(colInPK).isSelected()) {
- if (column.getPrimaryKeySeq() == null) {
- column.setPrimaryKeySeq(colInPK.isSelected() ? new
Integer(column.getParent().getPkSize()) : null);
+ if (colInPK.isSelected()) {
+ column.getParent().addToPK(column);
} else {
- column.setPrimaryKeySeq(colInPK.isSelected() ? new
Integer(column.getPrimaryKeySeq()) : null);
+ column.getParent().moveAfterPK(column);
}
}
@@ -702,6 +702,8 @@
column.setAutoIncrementSequenceName(colAutoIncSequenceName.getText());
}
}
+ } catch (SQLObjectException e) {
+ throw new RuntimeException(e);
} finally {
compoundEditRoot.commit();
}
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/DataMoverPanel.java Tue Jan 5
08:48:08 2010
+++ /trunk/src/ca/sqlpower/architect/swingui/DataMoverPanel.java Mon Feb 8
10:12:47 2010
@@ -284,7 +284,7 @@
// setup PK
for (SQLColumn srcCol : sourceTable.getColumns()) {
SQLColumn destCol =
destTable.getColumnByName(srcCol.getName());
- destCol.setPrimaryKeySeq(srcCol.getPrimaryKeySeq());
+ destTable.getPrimaryKeyIndex().addIndexColumn(destCol);
}
// TODO indexes and foriegn keys
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/IndexColumnTable.java Mon Jan
25 09:01:33 2010
+++ /trunk/src/ca/sqlpower/architect/swingui/IndexColumnTable.java Mon Feb
8 10:12:47 2010
@@ -480,28 +480,21 @@
* the ordering that the user provided in the JTable.
*/
public void finalizeIndex() {
- try {
- //First remove all the children of the index
- for (int i = index.getChildCount() - 1; i >= 0; i--) {
- index.removeChild(index.getChildren().get(i));// remove
all current children
- }
- for(Row r : model.getRowList()) {
- if (r.isEnabled()){
- if (r.getSQLColumn() != null) {
- index.addIndexColumn(r.getSQLColumn(),
r.getOrder());
- } else {
- logger.debug("Adding index column with no
SQLColumn. Column name is " + r.getColumn().getName());
- index.addIndexColumn(r.getColumn().getName(),
r.getOrder());
- }
+ List<Column> colsToMatch = new ArrayList<Column>();
+ for(Row r : model.getRowList()) {
+ if (r.isEnabled()){
+ if (r.getSQLColumn() != null) {
+ colsToMatch.add(new Column(r.getSQLColumn(),
r.getOrder()));
+ } else {
+ logger.debug("Adding index column with no SQLColumn.
Column name is " + r.getColumn().getName());
+ colsToMatch.add(new Column(r.getColumn().getName(),
r.getOrder()));
}
}
-
+ }
+ try {
+ index.makeColumnsLike(colsToMatch);
} catch (SQLObjectException e) {
throw new SQLObjectRuntimeException(e);
- } catch (IllegalArgumentException e) {
- throw new RuntimeException(e);
- } catch (ObjectDependentException e) {
- throw new RuntimeException(e);
}
}
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/IndexEditPanel.java Mon Dec 21
08:27:43 2009
+++ /trunk/src/ca/sqlpower/architect/swingui/IndexEditPanel.java Mon Feb 8
10:12:47 2010
@@ -35,7 +35,6 @@
import ca.sqlpower.object.ObjectDependentException;
import ca.sqlpower.sql.JDBCDataSourceType;
-import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLIndex;
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLObjectRuntimeException;
@@ -202,7 +201,7 @@
this.index = index;
name.setText(index.getName());
indexCopy = new SQLIndex(index);
- indexCopy.setPrimaryKeyIndex(false);
+ indexCopy.setParent(null);
}
private void loadIndexIntoPanel() {
@@ -268,26 +267,6 @@
//The operation is successful
index.makeColumnsLike(indexCopy);
SQLTable parentTable = parent;
- if (index.isPrimaryKeyIndex()) {
- try {
- parentTable.setMagicEnabled(false);
- for (SQLColumn c : parentTable.getColumns()) {
- c.setPrimaryKeySeq(null);
- }
- int i = 0;
- for (Column c : index.getChildren(Column.class)) {
- SQLColumn column = c.getColumn();
- if (column != null) {
- column.setPrimaryKeySeq(Integer.MAX_VALUE);
- parentTable.removeColumn(column);
- parentTable.addColumn(column, i, false);
- i++;
- }
- }
- } finally {
- parentTable.setMagicEnabled(true);
- }
- }
index.setName(name.getText());
index.setUnique(unique.isSelected());
index.setClustered(clustered.isSelected());
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Thu
Jan 28 15:27:58 2010
+++ /trunk/src/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Mon
Feb 8 10:12:47 2010
@@ -1280,7 +1280,7 @@
propNames.put("nullable", new Integer(((SQLColumn)
o).getNullable())); //$NON-NLS-1$
propNames.put("remarks", ((SQLColumn) o).getRemarks());
//$NON-NLS-1$
propNames.put("defaultValue", ((SQLColumn)
o).getDefaultValue()); //$NON-NLS-1$
- propNames.put("primaryKeySeq", ((SQLColumn)
o).getPrimaryKeySeq()); //$NON-NLS-1$
+ propNames.put("primaryKeySeq", ((SQLColumn)
o).isPrimaryKey() ? ((SQLColumn)
o).getParent().getChildrenWithoutPopulating(SQLColumn.class).indexOf(o) :
null); //$NON-NLS-1$
propNames.put("autoIncrement", Boolean.valueOf(((SQLColumn)
o).isAutoIncrement())); //$NON-NLS-1$
propNames.put("referenceCount", new
Integer(((SQLColumn)o).getReferenceCount())); //$NON-NLS-1$
if (((SQLColumn) o).isAutoIncrementSequenceNameSet()) {
@@ -1333,8 +1333,6 @@
sqlObjectSaveIdMap.put(o, id);
- boolean skipChildren = false;
-
//ioo.print("<"+type+" hashCode=\""+o.hashCode()+"\"
id=\""+id+"\" "); // use this for debugging duplicate object problems
ioo.print(out, "<"+type+" id="+quote(id)+" "); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
@@ -1352,7 +1350,7 @@
ioo.niprint(out, key+"="+quote(value.toString())+" ");
//$NON-NLS-1$ //$NON-NLS-2$
}
}
- if ( (!skipChildren) && o.allowsChildren() ) {
+ if (o.allowsChildren()) {
ioo.niprintln(out, ">"); //$NON-NLS-1$
Iterator children;
if (getSession().isSavingEntireSource()) {
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/TablePane.java Mon Jan 25
09:01:33 2010
+++ /trunk/src/ca/sqlpower/architect/swingui/TablePane.java Mon Feb 8
10:12:47 2010
@@ -516,17 +516,12 @@
+"' to table '"+getModel().getName()
//$NON-NLS-1$
+"' at
position "+ipWatcher.getInsertionPoint()); //$NON-NLS-1$
}
- getModel().addColumn(col,
ipWatcher.getInsertionPoint());
+ getModel().addColumn(col, newColumnsInPk,
ipWatcher.getInsertionPoint());
// You need to disable the normalization otherwise it goes
around
// the property change events and causes undo to fail when
dragging
// into the primary key of a table
logger.debug("Column listeners are " +
col.getSPListeners());
- if (newColumnsInPk) {
- col.setPrimaryKeySeqAndRearrangeCols(new
Integer(ipWatcher.getInsertionPoint()), false);
- } else {
-
col.setPrimaryKeySeqAndRearrangeCols(null, false);
- }
} else {
// importing column from a source database
getModel().inherit(insertionPoint, col, newColumnsInPk,
duplicateProperties.getDefaultTransferStyle(),
duplicateProperties.isPreserveColumnSource());
@@ -810,13 +805,6 @@
} finally {
setInsertionPoint(ITEM_INDEX_NONE);
- try {
- getModel().normalizePrimaryKey();
- } catch (SQLObjectException e) {
- logger.error("Error processing normalize PrimaryKey", e);
//$NON-NLS-1$
- ASUtils.showExceptionDialogNoReport(getParent().getOwner(),
- "Error processing normalize PrimaryKey after
processing drop operation", e); //$NON-NLS-1$
- }
}
return success;
}
@@ -933,7 +921,7 @@
public int getHiddenPkCount() {
int count = 0;
for (SQLColumn c : hiddenColumns) {
- if (c.getPrimaryKeySeq() != null) {
+ if (c.isPrimaryKey()) {
count++;
}
}
=======================================
---
/trunk/src/ca/sqlpower/architect/swingui/action/DeleteSelectedAction.java
Tue Jan 5 08:48:08 2010
+++
/trunk/src/ca/sqlpower/architect/swingui/action/DeleteSelectedAction.java
Mon Feb 8 10:12:47 2010
@@ -39,14 +39,13 @@
import ca.sqlpower.architect.swingui.DBTree;
import ca.sqlpower.architect.swingui.PlayPen;
import ca.sqlpower.object.ObjectDependentException;
-import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.LockedColumnException;
import ca.sqlpower.sqlobject.SQLColumn;
import ca.sqlpower.sqlobject.SQLIndex;
import ca.sqlpower.sqlobject.SQLObject;
+import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLRelationship;
import ca.sqlpower.sqlobject.SQLTable;
-import ca.sqlpower.sqlobject.SQLIndex.Column;
public class DeleteSelectedAction extends AbstractArchitectAction {
private static final Logger logger =
Logger.getLogger(DeleteSelectedAction.class);
@@ -137,15 +136,6 @@
if (o instanceof SQLIndex) {
SQLIndex index = (SQLIndex) o;
o.getParent().removeChild(o);
- List<SQLColumn> cols = new ArrayList<SQLColumn>();
- for (Column col : index.getChildren(Column.class))
{
- cols.add(col.getColumn());
- }
- for (SQLColumn col : cols) {
- if (col != null) {
- col.setPrimaryKeySeq(null);
- }
- }
} else {
//Side effect of removing a relationship's parent
table is to remove the relationship
//causing this to fail if the relationship is
removed immediately after.