Author: daceywang
Date: Tue Apr 7 10:03:13 2009
New Revision: 2975
Modified:
trunk/regress/ca/sqlpower/architect/swingui/TestTableEditPane.java
trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
trunk/src/ca/sqlpower/architect/ddl/InvalidNameDDLWarning.java
trunk/src/ca/sqlpower/architect/swingui/DBTree.java
trunk/src/ca/sqlpower/architect/swingui/TableEditPanel.java
trunk/src/ca/sqlpower/architect/swingui/action/PasteSelectedAction.java
Log:
1.Now allows the user to touch the physical name of SQLColumn and SQLTable.
Physical name will not be generated or corrected when forward engineer if
user has set one but will pop up a warning if it's not valid for the
specific database. So far the user has to set the logical name for a column
or table, we can generate the physical name for them like before if
physical name is blank.
2.Also modified SQLRelationship and SQLIndex to use physical name if it's
not empty instead of logical name anymore.
3.Added some test cases for physical name and changed some test cases for
SQLColumnSQLRelationship and TableEditPanel.
This is a fix for bug 1784. Notice that the user will lose their logical
names if they forward and then reverse engineer. However, they are supposed
to save the project to save their logical names.
Michelle is working on reporting formats, which is the only thing left for
this bug fix.
Modified: trunk/regress/ca/sqlpower/architect/swingui/TestTableEditPane.java
==============================================================================
--- trunk/regress/ca/sqlpower/architect/swingui/TestTableEditPane.java
(original)
+++ trunk/regress/ca/sqlpower/architect/swingui/TestTableEditPane.java Tue
Apr 7 10:03:13 2009
@@ -35,6 +35,7 @@
ArchitectSwingSession session = context.createSession();
t = new SQLTable(session.getTargetDatabase(), true);
t.setName("Test Table");
+ t.setPhysicalName("Test_Table_1");
SQLColumn pk1 = new SQLColumn(t, "PKColumn1", Types.INTEGER,
10,0);
t.addColumn(0,pk1);
@@ -43,25 +44,37 @@
tep = new TableEditPanel(session, t);
}
- public void testChangeName(){
+ public void testChangeName() {
tep.setNameText("New Name");
tep.applyChanges();
assertEquals ("New Name", t.getName());
}
+
+ public void testChangePhysicalName(){
+ tep.setPhysicalNameText("New_Name");
+ tep.applyChanges();
+ assertEquals("New_Name", t.getPhysicalName());
+ }
- public void testNameChangeUpdatesPk() throws Exception {
- assertEquals("Test Table_pk", t.getPrimaryKeyName());
- tep.setNameText("New Name");
+ public void testPrimaryNameChangeUpdatesPk() throws Exception {
+ assertEquals("Test_Table_1_pk", t.getPrimaryKeyName());
+ tep.setPhysicalNameText("New Name");
tep.applyChanges();
assertEquals ("New Name_pk", t.getPrimaryKeyName());
}
- public void testNameChangeDoesNotUpdatePkWhenPkNameAlsoChanged()
throws Exception {
- assertEquals("Test Table_pk", t.getPrimaryKeyName());
- tep.setNameText("New Name");
+ public void testNameChangeDoesNotUpdatePK() throws Exception {
+ tep.setNameText("New Table Name");
+ tep.applyChanges();
+ assertEquals("Test_Table_1_pk", t.getPrimaryKeyName());
+ }
+
+ public void
testPhysicalNameChangeDoesNotUpdatePkWhenPkNameAlsoChanged() throws
Exception {
+ assertEquals("Test_Table_1_pk", t.getPrimaryKeyName());
+ tep.setPhysicalNameText("New Name");
tep.setPkNameText("New PK Name");
tep.applyChanges();
- assertEquals ("New PK Name", t.getPrimaryKeyName());
+ assertEquals ("New PK Name", t.getPhysicalPrimaryKeyName());
}
}
Modified: trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
(original)
+++ trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Tue Apr 7
10:03:13 2009
@@ -1046,8 +1046,22 @@
* @throws SQLObjectException
*/
protected String createPhysicalName(Map<String, SQLObject> dupCheck,
SQLObject so) {
- logger.debug("transform identifier source: " +
so.getPhysicalName());
- so.setPhysicalName(toIdentifier(so.getName()));
+ logger.debug("transform identifier source: " +
so.getPhysicalName());
+ if ((so instanceof SQLTable || so instanceof SQLColumn) &&
+ (so.getPhysicalName() != null
&& !so.getPhysicalName().trim().equals(""))) {
+ String physicalName = so.getPhysicalName();
+ logger.debug("The physical name for this SQLObject is: " +
physicalName);
+ if (physicalName.lastIndexOf(' ') != -1) {
+ String renameTo = (toIdentifier(physicalName));
+ warnings.add(new InvalidNameDDLWarning(
+ String.format("Name %s has white spaces",
physicalName),
+ Arrays.asList(new SQLObject[] {so}),
+ String.format("Rename %s to %s", physicalName, renameTo
),
+ so, renameTo));
+ }
+ } else {
+ so.setPhysicalName(toIdentifier(so.getName()));
+ }
String physicalName = so.getPhysicalName();
if(isReservedWord(physicalName)) {
String renameTo = physicalName + "_1";
@@ -1058,18 +1072,19 @@
so, renameTo));
return physicalName;
}
-
+ logger.debug("The logical name field now is: " + so.getName());
+ logger.debug("The physical name field now is: " + physicalName);
int pointIndex = so.getPhysicalName().lastIndexOf('.');
- if
(!so.getName().substring(pointIndex+1,pointIndex+2).matches("[a-zA-Z]")){
+ if
(!so.getPhysicalName().substring(pointIndex+1,pointIndex+2).matches("[a-zA-Z]")){
String renameTo;
if (so instanceof SQLTable) {
- renameTo = "Table_" + so.getName();
+ renameTo = "Table_" + so.getPhysicalName();
} else if (so instanceof SQLColumn) {
- renameTo = "Column_" + so.getName();
+ renameTo = "Column_" + so.getPhysicalName();
} else if (so instanceof SQLIndex) {
- renameTo = "Index_" + so.getName();
+ renameTo = "Index_" + so.getPhysicalName();
} else {
- renameTo = "X_" + so.getName();
+ renameTo = "X_" + so.getPhysicalName();
}
warnings.add(new InvalidNameDDLWarning(
String.format("Name %s starts with a non-alpha
character", physicalName),
@@ -1100,17 +1115,17 @@
String message;
if (so instanceof SQLColumn) {
message = String.format("Column name %s in table %s
already in use",
- so.getName(),
- ((SQLColumn) so).getParentTable().getName());
+ so.getPhysicalName(),
+ ((SQLColumn)
so).getParentTable().getPhysicalName());
} else {
- message = String.format("Global name %s already in use",
physicalName);
+ message = String.format("Global name %s already in use",
physicalName2);
}
logger.debug("Rename to : " + renameTo2);
warnings.add(new InvalidNameDDLWarning(
message,
Arrays.asList(new SQLObject[] { so }),
- String.format("Rename %s to %s", physicalName,
renameTo2),
+ String.format("Rename %s to %s", physicalName2,
renameTo2),
so, renameTo2));
dupCheck.put(renameTo2, so);
@@ -1197,6 +1212,7 @@
*/
private String createPhysicalPrimaryKeyName(SQLTable t) throws
SQLObjectException {
+ logger.debug("The physical primary key name of the table is: " +
t.getPhysicalPrimaryKeyName());
String physName = toIdentifier(t.getPrimaryKeyName());
t.setPhysicalPrimaryKeyName(physName);
createPhysicalName(topLevelNames, t.getPrimaryKeyIndex());
Modified: trunk/src/ca/sqlpower/architect/ddl/InvalidNameDDLWarning.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/ddl/InvalidNameDDLWarning.java
(original)
+++ trunk/src/ca/sqlpower/architect/ddl/InvalidNameDDLWarning.java Tue Apr
7 10:03:13 2009
@@ -41,13 +41,13 @@
true,
quickFixMesssage,
whichObjectQuickFixRenames,
- "name");
+ "physicalName");
this.whatQuickFixShouldCallIt = whatQuickFixShouldCallIt;
}
public boolean quickFix() {
// XXX need differentiator for setName() vs setPhysicalName()
- whichObjectQuickFixFixes.setName(whatQuickFixShouldCallIt);
+ whichObjectQuickFixFixes.setPhysicalName(whatQuickFixShouldCallIt);
return true;
}
}
Modified: trunk/src/ca/sqlpower/architect/swingui/DBTree.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/DBTree.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/DBTree.java Tue Apr 7 10:03:13
2009
@@ -908,10 +908,12 @@
for (int j = i + 1; j < sortedLengths.size(); j++) {
for (SQLObject childObject :
pathLengthsToSelectedObjectsMap.get(sortedLengths.get(j))) {
SQLObject parent = childObject;
+ logger.debug("Initial Object before
recursively go to parent is: " + parent);
for (int k = 0; k < sortedLengths.get(j) -
pathCount; k++) {
parent = parent.getParent();
}
objectsToTransfer.add(parent);
+ logger.debug("Final Object after recursively
go to parent is: " + parent);
}
}
break;
@@ -963,6 +965,11 @@
logger.info("DBTree: exporting list of DnD-type tree paths");
//$NON-NLS-1$
+ }
+ if (logger.isDebugEnabled()) {
+ for(SQLObject object: objectsToTransfer) {
+ logger.debug("The object to transfer copy is: " + object);
+ }
}
return objectsToTransfer;
}
Modified: trunk/src/ca/sqlpower/architect/swingui/TableEditPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/TableEditPanel.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/TableEditPanel.java Tue Apr 7
10:03:13 2009
@@ -202,23 +202,55 @@
public JPanel getPanel() {
return this;
}
-
+
+ /**
+ * For testing only
+ * @return the String currently in the logicalName textField
+ */
public String getNameText() {
return logicalName.getText();
}
-
+
+ /**
+ * For testing only
+ * @param newName new logical name for the table
+ */
public void setNameText(String newName) {
logicalName.setText(newName);
}
-
+
+ /**
+ * For testing only
+ * @return the String currently in the pkName textField
+ */
public String getPkNameText() {
return pkName.getText();
}
-
+
+ /**
+ * For testing only
+ * @param newPKName new primaryKeyName for the table
+ */
public void setPkNameText(String newPkName) {
pkName.setText(newPkName);
}
-
+
+ /**
+ * For testing only
+ * @return the String currently in the physicalName textField
+ */
+ public String getPhysicalNameTest() {
+ return physicalName.getText();
+ }
+
+ /**
+ * For testing only
+ * @param newPhysicalName new physical name for the table
+ */
+ public void setPhysicalNameText(String newPhysicalName) {
+ physicalName.setText(newPhysicalName);
+ }
+
public boolean hasUnsavedChanges() {
// TODO return whether this panel has been changed
return true;
Modified:
trunk/src/ca/sqlpower/architect/swingui/action/PasteSelectedAction.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/action/PasteSelectedAction.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/action/PasteSelectedAction.java
Tue Apr 7 10:03:13 2009
@@ -61,7 +61,6 @@
public void
sessionClosing(SessionLifecycleEvent<ArchitectSwingSession> e) {
session.getPlayPen().removeFocusListener(focusListener);
- session.removeSessionLifecycleListener(this);
}
};
session.addSessionLifecycleListener(lifecycleListener);