Revision: 3662
Author: [email protected]
Date: Wed Jun 30 14:35:34 2010
Log: NEW - bug 2458: Create Critic Manager
http://trillian.sqlpower.ca/bugzilla/show_bug.cgi?id=2458

Exporting DDL now runs critics for only the platforms of the type you are exporting to. This prevents extra warnings from appearing.
http://code.google.com/p/power-architect/source/detail?r=3662

Modified:
/trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticAndSettings.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticManager.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/action/ExportDDLAction.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticAndSettings.java Wed Jun 30 12:59:24 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticAndSettings.java Wed Jun 30 14:35:34 2010
@@ -22,6 +22,16 @@
 import java.util.Collections;
 import java.util.List;

+import ca.sqlpower.architect.ddl.DB2DDLGenerator;
+import ca.sqlpower.architect.ddl.DDLGenerator;
+import ca.sqlpower.architect.ddl.H2DDLGenerator;
+import ca.sqlpower.architect.ddl.HSQLDBDDLGenerator;
+import ca.sqlpower.architect.ddl.MySqlDDLGenerator;
+import ca.sqlpower.architect.ddl.OracleDDLGenerator;
+import ca.sqlpower.architect.ddl.PostgresDDLGenerator;
+import ca.sqlpower.architect.ddl.SQLServer2000DDLGenerator;
+import ca.sqlpower.architect.ddl.SQLServer2005DDLGenerator;
+import ca.sqlpower.architect.ddl.SQLServerDDLGenerator;
 import ca.sqlpower.object.AbstractSPObject;
 import ca.sqlpower.object.SPObject;
 import ca.sqlpower.object.annotation.Accessor;
@@ -52,26 +62,68 @@
      * user-defined platform types to these types in the future.
      */
     public enum StarterPlatformTypes {
-        GENERIC("Generic"),
-        POSTGRESQL("PostgreSQL"),
-        MY_SQL("MySQL"),
-        SQL_SERVER("SQL Server"),
-        SQL_SERVER_2000("SQL Server 2000"),
-        SQL_SERVER_2005("SQL Server 2005"),
-        ORACLE("Oracle"),
-        DB2("DB2"),
-        H2("H2"),
-        HSQLDB("HSQLDB");
-
+        GENERIC("Generic", DDLGenerator.class),
+        POSTGRESQL("PostgreSQL", PostgresDDLGenerator.class),
+        MY_SQL("MySQL", MySqlDDLGenerator.class),
+        SQL_SERVER("SQL Server", SQLServerDDLGenerator.class),
+ SQL_SERVER_2000("SQL Server 2000", SQLServer2000DDLGenerator.class), + SQL_SERVER_2005("SQL Server 2005", SQLServer2005DDLGenerator.class),
+        ORACLE("Oracle", OracleDDLGenerator.class),
+        DB2("DB2", DB2DDLGenerator.class),
+        H2("H2", H2DDLGenerator.class),
+        HSQLDB("HSQLDB", HSQLDBDDLGenerator.class);
+
+        /**
+ * Human readable group name of the platform type which the critics using will
+         * be grouped by.
+         */
         private final String name;

-        private StarterPlatformTypes(String name) {
+        /**
+ * DDLGenerators associated with the platform. Some critic groups may
+         * only be meant to be executed if you are looking at forward
+ * engineering to a specific platform. If the group is only meant for a + * specific set of DDL generators provide their classes or a super class
+         * of only those types. If you want all of the platforms to be
+         * associated with the set of critics use the interface.
+         */
+        private final Class<? extends DDLGenerator>[] associatedGenerators;
+
+ private StarterPlatformTypes(String name, Class<? extends DDLGenerator> ... associatedGenerators) {
             this.name = name;
+            this.associatedGenerators = associatedGenerators;
         }

         public String getName() {
             return name;
         }
+
+        /**
+ * Finds the starter platform type by name. Not all critic group names
+         * have to be one of the starter types so this may be null.
+         */
+        public static StarterPlatformTypes getByGroupName(String name) {
+            for (StarterPlatformTypes type : values()) {
+                if (type.getName().equals(name)) {
+                    return type;
+                }
+            }
+            return null;
+        }
+
+        /**
+ * Returns true if this group is associated with the given generator + * class. (ie, if it is or extends a class that is connected to this
+         * group.)
+         */
+ public boolean isAssociated(Class<? extends DDLGenerator> associatedGenerator) { + for (Class<? extends DDLGenerator> generatorClass : associatedGenerators) {
+                if (generatorClass.isAssignableFrom(associatedGenerator)) {
+                    return true;
+                }
+            }
+            return false;
+        }
     }

     /**
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticManager.java Wed Jun 30 12:59:24 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/critic/CriticManager.java Wed Jun 30 14:35:34 2010
@@ -25,6 +25,7 @@
 import java.util.List;

 import ca.sqlpower.architect.ArchitectProject;
+import ca.sqlpower.architect.ddl.DDLGenerator;
 import ca.sqlpower.architect.ddl.critic.CriticAndSettings.Severity;
import ca.sqlpower.architect.ddl.critic.CriticAndSettings.StarterPlatformTypes;
 import ca.sqlpower.architect.ddl.critic.impl.AlphaNumericNameCritic;
@@ -172,9 +173,27 @@
      * are created.
      */
     public List<Criticism> criticize(Object root) {
+        return criticize(null, root);
+    }
+
+    /**
+ * Returns a list of criticisms calculated by critics in this manager based + * on the object passed to them. These criticisms are immutable after they
+     * are created.
+     *
+     * @param generatorClass
+ * The generator type we will be using to create DDL with. Will
+     *            limit some of the enabled critics to only use critics
+ * associated with this DDL generators of this type. If null all
+     *            enabled critics will be used.
+     */
+ public List<Criticism> criticize(Class<? extends DDLGenerator> generatorClass, Object root) {
         List<Critic> critics = new ArrayList<Critic>();
         for (CriticGrouping grouping : criticGroupings) {
             if (!grouping.isEnabled()) continue;
+ final StarterPlatformTypes starterTypeByGroupName = StarterPlatformTypes.getByGroupName(grouping.getPlatformType());
+            if (generatorClass != null && starterTypeByGroupName != null &&
+ !starterTypeByGroupName.isAssociated(generatorClass)) continue; for (CriticAndSettings singleSettings : grouping.getSettings()) { if (Severity.IGNORE.equals(singleSettings.getSeverity())) continue;
                 critics.add(singleSettings);
@@ -182,6 +201,7 @@
         }
         Criticizer criticizer = new Criticizer(critics);
         return Collections.unmodifiableList(criticizer.criticize(root));
+
     }

     @Override
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/action/ExportDDLAction.java Wed Jun 30 09:06:21 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/action/ExportDDLAction.java Wed Jun 30 14:35:34 2010
@@ -97,7 +97,8 @@
              * generateAndDisplayDDL method.
              */
private void checkErrorsAndGenerateDDL(final DDLGenerator ddlg) { - List<Criticism> criticisms = session.getWorkspace().getCriticManager().criticize(session.getTargetDatabase()); + List<Criticism> criticisms = session.getWorkspace().getCriticManager(). + criticize(ddlg.getClass(), session.getTargetDatabase());
                 if (criticisms.isEmpty()) {
                     try {
                         generateAndDisplayDDL(ddlPanel, ddlg);

Reply via email to