You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by jg...@apache.org on 2008/12/28 23:29:11 UTC

svn commit: r729795 - in /ibatis/trunk/java/tools/ibator/core: build/ src/org/apache/ibatis/ibator/api/ src/org/apache/ibatis/ibator/internal/rules/

Author: jgbutler
Date: Sun Dec 28 14:29:10 2008
New Revision: 729795

URL: http://svn.apache.org/viewvc?rev=729795&view=rev
Log:
Changes for IBATIS-569 - provide a method of overriding IbatorRules

Added:
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/BaseIbatorRules.java
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRulesDelegate.java
Modified:
    ibatis/trunk/java/tools/ibator/core/build/version.properties
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/ConditionalModelRules.java
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/FlatModelRules.java
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/HierarchicalModelRules.java
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRules.java

Modified: ibatis/trunk/java/tools/ibator/core/build/version.properties
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/version.properties?rev=729795&r1=729794&r2=729795&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/build/version.properties (original)
+++ ibatis/trunk/java/tools/ibator/core/build/version.properties Sun Dec 28 14:29:10 2008
@@ -1,4 +1,4 @@
 #Ibator build version info
-#Mon Dec 22 15:32:20 CST 2008
+#Sun Dec 28 16:25:29 CST 2008
 version=1.2.1
-buildNum=681
+buildNum=683

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java?rev=729795&r1=729794&r2=729795&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java Sun Dec 28 14:29:10 2008
@@ -491,11 +491,11 @@
         calculateSqlMapFileName();
         
         if (tableConfiguration.getModelType() == ModelType.HIERARCHICAL) {
-            rules = new HierarchicalModelRules(tableConfiguration, this);
+            rules = new HierarchicalModelRules(this);
         } else if (tableConfiguration.getModelType() == ModelType.FLAT) {
-            rules = new FlatModelRules(tableConfiguration, this);
+            rules = new FlatModelRules(this);
         } else {
-            rules = new ConditionalModelRules(tableConfiguration, this);
+            rules = new ConditionalModelRules(this);
         }
         
         ibatorContext.getPlugins().initialized(this);
@@ -686,4 +686,8 @@
     public void setRules(IbatorRules rules) {
         this.rules = rules;
     }
+
+    public TableConfiguration getTableConfiguration() {
+        return tableConfiguration;
+    }
 }

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/BaseIbatorRules.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/BaseIbatorRules.java?rev=729795&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/BaseIbatorRules.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/BaseIbatorRules.java Sun Dec 28 14:29:10 2008
@@ -0,0 +1,299 @@
+/*
+ *  Copyright 2006 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.ibatis.ibator.internal.rules;
+
+import org.apache.ibatis.ibator.api.IntrospectedTable;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.config.TableConfiguration;
+
+/**
+ * This class centralizes all the rules related to code generation - including
+ * the methods and objects to create, and certain attributes related to those
+ * objects.
+ * 
+ * See package JavaDoc for more information.
+ * 
+ * @author Jeff Butler
+ */
+public abstract class BaseIbatorRules implements IbatorRules {
+
+    protected TableConfiguration tableConfiguration;
+    protected IntrospectedTable introspectedTable;
+
+    /**
+     * 
+     */
+    public BaseIbatorRules(IntrospectedTable introspectedTable) {
+        super();
+        this.introspectedTable = introspectedTable;
+        this.tableConfiguration = introspectedTable.getTableConfiguration();
+    }
+
+    /**
+     * Implements the rule for generating the insert SQL Map element and DAO
+     * method. If the insert statement is allowed, then generate the element and
+     * method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateInsert() {
+        return tableConfiguration.isInsertStatementEnabled();
+    }
+
+    /**
+     * Implements the rule for generating the insert selective SQL Map element and DAO
+     * method. If the insert statement is allowed, then generate the element and
+     * method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateInsertSelective() {
+        return tableConfiguration.isInsertStatementEnabled();
+    }
+    
+    /**
+     * Calculates the class that contains all fields.  This class is used
+     * as the insert statement parameter, as well as the returned value
+     * from the select by primary key method.  The actual class depends
+     * on how the domain model is generated.
+     * 
+     * @return the type of the class that holds all fields
+     */
+    public FullyQualifiedJavaType calculateAllFieldsClass() {
+        
+        FullyQualifiedJavaType answer;
+        
+        if (generateRecordWithBLOBsClass()) {
+            answer = introspectedTable.getRecordWithBLOBsType();
+        } else if (generateBaseRecordClass()) {
+            answer = introspectedTable.getBaseRecordType();
+        } else {
+            answer = introspectedTable.getPrimaryKeyType();
+        }
+        
+        return answer;
+    }
+    
+    /**
+     * Implements the rule for generating the update by primary key without
+     * BLOBs SQL Map element and DAO method. If the table has a primary key as
+     * well as other non-BLOB fields, and the updateByPrimaryKey statement is
+     * allowed, then generate the element and method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateUpdateByPrimaryKeyWithoutBLOBs() {
+        boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
+            && introspectedTable.hasPrimaryKeyColumns()
+            && introspectedTable.hasBaseColumns();
+        
+        return rc;
+    }
+    
+    /**
+     * Implements the rule for generating the update by primary key with BLOBs
+     * SQL Map element and DAO method. If the table has a primary key as well as
+     * other BLOB fields, and the updateByPrimaryKey statement is allowed, then
+     * generate the element and method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateUpdateByPrimaryKeyWithBLOBs() {
+        boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
+            && introspectedTable.hasPrimaryKeyColumns()
+            && introspectedTable.hasBLOBColumns();
+    
+        return rc;
+    }
+
+    /**
+     * Implements the rule for generating the update by primary key selective
+     * SQL Map element and DAO method. If the table has a primary key as well as
+     * other fields, and the updateByPrimaryKey statement is allowed, then
+     * generate the element and method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateUpdateByPrimaryKeySelective() {
+        boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
+            && introspectedTable.hasPrimaryKeyColumns()
+            && (introspectedTable.hasBLOBColumns()
+                    || introspectedTable.hasBaseColumns());
+    
+        return rc;
+    }
+
+    /**
+     * Implements the rule for generating the delete by primary key SQL Map
+     * element and DAO method. If the table has a primary key, and the
+     * deleteByPrimaryKey statement is allowed, then generate the element and
+     * method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateDeleteByPrimaryKey() {
+        boolean rc = tableConfiguration.isDeleteByPrimaryKeyStatementEnabled()
+            && introspectedTable.hasPrimaryKeyColumns();
+
+        return rc;
+    }
+    
+    /**
+     * Implements the rule for generating the delete by example SQL Map element
+     * and DAO method. If the deleteByExample statement is allowed, then
+     * generate the element and method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateDeleteByExample() {
+        boolean rc = tableConfiguration.isDeleteByExampleStatementEnabled();
+
+        return rc;
+    }
+    
+    /**
+     * Implements the rule for generating the result map without BLOBs. If
+     * either select method is allowed, then generate the result map.
+     * 
+     * @return true if the result map should be generated
+     */
+    public boolean generateBaseResultMap() {
+        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
+            || tableConfiguration.isSelectByPrimaryKeyStatementEnabled();
+        
+        return rc;
+    }
+    
+    /**
+     * Implements the rule for generating the result map with BLOBs. If the
+     * table has BLOB columns, and either select method is allowed, then
+     * generate the result map.
+     * 
+     * @return true if the result map should be generated
+     */
+    public boolean generateResultMapWithBLOBs() {
+        boolean rc = (tableConfiguration.isSelectByExampleStatementEnabled()
+            || tableConfiguration.isSelectByPrimaryKeyStatementEnabled())
+            && introspectedTable.hasBLOBColumns();
+    
+        return rc;
+    }
+    
+    /**
+     * Implements the rule for generating the SQL example where clause element.
+     * Generate the element if the selectByExample or deleteByExample
+     * or countByExample statements are allowed.
+     * 
+     * @return true if the SQL where clause element should be generated
+     */
+    public boolean generateSQLExampleWhereClause() {
+        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
+            || tableConfiguration.isDeleteByExampleStatementEnabled()
+            || tableConfiguration.isCountByExampleStatementEnabled();
+        
+        return rc;
+    }
+    
+    /**
+     * Implements the rule for generating the select by primary key SQL Map
+     * element and DAO method. If the table has a primary key as well as other
+     * fields, and the selectByPrimaryKey statement is allowed, then generate
+     * the element and method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateSelectByPrimaryKey() {
+        boolean rc = tableConfiguration.isSelectByPrimaryKeyStatementEnabled()
+            && introspectedTable.hasPrimaryKeyColumns()
+            && (introspectedTable.hasBaseColumns()
+                    || introspectedTable.hasBLOBColumns());
+        
+        return rc;
+    }
+    
+    /**
+     * Implements the rule for generating the select by example without BLOBs
+     * SQL Map element and DAO method. If the selectByExample statement is
+     * allowed, then generate the element and method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateSelectByExampleWithoutBLOBs() {
+        return tableConfiguration.isSelectByExampleStatementEnabled();
+    }
+    
+    /**
+     * Implements the rule for generating the select by example with BLOBs SQL
+     * Map element and DAO method. If the table has BLOB fields and the
+     * selectByExample statement is allowed, then generate the element and
+     * method.
+     * 
+     * @return true if the element and method should be generated
+     */
+    public boolean generateSelectByExampleWithBLOBs() {
+        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
+            && introspectedTable.hasBLOBColumns();
+        
+        return rc;
+    }
+
+    /**
+     * Implements the rule for generating an example class.
+     * The class should be generated if the selectByExample or
+     * deleteByExample or countByExample methods are allowed.
+     * 
+     * @return true if the example class should be generated
+     */
+    public boolean generateExampleClass() {
+        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
+                || tableConfiguration.isDeleteByExampleStatementEnabled()
+                || tableConfiguration.isCountByExampleStatementEnabled()
+                || tableConfiguration.isUpdateByExampleStatementEnabled();
+    
+        return rc;
+    }
+    
+    public boolean generateCountByExample() {
+        boolean rc = tableConfiguration.isCountByExampleStatementEnabled();
+
+        return rc;
+    }
+
+    public boolean generateUpdateByExampleSelective() {
+        boolean rc = tableConfiguration.isUpdateByExampleStatementEnabled();
+
+        return rc;
+    }
+
+    public boolean generateUpdateByExampleWithoutBLOBs() {
+        boolean rc = tableConfiguration.isUpdateByExampleStatementEnabled()
+            && (introspectedTable.hasPrimaryKeyColumns()
+            || introspectedTable.hasBaseColumns());
+        
+        return rc;
+    }
+    
+    public boolean generateUpdateByExampleWithBLOBs() {
+        boolean rc = tableConfiguration.isUpdateByExampleStatementEnabled()
+            && introspectedTable.hasBLOBColumns();
+    
+        return rc;
+    }
+
+    public IntrospectedTable getIntrospectedTable() {
+        return introspectedTable;
+    }
+}

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/ConditionalModelRules.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/ConditionalModelRules.java?rev=729795&r1=729794&r2=729795&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/ConditionalModelRules.java (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/ConditionalModelRules.java Sun Dec 28 14:29:10 2008
@@ -17,7 +17,6 @@
 package org.apache.ibatis.ibator.internal.rules;
 
 import org.apache.ibatis.ibator.api.IntrospectedTable;
-import org.apache.ibatis.ibator.config.TableConfiguration;
 
 /**
  * This class encapsulates all the code generation rules for 
@@ -28,14 +27,13 @@
  * @author Jeff Butler
  *
  */
-public class ConditionalModelRules extends IbatorRules {
+public class ConditionalModelRules extends BaseIbatorRules {
 
     /**
      * 
      */
-    public ConditionalModelRules(TableConfiguration tableConfiguration,
-            IntrospectedTable introspectedTable) {
-        super(tableConfiguration, introspectedTable);
+    public ConditionalModelRules(IntrospectedTable introspectedTable) {
+        super(introspectedTable);
     }
 
     /**
@@ -44,7 +42,6 @@
      * 
      * @return true if the primary key should be generated
      */
-    @Override
     public boolean generatePrimaryKeyClass() {
         return introspectedTable.getPrimaryKeyColumns().size() > 1;
     }
@@ -58,7 +55,6 @@
      * 
      * @return true if the class should be generated
      */
-    @Override
     public boolean generateBaseRecordClass() {
         return introspectedTable.getBaseColumns().size() > 0
             || introspectedTable.getPrimaryKeyColumns().size() == 1
@@ -74,7 +70,6 @@
      * 
      * @return true if the record with BLOBs class should be generated
      */
-    @Override
     public boolean generateRecordWithBLOBsClass() {
         int otherColumnCount = introspectedTable.getPrimaryKeyColumns().size()
             + introspectedTable.getBaseColumns().size();

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/FlatModelRules.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/FlatModelRules.java?rev=729795&r1=729794&r2=729795&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/FlatModelRules.java (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/FlatModelRules.java Sun Dec 28 14:29:10 2008
@@ -17,7 +17,6 @@
 package org.apache.ibatis.ibator.internal.rules;
 
 import org.apache.ibatis.ibator.api.IntrospectedTable;
-import org.apache.ibatis.ibator.config.TableConfiguration;
 
 /**
  * This class encapsulates all the code generation rules for 
@@ -26,14 +25,13 @@
  * @author Jeff Butler
  *
  */
-public class FlatModelRules extends IbatorRules {
+public class FlatModelRules extends BaseIbatorRules {
 
     /**
      * 
      */
-    public FlatModelRules(TableConfiguration tableConfiguration,
-            IntrospectedTable introspectedTable) {
-        super(tableConfiguration, introspectedTable);
+    public FlatModelRules(IntrospectedTable introspectedTable) {
+        super(introspectedTable);
     }
 
     /**
@@ -41,7 +39,6 @@
      * 
      * @return true if the primary key should be generated
      */
-    @Override
     public boolean generatePrimaryKeyClass() {
         return false;
     }
@@ -51,7 +48,6 @@
      * 
      * @return true if the class should be generated
      */
-    @Override
     public boolean generateBaseRecordClass() {
         return true;
     }
@@ -61,7 +57,6 @@
      * 
      * @return true if the record with BLOBs class should be generated
      */
-    @Override
     public boolean generateRecordWithBLOBsClass() {
         return false;
     }

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/HierarchicalModelRules.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/HierarchicalModelRules.java?rev=729795&r1=729794&r2=729795&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/HierarchicalModelRules.java (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/HierarchicalModelRules.java Sun Dec 28 14:29:10 2008
@@ -17,7 +17,6 @@
 package org.apache.ibatis.ibator.internal.rules;
 
 import org.apache.ibatis.ibator.api.IntrospectedTable;
-import org.apache.ibatis.ibator.config.TableConfiguration;
 
 /**
  * This class encapsulates all the code generation rules for 
@@ -26,14 +25,13 @@
  * @author Jeff Butler
  *
  */
-public class HierarchicalModelRules extends IbatorRules {
+public class HierarchicalModelRules extends BaseIbatorRules {
 
     /**
      * 
      */
-    public HierarchicalModelRules(TableConfiguration tableConfiguration,
-            IntrospectedTable introspectedTable) {
-        super(tableConfiguration, introspectedTable);
+    public HierarchicalModelRules(IntrospectedTable introspectedTable) {
+        super(introspectedTable);
     }
 
     /**
@@ -43,7 +41,6 @@
      * 
      * @return true if the primary key should be generated
      */
-    @Override
     public boolean generatePrimaryKeyClass() {
         return introspectedTable.hasPrimaryKeyColumns();
     }
@@ -55,7 +52,6 @@
      * 
      * @return true if the class should be generated
      */
-    @Override
     public boolean generateBaseRecordClass() {
         return introspectedTable.hasBaseColumns();
     }
@@ -66,7 +62,6 @@
      * 
      * @return true if the record with BLOBs class should be generated
      */
-    @Override
     public boolean generateRecordWithBLOBsClass() {
         return introspectedTable.hasBLOBColumns();
     }

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRules.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRules.java?rev=729795&r1=729794&r2=729795&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRules.java (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRules.java Sun Dec 28 14:29:10 2008
@@ -17,31 +17,15 @@
 
 import org.apache.ibatis.ibator.api.IntrospectedTable;
 import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
-import org.apache.ibatis.ibator.config.TableConfiguration;
 
 /**
- * This class centralizes all the rules related to code generation - including
+ * This interface centralizes all the rules related to code generation - including
  * the methods and objects to create, and certain attributes related to those
  * objects.
  * 
- * See package JavaDoc for more information.
- * 
  * @author Jeff Butler
  */
-public abstract class IbatorRules {
-
-    protected TableConfiguration tableConfiguration;
-    protected IntrospectedTable introspectedTable;
-
-    /**
-     * 
-     */
-    public IbatorRules(TableConfiguration tableConfiguration,
-            IntrospectedTable introspectedTable) {
-        super();
-        this.tableConfiguration = tableConfiguration;
-        this.introspectedTable = introspectedTable;
-    }
+public interface IbatorRules {
 
     /**
      * Implements the rule for generating the insert SQL Map element and DAO
@@ -50,9 +34,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateInsert() {
-        return tableConfiguration.isInsertStatementEnabled();
-    }
+    boolean generateInsert();
 
     /**
      * Implements the rule for generating the insert selective SQL Map element and DAO
@@ -61,9 +43,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateInsertSelective() {
-        return tableConfiguration.isInsertStatementEnabled();
-    }
+    boolean generateInsertSelective();
     
     /**
      * Calculates the class that contains all fields.  This class is used
@@ -73,20 +53,7 @@
      * 
      * @return the type of the class that holds all fields
      */
-    public FullyQualifiedJavaType calculateAllFieldsClass() {
-        
-        FullyQualifiedJavaType answer;
-        
-        if (generateRecordWithBLOBsClass()) {
-            answer = introspectedTable.getRecordWithBLOBsType();
-        } else if (generateBaseRecordClass()) {
-            answer = introspectedTable.getBaseRecordType();
-        } else {
-            answer = introspectedTable.getPrimaryKeyType();
-        }
-        
-        return answer;
-    }
+    FullyQualifiedJavaType calculateAllFieldsClass();
     
     /**
      * Implements the rule for generating the update by primary key without
@@ -96,13 +63,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateUpdateByPrimaryKeyWithoutBLOBs() {
-        boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
-            && introspectedTable.hasPrimaryKeyColumns()
-            && introspectedTable.hasBaseColumns();
-        
-        return rc;
-    }
+    boolean generateUpdateByPrimaryKeyWithoutBLOBs();
     
     /**
      * Implements the rule for generating the update by primary key with BLOBs
@@ -112,13 +73,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateUpdateByPrimaryKeyWithBLOBs() {
-        boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
-            && introspectedTable.hasPrimaryKeyColumns()
-            && introspectedTable.hasBLOBColumns();
-    
-        return rc;
-    }
+    boolean generateUpdateByPrimaryKeyWithBLOBs();
 
     /**
      * Implements the rule for generating the update by primary key selective
@@ -128,14 +83,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateUpdateByPrimaryKeySelective() {
-        boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
-            && introspectedTable.hasPrimaryKeyColumns()
-            && (introspectedTable.hasBLOBColumns()
-                    || introspectedTable.hasBaseColumns());
-    
-        return rc;
-    }
+    boolean generateUpdateByPrimaryKeySelective();
 
     /**
      * Implements the rule for generating the delete by primary key SQL Map
@@ -145,12 +93,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateDeleteByPrimaryKey() {
-        boolean rc = tableConfiguration.isDeleteByPrimaryKeyStatementEnabled()
-            && introspectedTable.hasPrimaryKeyColumns();
-
-        return rc;
-    }
+    boolean generateDeleteByPrimaryKey();
     
     /**
      * Implements the rule for generating the delete by example SQL Map element
@@ -159,11 +102,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateDeleteByExample() {
-        boolean rc = tableConfiguration.isDeleteByExampleStatementEnabled();
-
-        return rc;
-    }
+    boolean generateDeleteByExample();
     
     /**
      * Implements the rule for generating the result map without BLOBs. If
@@ -171,12 +110,7 @@
      * 
      * @return true if the result map should be generated
      */
-    public boolean generateBaseResultMap() {
-        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
-            || tableConfiguration.isSelectByPrimaryKeyStatementEnabled();
-        
-        return rc;
-    }
+    boolean generateBaseResultMap();
     
     /**
      * Implements the rule for generating the result map with BLOBs. If the
@@ -185,13 +119,7 @@
      * 
      * @return true if the result map should be generated
      */
-    public boolean generateResultMapWithBLOBs() {
-        boolean rc = (tableConfiguration.isSelectByExampleStatementEnabled()
-            || tableConfiguration.isSelectByPrimaryKeyStatementEnabled())
-            && introspectedTable.hasBLOBColumns();
-    
-        return rc;
-    }
+    boolean generateResultMapWithBLOBs();
     
     /**
      * Implements the rule for generating the SQL example where clause element.
@@ -200,13 +128,7 @@
      * 
      * @return true if the SQL where clause element should be generated
      */
-    public boolean generateSQLExampleWhereClause() {
-        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
-            || tableConfiguration.isDeleteByExampleStatementEnabled()
-            || tableConfiguration.isCountByExampleStatementEnabled();
-        
-        return rc;
-    }
+    boolean generateSQLExampleWhereClause();
     
     /**
      * Implements the rule for generating the select by primary key SQL Map
@@ -216,14 +138,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateSelectByPrimaryKey() {
-        boolean rc = tableConfiguration.isSelectByPrimaryKeyStatementEnabled()
-            && introspectedTable.hasPrimaryKeyColumns()
-            && (introspectedTable.hasBaseColumns()
-                    || introspectedTable.hasBLOBColumns());
-        
-        return rc;
-    }
+    boolean generateSelectByPrimaryKey();
     
     /**
      * Implements the rule for generating the select by example without BLOBs
@@ -232,9 +147,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateSelectByExampleWithoutBLOBs() {
-        return tableConfiguration.isSelectByExampleStatementEnabled();
-    }
+    boolean generateSelectByExampleWithoutBLOBs();
     
     /**
      * Implements the rule for generating the select by example with BLOBs SQL
@@ -244,12 +157,7 @@
      * 
      * @return true if the element and method should be generated
      */
-    public boolean generateSelectByExampleWithBLOBs() {
-        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
-            && introspectedTable.hasBLOBColumns();
-        
-        return rc;
-    }
+    boolean generateSelectByExampleWithBLOBs();
 
     /**
      * Implements the rule for generating an example class.
@@ -258,41 +166,15 @@
      * 
      * @return true if the example class should be generated
      */
-    public boolean generateExampleClass() {
-        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
-                || tableConfiguration.isDeleteByExampleStatementEnabled()
-                || tableConfiguration.isCountByExampleStatementEnabled()
-                || tableConfiguration.isUpdateByExampleStatementEnabled();
-    
-        return rc;
-    }
-    
-    public boolean generateCountByExample() {
-        boolean rc = tableConfiguration.isCountByExampleStatementEnabled();
-
-        return rc;
-    }
-
-    public boolean generateUpdateByExampleSelective() {
-        boolean rc = tableConfiguration.isUpdateByExampleStatementEnabled();
-
-        return rc;
-    }
-
-    public boolean generateUpdateByExampleWithoutBLOBs() {
-        boolean rc = tableConfiguration.isUpdateByExampleStatementEnabled()
-            && (introspectedTable.hasPrimaryKeyColumns()
-            || introspectedTable.hasBaseColumns());
-        
-        return rc;
-    }
-    
-    public boolean generateUpdateByExampleWithBLOBs() {
-        boolean rc = tableConfiguration.isUpdateByExampleStatementEnabled()
-            && introspectedTable.hasBLOBColumns();
+    boolean generateExampleClass();
     
-        return rc;
-    }
+    boolean generateCountByExample();
+
+    boolean generateUpdateByExampleSelective();
+
+    boolean generateUpdateByExampleWithoutBLOBs();
+    
+    boolean generateUpdateByExampleWithBLOBs();
     
     /**
      * Implements the rule for determining whether to generate a primary key
@@ -300,16 +182,16 @@
      * primary key columns, then the primary key columns will be
      * added to the base class.
      * 
-     * @return true if a seperate primary key class should be generated
+     * @return true if a separate primary key class should be generated
      */
-    public abstract boolean generatePrimaryKeyClass();
+    boolean generatePrimaryKeyClass();
 
     /**
      * Implements the rule for generating a base record.
      * 
      * @return true if the class should be generated
      */
-    public abstract boolean generateBaseRecordClass();
+    boolean generateBaseRecordClass();
 
     /**
      * Implements the rule for generating a record with BLOBs.  If you 
@@ -318,5 +200,7 @@
      * 
      * @return true if the record with BLOBs class should be generated
      */
-    public abstract boolean generateRecordWithBLOBsClass();
+    boolean generateRecordWithBLOBsClass();
+    
+    IntrospectedTable getIntrospectedTable();
 }

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRulesDelegate.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRulesDelegate.java?rev=729795&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRulesDelegate.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/rules/IbatorRulesDelegate.java Sun Dec 28 14:29:10 2008
@@ -0,0 +1,157 @@
+/*
+ *  Copyright 2008 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.ibatis.ibator.internal.rules;
+
+import org.apache.ibatis.ibator.api.IntrospectedTable;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+
+/**
+ * This class can be used by plugins to easily implement a custom
+ * rules implementation.  Plugins should respect the rules implementation
+ * calculated by Ibator, as well as implementations from other plugins.
+ * In general, if something is disabled by the default rules or is
+ * disabled by some other plugin, it should not be re-enabled.
+ * Therefore, the following pattern of use is recommended:
+ * <pre>
+ * public class MyPlugin extends IbatorPluginAdapter {
+ *   &#64;Override
+ *   public void initialized(IntrospectedTable introspectedTable) {
+ *     MyRules myRules = new MyRules(introspectedTable.getRules());
+ *     introspectedTable.setRules(myRules);
+ *   }
+ * }
+ * 
+ * public class MyRules extends IbatorRulesDelegate (
+ *   public IbatorRulesDelegate(IbatorRules ibatorRules) {
+ *     super(ibatorRules);
+ *   }
+ *   
+ *   &#64;Override
+ *   public boolean generateInsert() {
+ *     boolean rc = super.generateInsert();
+ *     if (rc) {
+ *       // other plugins and the default rules enable generation
+ *       // we can decide to disable here.
+ *     }
+ *     
+ *     return rc;
+ *   }
+ * </pre>
+ *     
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class IbatorRulesDelegate implements IbatorRules {
+    protected IbatorRules ibatorRules;
+    
+    public IbatorRulesDelegate(IbatorRules ibatorRules) {
+        this.ibatorRules = ibatorRules;
+    }
+
+    public FullyQualifiedJavaType calculateAllFieldsClass() {
+        return ibatorRules.calculateAllFieldsClass();
+    }
+
+    public boolean generateBaseRecordClass() {
+        return ibatorRules.generateBaseRecordClass();
+    }
+
+    public boolean generateBaseResultMap() {
+        return ibatorRules.generateBaseResultMap();
+    }
+
+    public boolean generateCountByExample() {
+        return ibatorRules.generateCountByExample();
+    }
+
+    public boolean generateDeleteByExample() {
+        return ibatorRules.generateDeleteByExample();
+    }
+
+    public boolean generateDeleteByPrimaryKey() {
+        return ibatorRules.generateDeleteByPrimaryKey();
+    }
+
+    public boolean generateExampleClass() {
+        return ibatorRules.generateExampleClass();
+    }
+
+    public boolean generateInsert() {
+        return ibatorRules.generateInsert();
+    }
+
+    public boolean generateInsertSelective() {
+        return ibatorRules.generateInsertSelective();
+    }
+
+    public boolean generatePrimaryKeyClass() {
+        return ibatorRules.generatePrimaryKeyClass();
+    }
+
+    public boolean generateRecordWithBLOBsClass() {
+        return ibatorRules.generateRecordWithBLOBsClass();
+    }
+
+    public boolean generateResultMapWithBLOBs() {
+        return ibatorRules.generateResultMapWithBLOBs();
+    }
+
+    public boolean generateSelectByExampleWithBLOBs() {
+        return ibatorRules.generateSelectByExampleWithBLOBs();
+    }
+
+    public boolean generateSelectByExampleWithoutBLOBs() {
+        return ibatorRules.generateSelectByExampleWithoutBLOBs();
+    }
+
+    public boolean generateSelectByPrimaryKey() {
+        return ibatorRules.generateSelectByPrimaryKey();
+    }
+
+    public boolean generateSQLExampleWhereClause() {
+        return ibatorRules.generateSQLExampleWhereClause();
+    }
+
+    public boolean generateUpdateByExampleSelective() {
+        return ibatorRules.generateUpdateByExampleSelective();
+    }
+
+    public boolean generateUpdateByExampleWithBLOBs() {
+        return ibatorRules.generateUpdateByExampleWithBLOBs();
+    }
+
+    public boolean generateUpdateByExampleWithoutBLOBs() {
+        return ibatorRules.generateUpdateByExampleWithoutBLOBs();
+    }
+
+    public boolean generateUpdateByPrimaryKeySelective() {
+        return ibatorRules.generateUpdateByPrimaryKeySelective();
+    }
+
+    public boolean generateUpdateByPrimaryKeyWithBLOBs() {
+        return ibatorRules.generateUpdateByPrimaryKeyWithBLOBs();
+    }
+
+    public boolean generateUpdateByPrimaryKeyWithoutBLOBs() {
+        return ibatorRules.generateUpdateByPrimaryKeyWithoutBLOBs();
+    }
+
+    public IntrospectedTable getIntrospectedTable() {
+        return ibatorRules.getIntrospectedTable();
+    }
+}