Author: thomasobrien95
Date: Tue Dec 16 08:38:11 2008
New Revision: 2886

Added:
   trunk/regress/ca/sqlpower/architect/ddl/GenericDDLGeneratorTest.java
trunk/src/ca/sqlpower/architect/ddl/RelationshipMapsNoColumnsDDLWarning.java
Modified:
   trunk/src/ca/sqlpower/architect/ddl/GenericDDLGenerator.java

Log:
Fix for bug 1354. DDL validation was not giving a warning if a
relationship existed that had no columns. A warning now exists with
a test case for this bug.

Added: trunk/regress/ca/sqlpower/architect/ddl/GenericDDLGeneratorTest.java
==============================================================================
--- (empty file)
+++ trunk/regress/ca/sqlpower/architect/ddl/GenericDDLGeneratorTest.java Tue Dec 16 08:38:11 2008
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2008, 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.ddl;
+
+import junit.framework.TestCase;
+import ca.sqlpower.architect.SQLRelationship;
+import ca.sqlpower.architect.SQLTable;
+
+public class GenericDDLGeneratorTest extends TestCase {
+
+    /**
+ * Regression testing for bug 1354. If a relationship is forward engineered
+     * but has no columns then it should be skipped.
+     */
+    public void testSkipRelationWithNoColumns() throws Exception {
+        GenericDDLGenerator ddl = new GenericDDLGenerator();
+        SQLRelationship r = new SQLRelationship();
+        r.setName("Test Relation");
+        SQLTable pkTable = new SQLTable();
+        pkTable.initFolders(true);
+        SQLTable fkTable = new SQLTable();
+        fkTable.initFolders(true);
+        r.attachRelationship(pkTable, fkTable, true);
+        ddl.addRelationship(r);
+
+        assertEquals(1, ddl.getWarnings().size());
+    }
+}

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 Dec 16 08:38:11 2008
@@ -340,6 +340,11 @@
                colNameMap.clear();
                firstColumn = true;

+               if (r.getMappings().isEmpty()) {
+ warnings.add(new RelationshipMapsNoColumnsDDLWarning(r.getPkTable(), r.getFkTable()));
+                   errorMsg.append("Warning: Relationship has no columns to 
map:\n");
+               }
+               
                for (ColumnMapping cm : r.getMappings()) {
                        SQLColumn c = cm.getPkColumn();
                        SQLColumn fkCol = cm.getFkColumn();

Added: trunk/src/ca/sqlpower/architect/ddl/RelationshipMapsNoColumnsDDLWarning.java
==============================================================================
--- (empty file)
+++ trunk/src/ca/sqlpower/architect/ddl/RelationshipMapsNoColumnsDDLWarning.java Tue Dec 16 08:38:11 2008
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2008, 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.ddl;
+
+import java.util.Arrays;
+
+import ca.sqlpower.architect.SQLObject;
+import ca.sqlpower.architect.SQLTable;
+
+/**
+ * A DDL warning for when a relationship does not map any columns. There is no
+ * quick fix as the user will need to create columns.
+ */
+public class RelationshipMapsNoColumnsDDLWarning extends AbstractDDLWarning {
+
+ public RelationshipMapsNoColumnsDDLWarning(SQLTable pkTable, SQLTable fkTable) { + super(Arrays.asList(new SQLObject[] { pkTable, fkTable }), "No columns mapped in relationship between tables " + + pkTable.getName() + " and " + fkTable.getName(), false, null, null, null);
+    }
+}

Reply via email to