Revision: 3589
Author: [email protected]
Date: Tue Jun 8 07:36:06 2010
Log: Implementation of a critic that checks the max. length for comments in
MySQL
http://code.google.com/p/power-architect/source/detail?r=3589
Added:
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CommentCritic.java
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/MySQLCommentCritic.java
Modified:
/trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticizeAction.java
=======================================
--- /dev/null
+++
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CommentCritic.java
Tue Jun 8 07:36:06 2010
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2009, 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.critic;
+
+import ca.sqlpower.sqlobject.SQLColumn;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import ca.sqlpower.sqlobject.SQLObject;
+import ca.sqlpower.sqlobject.SQLTable;
+
+public class CommentCritic implements Critic<SQLObject> {
+
+ private final int maxTableCommentLength;
+ private final int maxColumnCommentLength;
+ private final String platformName;
+
+ public CommentCritic(String platformName, int maxLengthTable, int
maxLengthColumn) {
+ this.platformName = platformName;
+ this.maxColumnCommentLength = maxLengthColumn;
+ this.maxTableCommentLength = maxLengthTable;
+ }
+
+ public List<Criticism<SQLObject>> criticize(final SQLObject so) {
+
+ if (!(so instanceof SQLTable || so instanceof SQLColumn)) return
Collections.emptyList();
+
+ String remarks = null;
+ int maxLength = 0;
+
+ if (so instanceof SQLTable) {
+ remarks = ((SQLTable)so).getRemarks();
+ maxLength = maxTableCommentLength;
+ } else if (so instanceof SQLColumn) {
+ remarks = ((SQLColumn)so).getRemarks();
+ maxLength = maxColumnCommentLength;
+ }
+
+ List<Criticism<SQLObject>> criticisms = new
ArrayList<Criticism<SQLObject>>();
+ if (remarks != null && remarks.length() > maxLength && maxLength >
0) {
+ criticisms.add(new Criticism<SQLObject>(
+ so,
+ "Comment too long for " + platformName,
+ new QuickFix("Truncate comment to " + maxLength + "
characters") {
+ public void apply() {
+ if (so instanceof SQLTable) {
+ SQLTable tbl = (SQLTable)so;
+ if (tbl.getRemarks() != null &&
tbl.getRemarks().length() > maxTableCommentLength) {
+
tbl.setRemarks(tbl.getRemarks().substring(maxTableCommentLength));
+ }
+ } else if (so instanceof SQLColumn) {
+ SQLColumn col = (SQLColumn)so;
+ if (col.getRemarks() != null &&
col.getRemarks().length() > maxColumnCommentLength) {
+
col.setRemarks(col.getRemarks().substring(maxColumnCommentLength));
+ }
+ }
+ }
+ }));
+ }
+
+ return criticisms;
+ }
+}
=======================================
--- /dev/null
+++
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/MySQLCommentCritic.java
Tue Jun 8 07:36:06 2010
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2009, 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.critic;
+
+public class MySQLCommentCritic
+ extends CommentCritic {
+
+ public MySQLCommentCritic() {
+ super("MySQL", 255, 60);
+ }
+
+
+}
=======================================
---
/trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticizeAction.java
Thu Mar 4 08:08:10 2010
+++
/trunk/src/main/java/ca/sqlpower/architect/swingui/critic/CriticizeAction.java
Tue Jun 8 07:36:06 2010
@@ -29,6 +29,7 @@
import ca.sqlpower.architect.ddl.critic.Critic;
import ca.sqlpower.architect.ddl.critic.Criticizer;
+import ca.sqlpower.architect.ddl.critic.MySQLCommentCritic;
import ca.sqlpower.architect.ddl.critic.PhysicalNameCritic;
import ca.sqlpower.architect.ddl.critic.PrimaryKeyCritic;
import ca.sqlpower.architect.ddl.critic.RelationshipMappingTypeCritic;
@@ -58,6 +59,7 @@
public void actionPerformed(ActionEvent e) {
List<Critic<SQLObject>> critics = new
ArrayList<Critic<SQLObject>>();
critics.add(new PhysicalNameCritic("Oracle",
Pattern.compile("^[a-z_][a-z0-9_]*$", Pattern.CASE_INSENSITIVE), 30));
+ critics.add(new MySQLCommentCritic());
critics.add(new PrimaryKeyCritic());
critics.add(new RelationshipMappingTypeCritic());
Criticizer<SQLObject> criticizer = new
Criticizer<SQLObject>(critics);