Revision: 3611
Author: [email protected]
Date: Mon Jun 14 07:39:24 2010
Log: Added in a critic that warns users if there are relationships that
match no columns in the data model.
http://code.google.com/p/power-architect/source/detail?r=3611
Added:
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/EmptyRelationshipCritic.java
Modified:
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticManager.java
=======================================
--- /dev/null
+++
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/impl/EmptyRelationshipCritic.java
Mon Jun 14 07:39:24 2010
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2010, SQL Power Group Inc.
+ *
+ * This file is part of SQL Power Architect.
+ *
+ * SQL 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.
+ *
+ * SQL 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.critic.impl;
+
+import java.util.Collections;
+import java.util.List;
+
+import ca.sqlpower.architect.ddl.critic.CriticAndSettings;
+import ca.sqlpower.architect.ddl.critic.Criticism;
+import ca.sqlpower.sqlobject.SQLRelationship;
+
+/**
+ * Criticizes relationships if they do not have any columns mapped.
+ */
+public class EmptyRelationshipCritic extends CriticAndSettings {
+
+ public EmptyRelationshipCritic() {
+ super(StarterPlatformTypes.GENERIC.getName(), "Empty
relationships");
+ }
+
+ public List<Criticism> criticize(Object subject) {
+ if (subject instanceof SQLRelationship) {
+ SQLRelationship relation = (SQLRelationship) subject;
+ if (relation.getChildren().size() == 0) {
+ return Collections.singletonList(
+ new Criticism(subject,
+ "The relationship " + relation.getName()
+ " maps no children.",
+ EmptyRelationshipCritic.this));
+ }
+ }
+ return Collections.emptyList();
+ }
+
+}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticManager.java
Wed Jun 9 11:52:17 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticManager.java
Mon Jun 14 07:39:24 2010
@@ -26,6 +26,7 @@
import ca.sqlpower.architect.ddl.critic.CriticAndSettings.Severity;
import
ca.sqlpower.architect.ddl.critic.CriticAndSettings.StarterPlatformTypes;
+import ca.sqlpower.architect.ddl.critic.impl.EmptyRelationshipCritic;
import ca.sqlpower.architect.ddl.critic.impl.MySQLCommentCritic;
import ca.sqlpower.architect.ddl.critic.impl.OraclePhysicalNameCritic;
import ca.sqlpower.architect.ddl.critic.impl.PrimaryKeyCritic;
@@ -54,10 +55,12 @@
*/
private static final List<CriticAndSettings> STARTING_CRITICS =
Collections.unmodifiableList(Arrays.asList(
- new OraclePhysicalNameCritic(),
- new MySQLCommentCritic(),
new PrimaryKeyCritic(),
- new RelationshipMappingTypeCritic()));
+ new RelationshipMappingTypeCritic(),
+ new EmptyRelationshipCritic(),
+ new OraclePhysicalNameCritic(),
+ new MySQLCommentCritic()
+ ));
/**
* All of the critic groups known to this system.