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 2006/08/05 07:19:15 UTC

svn commit: r428963 [2/3] - in /ibatis/trunk/java/mapper/mapper2/tools/abator/core: htmldoc/ htmldoc/reference/ src/org/apache/ibatis/abator/api/ src/org/apache/ibatis/abator/config/ src/org/apache/ibatis/abator/config/xml/ src/org/apache/ibatis/abator...

Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/BaseLegacyDAOGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/BaseLegacyDAOGenerator.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/BaseLegacyDAOGenerator.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/BaseLegacyDAOGenerator.java Fri Aug  4 22:19:13 2006
@@ -0,0 +1,400 @@
+/*
+ *  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.abator.internal.java.dao;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.ibatis.abator.api.DAOGenerator;
+import org.apache.ibatis.abator.api.FullyQualifiedTable;
+import org.apache.ibatis.abator.api.IntrospectedTable;
+import org.apache.ibatis.abator.api.dom.java.CompilationUnit;
+import org.apache.ibatis.abator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.abator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.abator.api.dom.java.Method;
+import org.apache.ibatis.abator.api.dom.java.Parameter;
+import org.apache.ibatis.abator.internal.db.ColumnDefinition;
+import org.apache.ibatis.abator.internal.sqlmap.ExampleClause;
+import org.apache.ibatis.abator.internal.util.JavaBeansUtil;
+
+/**
+ * This class overrides the base DAO generator class to provide the legacy
+ * implementarion of the "by example" methods.
+ * 
+ * This class can be removed when we remove the Legacy generator set.
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class BaseLegacyDAOGenerator extends BaseDAOGenerator implements DAOGenerator {
+
+    /**
+     * 
+     */
+    public BaseLegacyDAOGenerator(AbstractDAOTemplate daoTemplate) {
+        super(daoTemplate, false);
+    }
+
+    protected List getSelectByExampleWithoutBLOBsMethods(
+            IntrospectedTable introspectedTable,
+            boolean interfaceMethod,
+            CompilationUnit compilationUnit) {
+
+        if (interfaceMethod && exampleMethodVisibility != JavaVisibility.PUBLIC) {
+            return null;
+        }
+
+        FullyQualifiedTable table = introspectedTable.getTable();
+        FullyQualifiedJavaType type = javaModelGenerator.getExampleType(table);
+        compilationUnit.addImportedType(type);
+        compilationUnit.addImportedType(FullyQualifiedJavaType.getNewListInstance());
+
+        Method method1 = new Method();
+        method1.addComment(table);
+        method1.setVisibility(exampleMethodVisibility);
+        method1.setReturnType(FullyQualifiedJavaType.getNewListInstance());
+        method1.setName("selectByExample"); //$NON-NLS-1$
+        method1.addParameter(new Parameter(type, "example")); //$NON-NLS-1$
+        method1.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(),
+                "orderByClause")); //$NON-NLS-1$
+        
+        Method method2 = new Method();
+        method2.addComment(table);
+        method2.setVisibility(JavaVisibility.PUBLIC);
+        method2.setReturnType(FullyQualifiedJavaType.getNewListInstance());
+        method2.setName("selectByExample"); //$NON-NLS-1$
+        method2.addParameter(new Parameter(type, "example")); //$NON-NLS-1$
+        
+        Iterator iter = daoTemplate.getCheckedExceptions().iterator();
+        while (iter.hasNext()) {
+            FullyQualifiedJavaType fqjt = (FullyQualifiedJavaType) iter.next();
+            method1.addException(fqjt);
+            method2.addException(fqjt);
+            compilationUnit.addImportedType(fqjt);
+        }
+
+        if (!interfaceMethod) {
+            // generate the implementation method
+            compilationUnit.addImportedType(FullyQualifiedJavaType.getNewMapInstance());
+            
+            StringBuffer sb = new StringBuffer();
+
+            method1.addBodyLine("Map parms = getExampleParms(example);"); //$NON-NLS-1$
+            method1.addBodyLine("if (orderByClause != null) {"); //$NON-NLS-1$
+            method1.addBodyLine("parms.put(\"ABATOR_ORDER_BY_CLAUSE\", orderByClause);"); //$NON-NLS-1$
+            method1.addBodyLine("}"); //$NON-NLS-1$
+
+            sb.append("List list = "); //$NON-NLS-1$
+            sb.append(daoTemplate.getQueryForListMethod(sqlMapGenerator.getSqlMapNamespace(table),
+                    sqlMapGenerator.getSelectByExampleStatementId(),
+                    "parms")); //$NON-NLS-1$
+            method1.addBodyLine(sb.toString());
+            method1.addBodyLine("return list;"); //$NON-NLS-1$
+
+            method2.addBodyLine("return selectByExample(example, null);"); //$NON-NLS-1$
+        }
+
+        ArrayList answer = new ArrayList();
+        answer.add(method1);
+        answer.add(method2);
+
+        return answer;
+    }
+
+    protected List getSelectByExampleWithBLOBsMethods(
+            IntrospectedTable introspectedTable,
+            boolean interfaceMethod,
+            CompilationUnit compilationUnit) {
+
+        if (interfaceMethod && exampleMethodVisibility != JavaVisibility.PUBLIC) {
+            return null;
+        }
+        
+        FullyQualifiedTable table = introspectedTable.getTable();
+        FullyQualifiedJavaType type = javaModelGenerator.getExampleType(table);
+        compilationUnit.addImportedType(type);
+        compilationUnit.addImportedType(FullyQualifiedJavaType.getNewListInstance());
+
+        Method method1 = new Method();
+        method1.addComment(table);
+        method1.setVisibility(exampleMethodVisibility);
+        method1.setReturnType(FullyQualifiedJavaType.getNewListInstance());
+        method1.setName("selectByExampleWithBLOBs"); //$NON-NLS-1$
+        method1.addParameter(new Parameter(type, "example")); //$NON-NLS-1$
+        method1.addParameter(new Parameter(FullyQualifiedJavaType.getStringInstance(),
+                "orderByClause")); //$NON-NLS-1$
+        
+        Method method2 = new Method();
+        method2.addComment(table);
+        method2.setVisibility(JavaVisibility.PUBLIC);
+        method2.setReturnType(FullyQualifiedJavaType.getNewListInstance());
+        method2.setName("selectByExampleWithBLOBs"); //$NON-NLS-1$
+        method2.addParameter(new Parameter(type, "example")); //$NON-NLS-1$
+
+        Iterator iter = daoTemplate.getCheckedExceptions().iterator();
+        while (iter.hasNext()) {
+            FullyQualifiedJavaType fqjt = (FullyQualifiedJavaType) iter.next();
+            method1.addException(fqjt);
+            method2.addException(fqjt);
+            compilationUnit.addImportedType(fqjt);
+        }
+
+        if (!interfaceMethod) {
+            // generate the implementation method
+            compilationUnit.addImportedType(FullyQualifiedJavaType.getNewMapInstance());
+
+            StringBuffer sb = new StringBuffer();
+
+            method1.addBodyLine("Map parms = getExampleParms(example);"); //$NON-NLS-1$
+            method1.addBodyLine("if (orderByClause != null) {"); //$NON-NLS-1$
+            method1.addBodyLine("parms.put(\"ABATOR_ORDER_BY_CLAUSE\", orderByClause);"); //$NON-NLS-1$
+            method1.addBodyLine("}"); //$NON-NLS-1$
+
+            sb.append("List list = "); //$NON-NLS-1$
+            sb.append(daoTemplate.getQueryForListMethod(sqlMapGenerator.getSqlMapNamespace(table),
+                    sqlMapGenerator.getSelectByExampleWithBLOBsStatementId(),
+                    "parms")); //$NON-NLS-1$
+            method1.addBodyLine(sb.toString());
+            method1.addBodyLine("return list;"); //$NON-NLS-1$
+
+            method2.addBodyLine("return selectByExampleWithBLOBs(example, null);"); //$NON-NLS-1$
+        }
+
+        ArrayList answer = new ArrayList();
+        answer.add(method1);
+        answer.add(method2);
+
+        return answer;
+    }
+
+    protected List getDeleteByExampleMethods(
+            IntrospectedTable introspectedTable,
+            boolean interfaceMethod,
+            CompilationUnit compilationUnit) {
+
+        if (interfaceMethod && exampleMethodVisibility != JavaVisibility.PUBLIC) {
+            return null;
+        }
+        
+        FullyQualifiedTable table = introspectedTable.getTable();
+        FullyQualifiedJavaType type = javaModelGenerator.getExampleType(table);
+        compilationUnit.addImportedType(type);
+
+        Method method = new Method();
+        method.addComment(table);
+        method.setVisibility(exampleMethodVisibility);
+        method.setReturnType(FullyQualifiedJavaType.getIntInstance());
+        method.setName(methodNameCalculator.getDeleteByExampleMethodName(introspectedTable));
+        method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$
+        
+        Iterator iter = daoTemplate.getCheckedExceptions().iterator();
+        while (iter.hasNext()) {
+            FullyQualifiedJavaType fqjt = (FullyQualifiedJavaType) iter.next();
+            method.addException(fqjt);
+            compilationUnit.addImportedType(fqjt);
+        }
+
+        if (!interfaceMethod) {
+            // generate the implementation method
+            StringBuffer sb = new StringBuffer();
+
+            sb.append("int rows = "); //$NON-NLS-1$
+            sb.append(daoTemplate.getDeleteMethod(sqlMapGenerator.getSqlMapNamespace(table),
+                    sqlMapGenerator.getDeleteByExampleStatementId(),
+                    "getExampleParms(example)")); //$NON-NLS-1$
+            method.addBodyLine(sb.toString());
+            
+            method.addBodyLine("return rows;"); //$NON-NLS-1$
+        }
+
+        ArrayList answer = new ArrayList();
+        answer.add(method);
+
+        return answer;
+    }
+
+    protected List getExtraImplementationMethods(
+            IntrospectedTable introspectedTable,
+            CompilationUnit compilationUnit) {
+
+        if (!introspectedTable.getRules().generateExampleClass()) {
+            return null;
+        }
+
+        ArrayList answer = new ArrayList();
+
+        FullyQualifiedTable table = introspectedTable.getTable();
+        FullyQualifiedJavaType type = javaModelGenerator.getExampleType(table);
+        
+        compilationUnit.addImportedType(FullyQualifiedJavaType.getNewMapInstance());
+        compilationUnit.addImportedType(FullyQualifiedJavaType.getNewHashMapInstance());
+        compilationUnit.addImportedType(type);
+
+        Method method = new Method();
+        method.addComment(table);
+        method.setVisibility(JavaVisibility.PRIVATE);
+        method.setReturnType(FullyQualifiedJavaType.getNewMapInstance());
+        method.setName("getExampleParms"); //$NON-NLS-1$
+        method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$
+        
+        method.addBodyLine("Map parms = new HashMap();"); //$NON-NLS-1$
+
+        Iterator iter = introspectedTable.getNonBLOBColumns();
+        while (iter.hasNext()) {
+            ColumnDefinition cd = (ColumnDefinition) iter.next();
+            StringBuffer sb = new StringBuffer();
+
+            Method method1 = getExampleParmsMethod(cd, table);
+            if (method1 != null) {
+                answer.add(method1);
+
+                sb.setLength(0);
+                sb.append("parms.putAll("); //$NON-NLS-1$
+                sb.append(method1.getName());
+                sb.append("(example));"); //$NON-NLS-1$
+                method.addBodyLine(sb.toString());
+            }
+        }
+
+        method.addBodyLine("return parms;"); //$NON-NLS-1$
+
+        answer.add(method);
+
+        return answer;
+    }
+
+    /**
+     * This method returns a properly formatted method that sets up example
+     * parms for an individual column. In the generated DAO, the method will be
+     * called by the <code>getExampleParms</code> method. The expectation is
+     * that there will be one column based method for each column in the table
+     * (except BLOB columns). We do it this way to avoid generating one huge
+     * method - which in some cases can actually be too large to compile. The
+     * generated method should have this signature:
+     * 
+     * <pre>
+     * 
+     *     private Map getXXXXExampleParms(YYYY example)
+     *  
+     * </pre>
+     * 
+     * Where XXXX is the column name and YYYY is the example class
+     * 
+     * @param cd
+     *            the column for which the method should be generated
+     * @param table
+     *            the table in which the column exists
+     * @return the method
+     */
+    private Method getExampleParmsMethod(ColumnDefinition cd,
+            FullyQualifiedTable table) {
+        
+        StringBuffer sb = new StringBuffer();
+
+        Method method = new Method();
+        method.addComment(table);
+        method.setVisibility(JavaVisibility.PRIVATE);
+        method.setReturnType(FullyQualifiedJavaType.getNewMapInstance());
+        sb.append("get"); //$NON-NLS-1$
+        sb.append(cd.getColumnName());
+        sb.append("ExampleParms"); //$NON-NLS-1$
+        method.setName(sb.toString());
+
+        method.addParameter(new Parameter(javaModelGenerator.getExampleType(table),
+                "example")); //$NON-NLS-1$
+
+        method.addBodyLine("Map parms = new HashMap();"); //$NON-NLS-1$
+
+        sb.setLength(0);
+        sb.append("switch (example."); //$NON-NLS-1$
+        String property = cd.getJavaProperty() + "_Indicator"; //$NON-NLS-1$
+        sb.append(JavaBeansUtil.getGetterMethodName(property));
+        sb.append("()) {"); //$NON-NLS-1$
+        method.addBodyLine(sb.toString());
+
+        Iterator clauseIterator = ExampleClause.getAllExampleClauses();
+        while (clauseIterator.hasNext()) {
+            ExampleClause clause = (ExampleClause) clauseIterator.next();
+
+            if (clause.isCharacterOnly() && !cd.isCharacterColumn()) {
+                continue;
+            }
+
+            sb.setLength(0);
+            sb.append("case "); //$NON-NLS-1$
+            sb.append(javaModelGenerator.getExampleType(table)
+                    .getShortName());
+            sb.append('.');
+            sb.append(clause.getExamplePropertyName());
+            sb.append(':');
+            method.addBodyLine(sb.toString());
+            
+            method.addBodyLine("if (example.isCombineTypeOr()) {"); //$NON-NLS-1$
+
+            sb.setLength(0);
+            sb.append("parms.put(\""); //$NON-NLS-1$
+            sb.append(clause.getSelectorOrProperty(cd));
+            sb.append("\", \"Y\");"); //$NON-NLS-1$
+            method.addBodyLine(sb.toString());
+
+            method.addBodyLine("} else {"); //$NON-NLS-1$
+
+            sb.setLength(0);
+            sb.append("parms.put(\""); //$NON-NLS-1$
+            sb.append(clause.getSelectorAndProperty(cd));
+            sb.append("\", \"Y\");"); //$NON-NLS-1$
+            method.addBodyLine(sb.toString());
+
+            method.addBodyLine("}"); //$NON-NLS-1$
+
+            if (clause.isPropertyInMapRequired()) {
+                String exampleProperty = cd.getJavaProperty();
+                
+                sb.setLength(0);
+                sb.append("parms.put(\""); //$NON-NLS-1$
+                sb.append(exampleProperty);
+                sb.append("\", "); //$NON-NLS-1$
+                FullyQualifiedJavaType fqjt = cd.getResolvedJavaType()
+                        .getFullyQualifiedJavaType();
+                if (fqjt.isPrimitive()) {
+                    sb.append("new "); //$NON-NLS-1$
+                    sb.append(fqjt.getPrimitiveTypeWrapper().getShortName());
+                    sb.append('(');
+                    sb.append("example."); //$NON-NLS-1$
+                    sb.append(JavaBeansUtil
+                            .getGetterMethodName(exampleProperty));
+                    sb.append("()));"); //$NON-NLS-1$
+                } else {
+                    sb.append("example."); //$NON-NLS-1$
+                    sb.append(JavaBeansUtil
+                            .getGetterMethodName(exampleProperty));
+                    sb.append("());"); //$NON-NLS-1$
+                }
+                method.addBodyLine(sb.toString());
+            }
+
+            method.addBodyLine("break;"); //$NON-NLS-1$
+        }
+
+        method.addBodyLine("}"); //$NON-NLS-1$
+
+        method.addBodyLine("return parms;"); //$NON-NLS-1$
+
+        return method;
+    }
+}

Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/GenericCILegacyDAOGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/GenericCILegacyDAOGenerator.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/GenericCILegacyDAOGenerator.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/GenericCILegacyDAOGenerator.java Fri Aug  4 22:19:13 2006
@@ -0,0 +1,33 @@
+/*
+ *  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.abator.internal.java.dao;
+
+/**
+ * This class generates DAO classes that are generic and utilize sql maps
+ * directly. The pattern is constructor injection.
+ * 
+ * @author Jeff Butler
+ */
+public class GenericCILegacyDAOGenerator extends BaseLegacyDAOGenerator {
+
+    /**
+     * 
+     */
+    public GenericCILegacyDAOGenerator() {
+        super(new GenericCIDAOTemplate());
+    }
+}

Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/GenericSILegacyDAOGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/GenericSILegacyDAOGenerator.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/GenericSILegacyDAOGenerator.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/GenericSILegacyDAOGenerator.java Fri Aug  4 22:19:13 2006
@@ -0,0 +1,33 @@
+/*
+ *  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.abator.internal.java.dao;
+
+/**
+ * This class generates DAO classes that are generic and utilize sql maps
+ * directly. The pattern is setter injection.
+ * 
+ * @author Jeff Butler
+ */
+public class GenericSILegacyDAOGenerator extends BaseLegacyDAOGenerator {
+
+    /**
+     * 
+     */
+    public GenericSILegacyDAOGenerator() {
+        super(new GenericSIDAOTemplate());
+    }
+}

Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/IbatisLegacyDAOGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/IbatisLegacyDAOGenerator.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/IbatisLegacyDAOGenerator.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/IbatisLegacyDAOGenerator.java Fri Aug  4 22:19:13 2006
@@ -0,0 +1,32 @@
+/*
+ *  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.abator.internal.java.dao;
+
+/**
+ * This class generates DAO classes based on the iBATIS DAO framework.
+ * 
+ * @author Jeff Butler
+ */
+public class IbatisLegacyDAOGenerator extends BaseLegacyDAOGenerator {
+
+    /**
+     * 
+     */
+    public IbatisLegacyDAOGenerator() {
+        super(new IbatisDAOTemplate());
+    }
+}

Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/SpringLegacyDAOGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/SpringLegacyDAOGenerator.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/SpringLegacyDAOGenerator.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/dao/SpringLegacyDAOGenerator.java Fri Aug  4 22:19:13 2006
@@ -0,0 +1,32 @@
+/*
+ *  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.abator.internal.java.dao;
+
+/**
+ * This class generates DAO classes based on the Spring framework.
+ * 
+ * @author Jeff Butler
+ */
+public class SpringLegacyDAOGenerator extends BaseLegacyDAOGenerator {
+
+    /**
+     * 
+     */
+    public SpringLegacyDAOGenerator() {
+        super(new SpringDAOTemplate());
+    }
+}

Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorJava2Impl.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorJava2Impl.java?rev=428963&r1=428962&r2=428963&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorJava2Impl.java (original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorJava2Impl.java Fri Aug  4 22:19:13 2006
@@ -35,7 +35,6 @@
 import org.apache.ibatis.abator.api.dom.java.Parameter;
 import org.apache.ibatis.abator.api.dom.java.TopLevelClass;
 import org.apache.ibatis.abator.internal.db.ColumnDefinition;
-import org.apache.ibatis.abator.internal.rules.AbatorRules;
 import org.apache.ibatis.abator.internal.util.JavaBeansUtil;
 import org.apache.ibatis.abator.internal.util.StringUtility;
 import org.apache.ibatis.abator.internal.util.messages.Messages;
@@ -245,7 +244,7 @@
 
     protected CompilationUnit getPrimaryKey(IntrospectedTable introspectedTable) {
 
-        if (!AbatorRules.generatePrimaryKey(introspectedTable)) {
+        if (!introspectedTable.getRules().generatePrimaryKeyClass()) {
             return null;
         }
 
@@ -254,55 +253,56 @@
         TopLevelClass answer = new TopLevelClass(type);
         answer.setVisibility(JavaVisibility.PUBLIC);
 
-        if (properties.containsKey("rootClass")) { //$NON-NLS-1$
-            FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(
-                    (String) properties.get("rootClass")); //$NON-NLS-1$
-
-            answer.setSuperClass(fqjt);
-            answer.addImportedType(fqjt);
+        String rootClass = (String) properties.get("rootClass"); //$NON-NLS-1$
+        if (rootClass != null) {
+            answer.setSuperClass(new FullyQualifiedJavaType(rootClass));
+            answer.addImportedType(answer.getSuperClass());
         }
-
+        
         generateClassParts(table, introspectedTable.getPrimaryKeyColumns(), answer);
 
         return answer;
     }
 
-    protected CompilationUnit getRecord(IntrospectedTable introspectedTable) {
+    protected CompilationUnit getBaseRecord(IntrospectedTable introspectedTable) {
 
-        if (!AbatorRules.generateBaseRecordWithNoSuperclass(introspectedTable)
-                && !AbatorRules
-                        .generateBaseRecordExtendingPrimaryKey(introspectedTable)) {
+        if (!introspectedTable.getRules().generateBaseRecordClass()) {
             return null;
         }
 
         FullyQualifiedTable table = introspectedTable.getTable();
-        FullyQualifiedJavaType type = getRecordType(table);
+        FullyQualifiedJavaType type = getBaseRecordType(table);
         TopLevelClass answer = new TopLevelClass(type);
         answer.setVisibility(JavaVisibility.PUBLIC);
-
-        if (AbatorRules
-                .generateBaseRecordExtendingPrimaryKey(introspectedTable)) {
+        
+        if (introspectedTable.getRules().generatePrimaryKeyClass()) {
             answer.setSuperClass(getPrimaryKeyType(table));
         } else {
-            if (properties.containsKey("rootClass")) { //$NON-NLS-1$
-                FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(
-                        (String) properties.get("rootClass")); //$NON-NLS-1$
-                answer.setSuperClass(fqjt);
-                answer.addImportedType(fqjt);
+            String rootClass = (String) properties.get("rootClass"); //$NON-NLS-1$
+            if (rootClass != null) {
+                answer.setSuperClass(new FullyQualifiedJavaType(rootClass));
+                answer.addImportedType(answer.getSuperClass());
             }
         }
+        
+        if (!introspectedTable.getRules().generatePrimaryKeyClass()
+                && introspectedTable.hasPrimaryKeyColumns()) {
+            generateClassParts(table, introspectedTable.getPrimaryKeyColumns(), answer);
+        }
 
-        generateClassParts(table, introspectedTable.getNonBLOBColumns(), answer);
+        generateClassParts(table, introspectedTable.getBaseColumns(), answer);
 
+        if (!introspectedTable.getRules().generateRecordWithBLOBsClass()
+                && introspectedTable.hasBLOBColumns()) {
+            generateClassParts(table, introspectedTable.getBLOBColumns(), answer);
+        }
+        
         return answer;
     }
 
     protected CompilationUnit getRecordWithBLOBs(IntrospectedTable introspectedTable) {
 
-        if (!AbatorRules
-                .generateRecordWithBLOBsExtendingPrimaryKey(introspectedTable)
-                && !AbatorRules
-                        .generateRecordWithBLOBsExtendingBaseRecord(introspectedTable)) {
+        if (!introspectedTable.getRules().generateRecordWithBLOBsClass()) {
             return null;
         }
 
@@ -310,14 +310,13 @@
         FullyQualifiedJavaType type = getRecordWithBLOBsType(table);
         TopLevelClass answer = new TopLevelClass(type);
         answer.setVisibility(JavaVisibility.PUBLIC);
-
-        if (AbatorRules
-                .generateRecordWithBLOBsExtendingPrimaryKey(introspectedTable)) {
-            answer.setSuperClass(getPrimaryKeyType(table));
+        
+        if (introspectedTable.getRules().generateBaseRecordClass()) {
+            answer.setSuperClass(getBaseRecordType(table));
         } else {
-            answer.setSuperClass(getRecordType(table));
+            answer.setSuperClass(getPrimaryKeyType(table));
         }
-
+        
         generateClassParts(table, introspectedTable.getBLOBColumns(), answer);
 
         return answer;
@@ -352,11 +351,8 @@
     }
 
     /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.ibatis.abator.api.JavaModelGenerator#getGeneratedJavaFiles(org.apache.ibatis.abator.internal.db.ColumnDefinitions,
-     *      org.apache.ibatis.abator.config.TableConfiguration,
-     *      org.apache.ibatis.abator.api.ProgressCallback)
+     *  (non-Javadoc)
+     * @see org.apache.ibatis.abator.api.JavaModelGenerator#getGeneratedJavaFiles(org.apache.ibatis.abator.api.IntrospectedTable, org.apache.ibatis.abator.api.ProgressCallback)
      */
     public List getGeneratedJavaFiles(IntrospectedTable introspectedTable, ProgressCallback callback) {
         List list = new ArrayList();
@@ -385,7 +381,7 @@
         callback.startSubTask(Messages.getString(
                 "Progress.8", //$NON-NLS-1$
                 tableName));
-        cu = getRecord(introspectedTable);
+        cu = getBaseRecord(introspectedTable);
         if (cu != null) {
             GeneratedJavaFile gjf = new GeneratedJavaFile(cu, targetProject);
             list.add(gjf);
@@ -432,7 +428,7 @@
      * 
      * @see org.apache.ibatis.abator.api.JavaModelGenerator#getRecordType(org.apache.ibatis.abator.config.FullyQualifiedTable)
      */
-    public FullyQualifiedJavaType getRecordType(FullyQualifiedTable table) {
+    public FullyQualifiedJavaType getBaseRecordType(FullyQualifiedTable table) {
         String key = "getRecordType"; //$NON-NLS-1$
 
         Map map = getTableValueMap(table);
@@ -640,8 +636,8 @@
         return method;
     }
 
-    protected CompilationUnit getExample(IntrospectedTable introspectedTable) {
-        if (!AbatorRules.generateExample(introspectedTable)) {
+    protected TopLevelClass getExample(IntrospectedTable introspectedTable) {
+        if (!introspectedTable.getRules().generateExampleClass()) {
             return null;
         }
 
@@ -750,12 +746,9 @@
                 .addBodyLine("criteriaWithBetweenValue = new ArrayList();"); //$NON-NLS-1$
         answer.addMethod(method);
 
-        Iterator iter = introspectedTable.getAllColumns();
+        Iterator iter = introspectedTable.getNonBLOBColumns();
         while (iter.hasNext()) {
             ColumnDefinition cd = (ColumnDefinition) iter.next();
-            if (cd.isBLOBColumn()) {
-                continue;
-            }
             
             if (StringUtility.stringHasValue(cd.getTypeHandler())) {
                 addtypeHandledObjectsAndMethods(cd, method, answer);
@@ -1023,14 +1016,10 @@
             answer.addMethod(method);
         }
 
-        iter = introspectedTable.getAllColumns();
+        iter = introspectedTable.getNonBLOBColumns();
         while (iter.hasNext()) {
             ColumnDefinition cd = (ColumnDefinition) iter.next();
 
-            if (cd.isBLOBColumn()) {
-                continue;
-            }
-
             topLevelClass.addImportedType(cd.getResolvedJavaType()
                     .getFullyQualifiedJavaType());
 
@@ -1300,5 +1289,9 @@
         sb.append("CriteriaWithBetweenValue.add(map);"); //$NON-NLS-1$
         method.addBodyLine(sb.toString());
         innerClass.addMethod(method);
+    }
+
+    public String getProperty(String property) {
+        return (String) properties.get(property);
     }
 }

Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorJava5Impl.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorJava5Impl.java?rev=428963&r1=428962&r2=428963&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorJava5Impl.java (original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorJava5Impl.java Fri Aug  4 22:19:13 2006
@@ -19,7 +19,6 @@
 
 import org.apache.ibatis.abator.api.FullyQualifiedTable;
 import org.apache.ibatis.abator.api.IntrospectedTable;
-import org.apache.ibatis.abator.api.dom.java.CompilationUnit;
 import org.apache.ibatis.abator.api.dom.java.Field;
 import org.apache.ibatis.abator.api.dom.java.FullyQualifiedJavaType;
 import org.apache.ibatis.abator.api.dom.java.InnerClass;
@@ -29,7 +28,6 @@
 import org.apache.ibatis.abator.api.dom.java.Parameter;
 import org.apache.ibatis.abator.api.dom.java.TopLevelClass;
 import org.apache.ibatis.abator.internal.db.ColumnDefinition;
-import org.apache.ibatis.abator.internal.rules.AbatorRules;
 import org.apache.ibatis.abator.internal.util.JavaBeansUtil;
 import org.apache.ibatis.abator.internal.util.StringUtility;
 
@@ -45,8 +43,8 @@
         super();
     }
 
-    protected CompilationUnit getExample(IntrospectedTable introspectedTable) {
-        if (!AbatorRules.generateExample(introspectedTable)) {
+    protected TopLevelClass getExample(IntrospectedTable introspectedTable) {
+        if (!introspectedTable.getRules().generateExampleClass()) {
             return null;
         }
 
@@ -156,12 +154,9 @@
                 .addBodyLine("criteriaWithBetweenValue = new ArrayList<Map<String, Object>>();"); //$NON-NLS-1$
         answer.addMethod(method);
 
-        Iterator iter = introspectedTable.getAllColumns();
+        Iterator iter = introspectedTable.getNonBLOBColumns();
         while (iter.hasNext()) {
             ColumnDefinition cd = (ColumnDefinition) iter.next();
-            if (cd.isBLOBColumn()) {
-                continue;
-            }
             
             if (StringUtility.stringHasValue(cd.getTypeHandler())) {
                 addtypeHandledObjectsAndMethods(cd, method, answer);
@@ -442,13 +437,9 @@
             answer.addMethod(method);
         }
 
-        iter = introspectedTable.getAllColumns();
+        iter = introspectedTable.getNonBLOBColumns();
         while (iter.hasNext()) {
             ColumnDefinition cd = (ColumnDefinition) iter.next();
-
-            if (cd.isBLOBColumn()) {
-                continue;
-            }
 
             topLevelClass.addImportedType(cd.getResolvedJavaType()
                     .getFullyQualifiedJavaType());

Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorLegacyImpl.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorLegacyImpl.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorLegacyImpl.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/java/model/JavaModelGeneratorLegacyImpl.java Fri Aug  4 22:19:13 2006
@@ -0,0 +1,162 @@
+/*
+ *  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.abator.internal.java.model;
+
+import java.util.Iterator;
+
+import org.apache.ibatis.abator.api.FullyQualifiedTable;
+import org.apache.ibatis.abator.api.IntrospectedTable;
+import org.apache.ibatis.abator.api.JavaModelGenerator;
+import org.apache.ibatis.abator.api.dom.java.Field;
+import org.apache.ibatis.abator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.abator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.abator.api.dom.java.Method;
+import org.apache.ibatis.abator.api.dom.java.Parameter;
+import org.apache.ibatis.abator.api.dom.java.TopLevelClass;
+import org.apache.ibatis.abator.internal.db.ColumnDefinition;
+import org.apache.ibatis.abator.internal.sqlmap.ExampleClause;
+import org.apache.ibatis.abator.internal.util.JavaBeansUtil;
+
+/**
+ * This class overrides methods in the Java2 implementation to provide the
+ * legacy implementation of the example class.
+ * 
+ * This class can be removed when we remove the Legacy generator set.
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class JavaModelGeneratorLegacyImpl extends JavaModelGeneratorJava2Impl implements JavaModelGenerator {
+
+    /**
+     * 
+     */
+    public JavaModelGeneratorLegacyImpl() {
+        super();
+    }
+
+    protected TopLevelClass getExample(IntrospectedTable introspectedTable) {
+        if (!introspectedTable.getRules().generateExampleClass()) {
+            return null;
+        }
+
+        FullyQualifiedTable table = introspectedTable.getTable();
+        FullyQualifiedJavaType type = getExampleType(table);
+        TopLevelClass topLevelClass = new TopLevelClass(type);
+        topLevelClass.setVisibility(JavaVisibility.PUBLIC);
+        
+        if (introspectedTable.getRules().generateBaseRecordClass()) {
+            topLevelClass.setSuperClass(getBaseRecordType(table));
+        } else {
+            topLevelClass.setSuperClass(getPrimaryKeyType(table));
+        }
+
+        StringBuffer sb = new StringBuffer();
+        Field field = new Field();
+        field.addComment(table);
+        field.setVisibility(JavaVisibility.PUBLIC);
+        field.setModifierStatic(true);
+        field.setModifierFinal(true);
+        field.setType(FullyQualifiedJavaType.getIntInstance());
+        field.setName("EXAMPLE_IGNORE"); //$NON-NLS-1$
+        field.setInitializationString("0"); //$NON-NLS-1$
+        topLevelClass.addField(field);
+
+        Iterator iter = ExampleClause.getAllExampleClauses();
+        while (iter.hasNext()) {
+            ExampleClause clause = (ExampleClause) iter.next();
+            field = new Field();
+            field.addComment(table);
+            field.setVisibility(JavaVisibility.PUBLIC);
+            field.setModifierStatic(true);
+            field.setModifierFinal(true);
+            field.setType(FullyQualifiedJavaType.getIntInstance());
+            field.setName(clause.getExamplePropertyName());
+            field.setInitializationString(Integer.toString(clause
+                    .getExamplePropertyValue()));
+            topLevelClass.addField(field);
+        }
+
+        field = new Field();
+        field.addComment(table);
+        field.setVisibility(JavaVisibility.PRIVATE);
+        field.setType(FullyQualifiedJavaType.getBooleanPrimitiveInstance());
+        field.setName("combineTypeOr"); //$NON-NLS-1$
+        topLevelClass.addField(field);
+
+        Method method = new Method();
+        method.addComment(table);
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setName("setCombineTypeOr"); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getBooleanPrimitiveInstance(), "combineTypeOr")); //$NON-NLS-1$
+        method.addBodyLine("this.combineTypeOr = combineTypeOr;"); //$NON-NLS-1$
+        topLevelClass.addMethod(method);
+
+        method = new Method();
+        method.addComment(table);
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(FullyQualifiedJavaType
+                .getBooleanPrimitiveInstance());
+        method.setName("isCombineTypeOr"); //$NON-NLS-1$
+        method.addBodyLine("return combineTypeOr;"); //$NON-NLS-1$
+        topLevelClass.addMethod(method);
+
+        iter = introspectedTable.getNonBLOBColumns();
+        while (iter.hasNext()) {
+            ColumnDefinition cd = (ColumnDefinition) iter.next();
+
+            String fieldName = cd.getJavaProperty() + "_Indicator"; //$NON-NLS-1$
+
+            field = new Field();
+            field.addComment(table);
+            field.setVisibility(JavaVisibility.PRIVATE);
+            field.setType(FullyQualifiedJavaType.getIntInstance());
+            field.setName(fieldName);
+            topLevelClass.addField(field);
+
+            method = new Method();
+            method.addComment(table);
+            method.setVisibility(JavaVisibility.PUBLIC);
+            method.setReturnType(FullyQualifiedJavaType.getIntInstance());
+            method.setName(JavaBeansUtil.getGetterMethodName(fieldName));
+            sb.setLength(0);
+            sb.append("return "); //$NON-NLS-1$
+            sb.append(fieldName);
+            sb.append(';');
+            method.addBodyLine(sb.toString());
+            topLevelClass.addMethod(method);
+
+            method = new Method();
+            method.addComment(table);
+            method.setVisibility(JavaVisibility.PUBLIC);
+            method.setName(JavaBeansUtil.getSetterMethodName(fieldName));
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getIntInstance(), fieldName));
+            sb.setLength(0);
+            sb.append("this."); //$NON-NLS-1$
+            sb.append(fieldName);
+            sb.append(" = "); //$NON-NLS-1$
+            sb.append(fieldName);
+            sb.append(';');
+            method.addBodyLine(sb.toString());
+            topLevelClass.addMethod(method);
+        }
+
+        return topLevelClass;
+    }
+}

Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/AbatorRules.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/AbatorRules.java?rev=428963&r1=428962&r2=428963&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/AbatorRules.java (original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/AbatorRules.java Fri Aug  4 22:19:13 2006
@@ -15,8 +15,11 @@
  */
 package org.apache.ibatis.abator.internal.rules;
 
-import org.apache.ibatis.abator.api.IntrospectedTable;
-import org.apache.ibatis.abator.api.TableType;
+import org.apache.ibatis.abator.api.FullyQualifiedTable;
+import org.apache.ibatis.abator.api.JavaModelGenerator;
+import org.apache.ibatis.abator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.abator.config.TableConfiguration;
+import org.apache.ibatis.abator.internal.db.ColumnDefinitions;
 
 /**
  * This class centralizes all the rules related to code generation - including
@@ -27,498 +30,240 @@
  * 
  * @author Jeff Butler
  */
-public class AbatorRules {
+public abstract class AbatorRules {
 
-    /**
-     * Utility class - no instances allowed.
-     */
-    private AbatorRules() {
-        super();
-    }
-
-    // start of domain object generation rules
+    protected TableConfiguration tableConfiguration;
+    protected ColumnDefinitions columnDefinitions;
 
     /**
-     * Implements the rule for determining whether to generate a primary key
-     * class. If the physical table has a primary key, then we generate the
-     * class.
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the primary key should be generated
-     */
-    public static boolean generatePrimaryKey(IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.PK_NO_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_NO_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        return rc;
-    }
-
-    /**
-     * Implements the rule for generating a base record that extends the primary
-     * key. If the table has a primary key, and has non-BLOB non-Primary Key
-     * fields, then generate the class.
-     * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the base record class should be generated
-     */
-    public static boolean generateBaseRecordExtendingPrimaryKey(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.PK_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        return rc;
+     */
+    public AbatorRules(TableConfiguration tableConfiguration,
+            ColumnDefinitions columnDefinitions) {
+        super();
+        this.tableConfiguration = tableConfiguration;
+        this.columnDefinitions = columnDefinitions;
     }
 
     /**
-     * Implements the rule for generating a base record with no super class. If
-     * the table does not have a primary key, then generate the class.
+     * 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.
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the base record class should be generated
-     */
-    public static boolean generateBaseRecordWithNoSuperclass(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.NO_PK_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.NO_PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        return rc;
+     * @return true if the element and method should be generated
+     */
+    public boolean generateInsert() {
+        return tableConfiguration.isInsertStatementEnabled();
     }
 
     /**
-     * Implements the rule for generating a record with BLOBs class extending
-     * the primary key class. If the table has a primary key, but all other
-     * fields are BLOBs, then generate the class.
+     * 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.
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the record with BLOBs class should be generated
+     * @param javaModelGenerator
+     * @param table
+     * @return
      */
-    public static boolean generateRecordWithBLOBsExtendingPrimaryKey(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.PK_NO_FIELDS_BLOBS) {
-            rc = true;
+    public FullyQualifiedJavaType calculateAllFieldsClass(JavaModelGenerator javaModelGenerator,
+            FullyQualifiedTable table) {
+        
+        FullyQualifiedJavaType answer;
+        
+        if (generateRecordWithBLOBsClass()) {
+            answer = javaModelGenerator.getRecordWithBLOBsType(table);
+        } else if (generateBaseRecordClass()) {
+            answer = javaModelGenerator.getBaseRecordType(table);
         } else {
-            rc = false;
+            answer = javaModelGenerator.getPrimaryKeyType(table);
         }
-
-        return rc;
+        
+        return answer;
     }
-
+    
     /**
-     * Implements the rule for generating a record with BLOBs class extending
-     * the base record class. If the table has non-BLOB non-Primary Key fields,
-     * then generate the class.
+     * 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.
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the record with BLOBs class should be generated
+     * @return true if the element and method should be generated
      */
-    public static boolean generateRecordWithBLOBsExtendingBaseRecord(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.NO_PK_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
+    public boolean generateUpdateByPrimaryKeyWithoutBLOBs() {
+        boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
+            && columnDefinitions.hasPrimaryKeyColumns()
+            && columnDefinitions.hasBaseColumns();
+        
         return rc;
     }
-
+    
     /**
-     * Implements the rule for generating an example class extending the primary
-     * key. If there is a primary key, and there are no non-Primary Key non-Blob
-     * fields, then generate the class. Also, the class should only be generated
-     * if the selectByExample or deleteByExample methods are allowed. This
-     * method only applies to the "Legacy" generator set.
+     * 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.
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the example class should be generated
+     * @return true if the element and method should be generated
      */
-    public static boolean generateExampleExtendingPrimaryKey(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.PK_NO_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_NO_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        if (rc) {
-            rc = generateExample(introspectedTable);
-        }
-
+    public boolean generateUpdateByPrimaryKeyWithBLOBs() {
+        boolean rc = tableConfiguration.isUpdateByPrimaryKeyStatementEnabled()
+            && columnDefinitions.hasPrimaryKeyColumns()
+            && columnDefinitions.hasBLOBColumns();
+    
         return rc;
     }
 
     /**
-     * Implements the rule for generating an example class extending the base
-     * record. If there are non non-Primary Key non-Blob fields, then generate
-     * the class. Also, the class should only be generated if the
-     * selectByExample or deleteByExample methods are allowed. This method only
-     * applies to the "Legacy" generator set.
+     * 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.
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the example class should be generated
+     * @return true if the element and method should be generated
      */
-    public static boolean generateExampleExtendingBaseRecord(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.NO_PK_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.NO_PK_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        if (rc) {
-            rc = generateExample(introspectedTable);
-        }
+    public boolean generateDeleteByPrimaryKey() {
+        boolean rc = tableConfiguration.isDeleteByPrimaryKeyStatementEnabled()
+            && columnDefinitions.hasPrimaryKeyColumns();
 
         return rc;
     }
-
+    
     /**
-     * Implements the rule for generating an example class with no super class.
-     * The class should only be generated if the
-     * selectByExample or deleteByExample methods are allowed. This method only
-     * applies to the "Java2" and "Java5" generator sets.
+     * 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.
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the example class should be generated
+     * @return true if the element and method should be generated
      */
-    public static boolean generateExample(IntrospectedTable introspectedTable) {
-        boolean rc = introspectedTable.isSelectByExampleStatementEnabled()
-                || introspectedTable.isDeleteByExampleStatementEnabled();
+    public boolean generateDeleteByExample() {
+        boolean rc = tableConfiguration.isDeleteByExampleStatementEnabled();
 
         return rc;
     }
-
-    // end of domain object generation rules
-    // start of SqlMAP and DAO Method rules rules
-
+    
     /**
      * Implements the rule for generating the result map without BLOBs. If
      * either select method is allowed, then generate the result map.
      * 
-     * @param introspectedTable
-     *            the introspected table
      * @return true if the result map should be generated
      */
-    public static boolean generateResultMapWithoutBLOBs(
-            IntrospectedTable introspectedTable) {
-        return introspectedTable.isSelectByExampleStatementEnabled()
-                || introspectedTable.isSelectByPrimaryKeyStatementEnabled();
+    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.
      * 
-     * @param introspectedTable
-     *            the introspected table
      * @return true if the result map should be generated
      */
-    public static boolean generateResultMapWithBLOBs(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.NO_PK_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_NO_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        if (rc) {
-            rc = introspectedTable.isSelectByExampleStatementEnabled()
-                    || introspectedTable.isSelectByPrimaryKeyStatementEnabled();
-        }
-
+    public boolean generateResultMapWithBLOBs() {
+        boolean rc = (tableConfiguration.isSelectByExampleStatementEnabled()
+            || tableConfiguration.isSelectByPrimaryKeyStatementEnabled())
+            && columnDefinitions.hasBLOBColumns();
+    
         return rc;
     }
-
+    
     /**
      * Implements the rule for generating the SQL example where clause element.
      * Generate the element if either the selectByExample or deleteByExample
      * statement is allowed.
      * 
-     * @param introspectedTable
-     *            the introspected table
      * @return true if the SQL where clause element should be generated
      */
-    public static boolean generateSQLExampleWhereClause(
-            IntrospectedTable introspectedTable) {
-        return introspectedTable.isSelectByExampleStatementEnabled()
-                || introspectedTable.isDeleteByExampleStatementEnabled();
-    }
-
-    /**
-     * 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.
-     * 
-     * @param tc
-     *            the table configuration object
-     * @return true if the element and method should be generated
-     */
-    public static boolean generateSelectByExampleWithoutBLOBs(
-            IntrospectedTable introspectedTable) {
-        return introspectedTable.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.
-     * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the element and method should be generated
-     */
-    public static boolean generateSelectByExampleWithBLOBs(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.NO_PK_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_NO_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        if (rc) {
-            rc = introspectedTable.isSelectByExampleStatementEnabled();
-        }
-
+    public boolean generateSQLExampleWhereClause() {
+        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
+            || tableConfiguration.isDeleteByExampleStatementEnabled();
+        
         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.
      * 
-     * @param introspectedTable
-     *            the introspected table
      * @return true if the element and method should be generated
      */
-    public static boolean generateSelectByPrimaryKey(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.PK_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_NO_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        if (rc) {
-            rc = introspectedTable.isSelectByPrimaryKeyStatementEnabled();
-        }
-
+    public boolean generateSelectByPrimaryKey() {
+        boolean rc = tableConfiguration.isSelectByPrimaryKeyStatementEnabled()
+            && columnDefinitions.hasPrimaryKeyColumns()
+            && (columnDefinitions.hasBaseColumns()
+                    || columnDefinitions.hasBLOBColumns());
+        
         return rc;
     }
-
+    
     /**
-     * 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.
+     * 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.
      * 
-     * @param introspectedTable
-     *            the introspected table
      * @return true if the element and method should be generated
      */
-    public static boolean generateInsert(IntrospectedTable introspectedTable) {
-        return introspectedTable.isInsertStatementEnabled();
+    public boolean generateSelectByExampleWithoutBLOBs() {
+        return tableConfiguration.isSelectByExampleStatementEnabled();
     }
-
+    
     /**
-     * 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.
+     * 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.
      * 
-     * @param introspectedTable
-     *            the introspected table
      * @return true if the element and method should be generated
      */
-    public static boolean generateUpdateByPrimaryKeyWithoutBLOBs(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.PK_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        if (rc) {
-            rc = introspectedTable.isUpdateByPrimaryKeyStatementEnabled();
-        }
-
+    public boolean generateSelectByExampleWithBLOBs() {
+        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
+            && columnDefinitions.hasBLOBColumns();
+        
         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.
+     * Implements the rule for generating an example class with no super class.
+     * The class should only be generated if the selectByExample or
+     * deleteByExample methods are allowed.
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the element and method should be generated
+     * @return true if the example class should be generated
      */
-    public static boolean generateUpdateByPrimaryKeyWithBLOBs(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.PK_NO_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
-
-        if (rc) {
-            rc = introspectedTable.isUpdateByPrimaryKeyStatementEnabled();
-        }
-
+    public boolean generateExampleClass() {
+        boolean rc = tableConfiguration.isSelectByExampleStatementEnabled()
+                || tableConfiguration.isDeleteByExampleStatementEnabled();
+    
         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.
+     * Implements the rule for determining whether to generate a primary key
+     * class.  If you return false from this method, and the table has
+     * primary key columns, then the primary key columns will be
+     * added to the base class.
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the element and method should be generated
+     * @return true if a seperate primary key class should be generated
      */
-    public static boolean generateDeleteByPrimaryKey(
-            IntrospectedTable introspectedTable) {
-        TableType tableType = introspectedTable.getTableType();
-
-        boolean rc;
-
-        if (tableType == TableType.PK_NO_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_NO_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_NO_FIELDS_BLOBS) {
-            rc = true;
-        } else if (tableType == TableType.PK_FIELDS_BLOBS) {
-            rc = true;
-        } else {
-            rc = false;
-        }
+    public abstract boolean generatePrimaryKeyClass();
 
-        if (rc) {
-            rc = introspectedTable.isDeleteByPrimaryKeyStatementEnabled();
-        }
-
-        return rc;
-    }
+    /**
+     * Implements the rule for generating a base record.
+     * 
+     * @return true if the class should be generated
+     */
+    public abstract boolean generateBaseRecordClass();
 
     /**
-     * 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.
+     * Implements the rule for generating a record with BLOBs.  If you 
+     * return false from this method, and the table had BLOB columns,
+     * then the BLOB columns will be added to the base class.  
      * 
-     * @param introspectedTable
-     *            the introspected table
-     * @return true if the element and method should be generated
+     * @return true if the record with BLOBs class should be generated
      */
-    public static boolean generateDeleteByExample(
-            IntrospectedTable introspectedTable) {
-        return introspectedTable.isDeleteByExampleStatementEnabled();
-    }
+    public abstract boolean generateRecordWithBLOBsClass();
 }

Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/ConditionalModelRules.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/ConditionalModelRules.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/ConditionalModelRules.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/ConditionalModelRules.java Fri Aug  4 22:19:13 2006
@@ -0,0 +1,76 @@
+/*
+ *  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.abator.internal.rules;
+
+import org.apache.ibatis.abator.config.TableConfiguration;
+import org.apache.ibatis.abator.internal.db.ColumnDefinitions;
+
+/**
+ * This class encapsulates all the code generation rules for 
+ * a table using the conditional model.  In this model we do not
+ * generate primary key or record with BLOBs classes if the class
+ * would only hold one field.
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class ConditionalModelRules extends AbatorRules {
+
+    /**
+     * 
+     */
+    public ConditionalModelRules(TableConfiguration tableConfiguration,
+            ColumnDefinitions columnDefinitions) {
+        super(tableConfiguration, columnDefinitions);
+    }
+
+    /**
+     * We generate a primary key if there is more than one primary key
+     * field.
+     * 
+     * @return true if the primary key should be generated
+     */
+    public boolean generatePrimaryKeyClass() {
+        return columnDefinitions.getPrimaryKeyColumns().size() > 1;
+    }
+
+    /**
+     * Generate a base record if there are any base columns,
+     * or if there is only one primary key coulmn (in which case
+     * we will not generate a primary key class), or if there is only one
+     * BLOB column (in which case we will not generate a record with
+     * BLOBs class).
+     * 
+     * @return true if the class should be generated
+     */
+    public boolean generateBaseRecordClass() {
+        return columnDefinitions.getBaseColumns().size() > 0
+            || columnDefinitions.getPrimaryKeyColumns().size() == 1
+            || columnDefinitions.getBaseColumns().size() == 1;
+        
+    }
+
+    /**
+     * We generate a record with BLOBs class if there is more than one
+     * BLOB column. 
+     * 
+     * @return true if the record with BLOBs class should be generated
+     */
+    public boolean generateRecordWithBLOBsClass() {
+        return columnDefinitions.getBLOBColumns().size() > 1;
+    }
+}

Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/FlatModelRules.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/FlatModelRules.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/FlatModelRules.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/FlatModelRules.java Fri Aug  4 22:19:13 2006
@@ -0,0 +1,65 @@
+/*
+ *  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.abator.internal.rules;
+
+import org.apache.ibatis.abator.config.TableConfiguration;
+import org.apache.ibatis.abator.internal.db.ColumnDefinitions;
+
+/**
+ * This class encapsulates all the code generation rules for 
+ * a table using the flat model.
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class FlatModelRules extends AbatorRules {
+
+    /**
+     * 
+     */
+    public FlatModelRules(TableConfiguration tableConfiguration,
+            ColumnDefinitions columnDefinitions) {
+        super(tableConfiguration, columnDefinitions);
+    }
+
+    /**
+     * We never generate a primary key in the flat model.
+     * 
+     * @return true if the primary key should be generated
+     */
+    public boolean generatePrimaryKeyClass() {
+        return false;
+    }
+
+    /**
+     * We always generate a base record in the flat model.
+     * 
+     * @return true if the class should be generated
+     */
+    public boolean generateBaseRecordClass() {
+        return true;
+    }
+
+    /**
+     * We never generate a record with BLOBs class in the flat model. 
+     * 
+     * @return true if the record with BLOBs class should be generated
+     */
+    public boolean generateRecordWithBLOBsClass() {
+        return false;
+    }
+}

Added: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/HierarchicalModelRules.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/HierarchicalModelRules.java?rev=428963&view=auto
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/HierarchicalModelRules.java (added)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/HierarchicalModelRules.java Fri Aug  4 22:19:13 2006
@@ -0,0 +1,70 @@
+/*
+ *  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.abator.internal.rules;
+
+import org.apache.ibatis.abator.config.TableConfiguration;
+import org.apache.ibatis.abator.internal.db.ColumnDefinitions;
+
+/**
+ * This class encapsulates all the code generation rules for 
+ * a table using the hierarchical model.
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class HierarchicalModelRules extends AbatorRules {
+
+    /**
+     * 
+     */
+    public HierarchicalModelRules(TableConfiguration tableConfiguration,
+            ColumnDefinitions columnDefinitions) {
+        super(tableConfiguration, columnDefinitions);
+    }
+
+    /**
+     * Implements the rule for determining whether to generate a primary key
+     * class. If the physical table has a primary key, then we generate the
+     * class.
+     * 
+     * @return true if the primary key should be generated
+     */
+    public boolean generatePrimaryKeyClass() {
+        return columnDefinitions.hasPrimaryKeyColumns();
+    }
+
+    /**
+     * Implements the rule for generating a base record.  If the table
+     * has fields that are not in the primary key, and non-BLOB fields,
+     * then generate the class.
+     * 
+     * @return true if the class should be generated
+     */
+    public boolean generateBaseRecordClass() {
+        return columnDefinitions.hasBaseColumns();
+    }
+
+    /**
+     * Implements the rule for generating a record with BLOBs.  A record
+     * with BLOBs is generated if the table contains any BLOB fields. 
+     * 
+     * @return true if the record with BLOBs class should be generated
+     */
+    public boolean generateRecordWithBLOBsClass() {
+        return columnDefinitions.hasBLOBColumns();
+    }
+}

Modified: ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/package.html
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/package.html?rev=428963&r1=428962&r2=428963&view=diff
==============================================================================
--- ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/package.html (original)
+++ ibatis/trunk/java/mapper/mapper2/tools/abator/core/src/org/apache/ibatis/abator/internal/rules/package.html Fri Aug  4 22:19:13 2006
@@ -20,7 +20,7 @@
 <h2>Table Types</h2>
 <p>Abator defines different types of tables, based on the structure of the table.
   The table types are defined as follows:</p>
-  
+
 <table border="1" cellspacing="0" cellpadding="5">
   <tr>
     <th>Table Type</th>
@@ -79,7 +79,7 @@
 </table>
 
 <h2>SQL Map and DAO Method Rules</h2>
-<p>Abator generates different SQL Map elements based on the table type, and the 
+<p>Abator generates different SQL Map elements based on the table type, and the
 user configuration.  The following table describes what SQL Map elements will be
 generated based on the structure of the table.  The notes following the table describe
 how user configuration options can alter these rules.</p>
@@ -206,9 +206,10 @@
 </ul>
 
 <h2>Domain Object Rules</h2>
-<p>Abator generates different domain objects based on the structure of the table.
+<p>Abator generates different domain objects based on the structure of the table,
+and user configuration options.
 The following table describes the rules.  One important note is that
-Abator will not include BLOB columns in the Example classes - because 
+Abator will not include BLOB columns in the Example classes - because
 most databases do not support BLOB columns in the WHERE clause.  In
 the table, we use the term "base record" to mean the class that
 holds the non-BLOB and non-Primary Key fields.  The notes following the table
@@ -217,79 +218,142 @@
 <table border="1" cellspacing="0" cellpadding="5">
   <tr>
     <th>Table Type</th>
-    <th>Primary Key?</th>
-    <th>Base Record Extending Primary Key?</th>
-    <th>Base Record with no Super Class?</th>
-    <th>Record with BLOBs Extending Primary Key?</th>
-    <th>Record with BLOBs Extending Base Record?</th>
-    <th>Example Extending Primary Key?</th>
-    <th>Example Extending Base Record?</th>
+    <th>Generate Primary Key?</th>
+    <th>Generate Base Record?</th>
+    <th>Generate Record with BLOBs?</th>
   </tr>
   <tr>
     <th>NO_PK_FIELDS_NO_BLOBS</th>
     <td>No</td>
-    <td>No</td>
     <td>Yes</td>
     <td>No</td>
-    <td>No</td>
-    <td>No</td>
-    <td>Yes</td>
   </tr>
   <tr>
     <th>NO_PK_FIELDS_BLOBS</th>
     <td>No</td>
-    <td>No</td>
-    <td>Yes</td>
-    <td>No</td>
-    <td>Yes</td>
-    <td>No</td>
-    <td>Yes</td>
+    <td>c: Yes
+        <br />f: Yes, include ALL fields
+        <br />h: Yes
+    </td>
+    <td>c: Yes
+      <br />f: No
+      <br />h: Yes
+    </td>
   </tr>
   <tr>
     <th>PK_NO_FIELDS_NO_BLOBS</th>
-    <td>Yes</td>
-    <td>No</td>
-    <td>No</td>
-    <td>No</td>
-    <td>No</td>
-    <td>Yes</td>
+    <td>c: No
+        <br />f: No
+        <br />h: Yes
+    </td>
+    <td>c(1): No
+        <br />c(>1): Yes, include ALL fields
+        <br />f: Yes, include ALL fields
+        <br />h: No
+    </td>
     <td>No</td>
   </tr>
   <tr>
     <th>PK_FIELDS_NO_BLOBS</th>
-    <td>Yes</td>
-    <td>Yes</td>
-    <td>No</td>
+    <td>c(1): No
+        <br />c(>1): Yes
+        <br />f: No
+        <br />h: Yes
+    </td>
+    <td>c(1): Yes, include key field
+      <br />c(>1): Yes, do not include key fields
+      <br />f: Yes, include ALL fields
+      <br />h: Yes, do not include key field(s)
+    </td>
     <td>No</td>
-    <td>No</td>
-    <td>No</td>
-    <td>Yes</td>
   </tr>
   <tr>
     <th>PK_NO_FIELDS_BLOBS</th>
-    <td>Yes</td>
-    <td>No</td>
-    <td>No</td>
-    <td>Yes</td>
-    <td>No</td>
-    <td>Yes</td>
-    <td>No</td>
+    <td>c(1): No
+        <br />c(>1): Yes
+        <br />f: No
+        <br />h: Yes
+    </td>
+    <td>c(1): Yes, include ALL fields
+        <br />c(>1): No
+        <br />f: Yes, include ALL fields
+        <br />h: No
+    </td>
+    <td>c(1): No
+        <br />c(>1): Yes, BLOBs only
+      <br />f: No
+      <br />h: Yes
+    </td>
   </tr>
   <tr>
     <th>PK_FIELDS_BLOBS</th>
-    <td>Yes</td>
-    <td>Yes</td>
-    <td>No</td>
-    <td>No</td>
-    <td>Yes</td>
-    <td>No</td>
-    <td>Yes</td>
+    <td>c(1): No
+        <br />c(>1): Yes
+        <br />f: No
+        <br />h: Yes
+    </td>
+    <td>c(1): Yes, include key field
+        <br />c(>1): Yes, do not include key fields
+        <br />f: Yes, include ALL fields
+        <br />h: Yes
+    </td>
+    <td>c: Yes
+      <br />f: No
+      <br />h: Yes
+    </td>
+  </tr>
+</table>
+
+<p />
+
+<table border="1" cellspacing="0" cellpadding="5">
+  <tr>
+    <th>Table Type</th>
+    <th>Base Record Super Class</th>
+    <th>Record with BLOBs Super Class</th>
+    <th>Example Super Class</th>
+  </tr>
+  <tr>
+    <th>NO_PK_FIELDS_NO_BLOBS</th>
+    <td>None</td>
+    <td>N/A</td>
+    <td>Base Record</td>
+  </tr>
+  <tr>
+    <th>NO_PK_FIELDS_BLOBS</th>
+    <td>None</td>
+    <td>Base Record</td>
+    <td>Base Record</td>
+  </tr>
+  <tr>
+    <th>PK_NO_FIELDS_NO_BLOBS</th>
+    <td>N/A</td>
+    <td>N/A</td>
+    <td>Primary Key</td>
+  </tr>
+  <tr>
+    <th>PK_FIELDS_NO_BLOBS</th>
+    <td>Primary Key</td>
+    <td>N/A</td>
+    <td>Base Record</td>
+  </tr>
+  <tr>
+    <th>PK_NO_FIELDS_BLOBS</th>
+    <td>N/A</td>
+    <td>Primary Key</td>
+    <td>Primary Key</td>
+  </tr>
+  <tr>
+    <th>PK_FIELDS_BLOBS</th>
+    <td>Primary Key</td>
+    <td>Base Record</td>
+    <td>Base Record</td>
   </tr>
 </table>
 
 <p>Notes:</p>
 <ul>
-  <li>If the selectByExample and deleteByExample methods are disallowed, then 
+  <li>If the selectByExample and deleteByExample methods are disallowed, then
       Abator will not generate the Example class</li>
   <li>The example class will subclass the Primary Key or the Base Record only when
       using the "Legacy" generator set.  Otherwise, the example class will not subclass