ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgbut...@apache.org
Subject svn commit: r703569 [4/6] - in /ibatis/trunk/java/tools/ibator/core: build/ devlib/ doc/ src/org/apache/ibatis/ibator/api/ src/org/apache/ibatis/ibator/config/ src/org/apache/ibatis/ibator/config/xml/ src/org/apache/ibatis/ibator/generator/ src/org/apa...
Date Fri, 10 Oct 2008 20:08:12 GMT
Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/GenericCIDAOTemplate.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/GenericCIDAOTemplate.java?rev=703569&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/GenericCIDAOTemplate.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/GenericCIDAOTemplate.java Fri Oct 10 13:08:10 2008
@@ -0,0 +1,93 @@
+/*
+ *  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.generator.ibatis2.dao.templates;
+
+import org.apache.ibatis.ibator.api.dom.java.Field;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.ibator.api.dom.java.Method;
+import org.apache.ibatis.ibator.api.dom.java.Parameter;
+
+/**
+ * @author Jeff Butler
+ */
+public class GenericCIDAOTemplate extends AbstractDAOTemplate {
+
+    private FullyQualifiedJavaType sqlMapClientType =
+        new FullyQualifiedJavaType("com.ibatis.sqlmap.client.SqlMapClient"); //$NON-NLS-1$
+    
+    /**
+     *  
+     */
+    public GenericCIDAOTemplate() {
+        super();
+    }
+
+    @Override
+    protected void configureCheckedExceptions() {
+        addCheckedException(new FullyQualifiedJavaType("java.sql.SQLException")); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureConstructorTemplate() {
+        Method constructor = new Method();
+        constructor.setConstructor(true);
+        constructor.setVisibility(JavaVisibility.PUBLIC);
+        constructor.addParameter(new Parameter(sqlMapClientType, "sqlMapClient")); //$NON-NLS-1$
+        constructor.addBodyLine("super();"); //$NON-NLS-1$
+        constructor.addBodyLine("this.sqlMapClient = sqlMapClient;"); //$NON-NLS-1$
+        setConstructorTemplate(constructor);
+    }
+
+    @Override
+    protected void configureDeleteMethodTemplate() {
+        setDeleteMethodTemplate("sqlMapClient.delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureFields() {
+        Field field = new Field();
+        field.setVisibility(JavaVisibility.PRIVATE);
+        field.setType(sqlMapClientType);
+        field.setName("sqlMapClient"); //$NON-NLS-1$
+        addField(field);
+    }
+
+    @Override
+    protected void configureImplementationImports() {
+        addImplementationImport(sqlMapClientType);
+    }
+
+    @Override
+    protected void configureInsertMethodTemplate() {
+        setInsertMethodTemplate("sqlMapClient.insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureQueryForListMethodTemplate() {
+        setQueryForListMethodTemplate("sqlMapClient.queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureQueryForObjectMethodTemplate() {
+        setQueryForObjectMethodTemplate("sqlMapClient.queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureUpdateMethodTemplate() {
+        setUpdateMethodTemplate("sqlMapClient.update(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+}

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/GenericSIDAOTemplate.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/GenericSIDAOTemplate.java?rev=703569&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/GenericSIDAOTemplate.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/GenericSIDAOTemplate.java Fri Oct 10 13:08:10 2008
@@ -0,0 +1,107 @@
+/*
+ *  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.generator.ibatis2.dao.templates;
+
+import org.apache.ibatis.ibator.api.dom.java.Field;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.ibator.api.dom.java.Method;
+import org.apache.ibatis.ibator.api.dom.java.Parameter;
+
+/**
+ * @author Jeff Butler
+ */
+public class GenericSIDAOTemplate extends AbstractDAOTemplate {
+
+    private FullyQualifiedJavaType sqlMapClientType = new FullyQualifiedJavaType(
+            "com.ibatis.sqlmap.client.SqlMapClient"); //$NON-NLS-1$
+    /**
+     *  
+     */
+    public GenericSIDAOTemplate() {
+        super();
+    }
+
+    @Override
+    protected void configureCheckedExceptions() {
+        addCheckedException(new FullyQualifiedJavaType("java.sql.SQLException")); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureConstructorTemplate() {
+        Method method = new Method();
+        method.setConstructor(true);
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.addBodyLine("super();"); //$NON-NLS-1$
+        setConstructorTemplate(method);
+    }
+
+    @Override
+    protected void configureDeleteMethodTemplate() {
+        setDeleteMethodTemplate("sqlMapClient.delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureFields() {
+        Field field = new Field();
+        field.setVisibility(JavaVisibility.PRIVATE);
+        field.setType(sqlMapClientType);
+        field.setName("sqlMapClient"); //$NON-NLS-1$
+        addField(field);
+    }
+
+    @Override
+    protected void configureImplementationImports() {
+        addImplementationImport(sqlMapClientType);
+    }
+
+    @Override
+    protected void configureInsertMethodTemplate() {
+        setInsertMethodTemplate("sqlMapClient.insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureMethods() {
+        Method method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setName("setSqlMapClient"); //$NON-NLS-1$
+        method.addParameter(new Parameter(sqlMapClientType, "sqlMapClient")); //$NON-NLS-1$
+        method.addBodyLine("this.sqlMapClient = sqlMapClient;"); //$NON-NLS-1$
+        addMethod(method);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setName("getSqlMapClient"); //$NON-NLS-1$
+        method.setReturnType(sqlMapClientType);
+        method.addBodyLine("return sqlMapClient;"); //$NON-NLS-1$
+        addMethod(method);
+    }
+
+    @Override
+    protected void configureQueryForListMethodTemplate() {
+        setQueryForListMethodTemplate("sqlMapClient.queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureQueryForObjectMethodTemplate() {
+        setQueryForObjectMethodTemplate("sqlMapClient.queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureUpdateMethodTemplate() {
+        setUpdateMethodTemplate("sqlMapClient.update(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+}

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/IbatisDAOTemplate.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/IbatisDAOTemplate.java?rev=703569&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/IbatisDAOTemplate.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/IbatisDAOTemplate.java Fri Oct 10 13:08:10 2008
@@ -0,0 +1,83 @@
+/*
+ *  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.generator.ibatis2.dao.templates;
+
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.ibator.api.dom.java.Method;
+import org.apache.ibatis.ibator.api.dom.java.Parameter;
+
+/**
+ * @author Jeff Butler
+ */
+public class IbatisDAOTemplate extends AbstractDAOTemplate {
+
+    private FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(
+            "com.ibatis.dao.client.DaoManager"); //$NON-NLS-1$
+    
+    /**
+     *  
+     */
+    public IbatisDAOTemplate() {
+        super();
+    }
+
+    @Override
+    protected void configureConstructorTemplate() {
+        Method method = new Method();
+        method.setConstructor(true);
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.addParameter(new Parameter(fqjt, "daoManager")); //$NON-NLS-1$
+        method.addBodyLine("super(daoManager);"); //$NON-NLS-1$
+        setConstructorTemplate(method);
+    }
+
+    @Override
+    protected void configureDeleteMethodTemplate() {
+        setDeleteMethodTemplate("delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureImplementationImports() {
+        addImplementationImport(fqjt);
+    }
+
+    @Override
+    protected void configureInsertMethodTemplate() {
+        setInsertMethodTemplate("insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureQueryForListMethodTemplate() {
+        setQueryForListMethodTemplate("queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureQueryForObjectMethodTemplate() {
+        setQueryForObjectMethodTemplate("queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureSuperClass() {
+        setSuperClass(new FullyQualifiedJavaType(
+        "com.ibatis.dao.client.template.SqlMapDaoTemplate")); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureUpdateMethodTemplate() {
+        setUpdateMethodTemplate("update(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+}

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/SpringDAOTemplate.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/SpringDAOTemplate.java?rev=703569&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/SpringDAOTemplate.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/dao/templates/SpringDAOTemplate.java Fri Oct 10 13:08:10 2008
@@ -0,0 +1,73 @@
+/*
+ *  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.generator.ibatis2.dao.templates;
+
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.ibator.api.dom.java.Method;
+
+/**
+ * @author Jeff Butler
+ */
+public class SpringDAOTemplate extends AbstractDAOTemplate {
+
+    /**
+     *  
+     */
+    public SpringDAOTemplate() {
+        super();
+    }
+
+    @Override
+    protected void configureConstructorTemplate() {
+        Method method = new Method();
+        method.setConstructor(true);
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.addBodyLine("super();"); //$NON-NLS-1$
+        setConstructorTemplate(method);
+    }
+
+    @Override
+    protected void configureDeleteMethodTemplate() {
+        setDeleteMethodTemplate("getSqlMapClientTemplate().delete(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureInsertMethodTemplate() {
+        setInsertMethodTemplate("getSqlMapClientTemplate().insert(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureQueryForListMethodTemplate() {
+        setQueryForListMethodTemplate("getSqlMapClientTemplate().queryForList(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureQueryForObjectMethodTemplate() {
+        setQueryForObjectMethodTemplate("getSqlMapClientTemplate().queryForObject(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureSuperClass() {
+        setSuperClass(new FullyQualifiedJavaType(
+            "org.springframework.orm.ibatis.support.SqlMapClientDaoSupport")); //$NON-NLS-1$
+    }
+
+    @Override
+    protected void configureUpdateMethodTemplate() {
+        setUpdateMethodTemplate("getSqlMapClientTemplate().update(\"{0}.{1}\", {2});"); //$NON-NLS-1$
+    }
+}

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseModelClassGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseModelClassGenerator.java?rev=703569&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseModelClassGenerator.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseModelClassGenerator.java Fri Oct 10 13:08:10 2008
@@ -0,0 +1,131 @@
+/*
+ *  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.generator.ibatis2.model;
+
+import java.util.Properties;
+
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.java.Field;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.ibator.api.dom.java.Method;
+import org.apache.ibatis.ibator.api.dom.java.Parameter;
+import org.apache.ibatis.ibator.config.PropertyRegistry;
+import org.apache.ibatis.ibator.generator.AbstractGeneratorImpl;
+import org.apache.ibatis.ibator.internal.util.JavaBeansUtil;
+import org.apache.ibatis.ibator.internal.util.StringUtility;
+
+/**
+ * 
+ * @author Jeff Butler
+ *
+ */
+public abstract class BaseModelClassGenerator extends AbstractGeneratorImpl {
+    
+    public BaseModelClassGenerator() {
+        super();
+    }
+
+    public boolean isTrimStringsEnabled () {
+        Properties properties = ibatorContext.getJavaModelGeneratorConfiguration().getProperties();
+        boolean rc = StringUtility.isTrue(properties
+                .getProperty(PropertyRegistry.MODEL_GENERATOR_TRIM_STRINGS));
+        return rc;
+    }
+
+    public Field getJavaBeansField(IntrospectedColumn introspectedColumn) {
+        FullyQualifiedJavaType fqjt = introspectedColumn
+                .getFullyQualifiedJavaType();
+        String property = introspectedColumn.getJavaProperty();
+
+        Field field = new Field();
+        field.setVisibility(JavaVisibility.PRIVATE);
+        field.setType(fqjt);
+        field.setName(property);
+        ibatorContext.getCommentGenerator().addFieldComment(field,
+                introspectedTable.getFullyQualifiedTable(),
+                introspectedColumn.getActualColumnName());
+
+        return field;
+    }
+
+    public Method getJavaBeansSetter(IntrospectedColumn introspectedColumn) {
+        FullyQualifiedJavaType fqjt = introspectedColumn
+                .getFullyQualifiedJavaType();
+        String property = introspectedColumn.getJavaProperty();
+
+        Method method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setName(JavaBeansUtil.getSetterMethodName(property));
+        method.addParameter(new Parameter(fqjt, property));
+        ibatorContext.getCommentGenerator().addSetterComment(method,
+                introspectedTable.getFullyQualifiedTable(),
+                introspectedColumn.getActualColumnName());
+
+        StringBuilder sb = new StringBuilder();
+        if (isTrimStringsEnabled() && introspectedColumn.isStringColumn()) {
+            sb.append("this."); //$NON-NLS-1$
+            sb.append(property);
+            sb.append(" = "); //$NON-NLS-1$
+            sb.append(property);
+            sb.append(" == null ? null : "); //$NON-NLS-1$
+            sb.append(property);
+            sb.append(".trim();"); //$NON-NLS-1$
+            method.addBodyLine(sb.toString());
+        } else {
+            sb.append("this."); //$NON-NLS-1$
+            sb.append(property);
+            sb.append(" = "); //$NON-NLS-1$
+            sb.append(property);
+            sb.append(';');
+            method.addBodyLine(sb.toString());
+        }
+
+        return method;
+    }
+
+    public Method getJavaBeansGetter(IntrospectedColumn introspectedColumn) {
+        FullyQualifiedJavaType fqjt = introspectedColumn
+                .getFullyQualifiedJavaType();
+        String property = introspectedColumn.getJavaProperty();
+
+        Method method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(fqjt);
+        method.setName(JavaBeansUtil.getGetterMethodName(property, fqjt));
+        ibatorContext.getCommentGenerator().addGetterComment(method,
+                introspectedTable.getFullyQualifiedTable(),
+                introspectedColumn.getActualColumnName());
+
+        StringBuilder sb = new StringBuilder();
+        sb.append("return "); //$NON-NLS-1$
+        sb.append(property);
+        sb.append(';');
+        method.addBodyLine(sb.toString());
+
+        return method;
+    }
+
+    public String getRootClass () {
+        String rootClass = introspectedTable.getTableConfigurationProperty(PropertyRegistry.ANY_ROOT_CLASS);
+        if (rootClass == null) {
+            Properties properties = ibatorContext.getJavaModelGeneratorConfiguration().getProperties();
+            rootClass = properties.getProperty(PropertyRegistry.ANY_ROOT_CLASS);
+        }
+        
+        return rootClass;
+    }
+}

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseRecordGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseRecordGenerator.java?rev=703569&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseRecordGenerator.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/BaseRecordGenerator.java Fri Oct 10 13:08:10 2008
@@ -0,0 +1,139 @@
+/*
+ *  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.generator.ibatis2.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ibatis.ibator.api.CommentGenerator;
+import org.apache.ibatis.ibator.api.FullyQualifiedTable;
+import org.apache.ibatis.ibator.api.IbatorPlugin;
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.java.CompilationUnit;
+import org.apache.ibatis.ibator.api.dom.java.Field;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.ibator.api.dom.java.Method;
+import org.apache.ibatis.ibator.api.dom.java.TopLevelClass;
+import org.apache.ibatis.ibator.generator.JavaGenerator;
+import org.apache.ibatis.ibator.internal.util.messages.Messages;
+
+/**
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class BaseRecordGenerator extends BaseModelClassGenerator implements JavaGenerator {
+
+    public BaseRecordGenerator() {
+        super();
+    }
+
+    public List<CompilationUnit> getCompilationUnits() {
+        FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
+        progressCallback.startSubTask(Messages.getString("Progress.8", table.toString()));
+        IbatorPlugin plugins = ibatorContext.getPlugins();
+        CommentGenerator commentGenerator = ibatorContext.getCommentGenerator();
+
+        FullyQualifiedJavaType type = introspectedTable.getBaseRecordType();
+        TopLevelClass topLevelClass = new TopLevelClass(type);
+        topLevelClass.setVisibility(JavaVisibility.PUBLIC);
+        commentGenerator.addJavaFileComment(topLevelClass);
+        
+        FullyQualifiedJavaType superClass = getSuperClass();
+        if (superClass != null) {
+            topLevelClass.setSuperClass(superClass);
+            topLevelClass.addImportedType(superClass);
+        }
+
+        List<IntrospectedColumn> introspectedColumns;
+        if (includePrimaryKeyColumns()) {
+            if (includeBLOBColumns()) {
+                introspectedColumns = introspectedTable.getAllColumns();
+            } else {
+                introspectedColumns = introspectedTable.getNonBLOBColumns();
+            }
+        } else {
+            if (includeBLOBColumns()) {
+                introspectedColumns = introspectedTable.getNonPrimaryKeyColumns();
+            } else {
+                introspectedColumns = introspectedTable.getBaseColumns();
+            }
+        }
+
+        String rootClass = getRootClass();
+        for (IntrospectedColumn introspectedColumn : introspectedColumns) {
+            if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
+                continue;
+            }
+
+            Field field = getJavaBeansField(introspectedColumn);
+            if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn,
+                    introspectedTable)) {
+                topLevelClass.addField(field);
+                topLevelClass.addImportedType(field.getType());
+            }
+
+            Method method = getJavaBeansGetter(introspectedColumn);
+            if (plugins.modelGetterMethodGenerated(method, topLevelClass,
+                    introspectedColumn, introspectedTable)) {
+                topLevelClass.addMethod(method);
+            }
+
+            method = getJavaBeansSetter(introspectedColumn);
+            if (plugins.modelSetterMethodGenerated(method, topLevelClass,
+                    introspectedColumn, introspectedTable)) {
+                topLevelClass.addMethod(method);
+            }
+        }
+
+        List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
+        if (ibatorContext.getPlugins().modelBaseRecordClassGenerated(topLevelClass, introspectedTable)) {
+            answer.add(topLevelClass);
+        }
+        return answer;
+    }
+    
+    private FullyQualifiedJavaType getSuperClass() {
+        FullyQualifiedJavaType superClass;
+        if (introspectedTable.getRules().generatePrimaryKeyClass()) {
+            superClass = introspectedTable.getPrimaryKeyType();
+        } else {
+            String rootClass = getRootClass();
+            if (rootClass != null) {
+                superClass = new FullyQualifiedJavaType(rootClass);
+            } else {
+                superClass = null;
+            }
+        }
+        
+        return superClass;
+    }
+    
+    private boolean includePrimaryKeyColumns() {
+        return !introspectedTable.getRules().generatePrimaryKeyClass()
+            && introspectedTable.hasPrimaryKeyColumns();
+    }
+    
+    private boolean includeBLOBColumns() {
+        return !introspectedTable.getRules().generateRecordWithBLOBsClass()
+            && introspectedTable.hasBLOBColumns();
+    }
+
+    public int getNumberOfSubtasks() {
+        return 1;
+    }
+}

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/ExampleGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/ExampleGenerator.java?rev=703569&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/ExampleGenerator.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/ExampleGenerator.java Fri Oct 10 13:08:10 2008
@@ -0,0 +1,1124 @@
+/*
+ *  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.generator.ibatis2.model;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.ibatis.ibator.api.CommentGenerator;
+import org.apache.ibatis.ibator.api.FullyQualifiedTable;
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.IntrospectedTable;
+import org.apache.ibatis.ibator.api.dom.OutputUtilities;
+import org.apache.ibatis.ibator.api.dom.java.CompilationUnit;
+import org.apache.ibatis.ibator.api.dom.java.Field;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.java.InnerClass;
+import org.apache.ibatis.ibator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.ibator.api.dom.java.Method;
+import org.apache.ibatis.ibator.api.dom.java.Parameter;
+import org.apache.ibatis.ibator.api.dom.java.TopLevelClass;
+import org.apache.ibatis.ibator.generator.JavaGenerator;
+import org.apache.ibatis.ibator.internal.rules.IbatorRules;
+import org.apache.ibatis.ibator.internal.util.JavaBeansUtil;
+import org.apache.ibatis.ibator.internal.util.StringUtility;
+import org.apache.ibatis.ibator.internal.util.messages.Messages;
+
+/**
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class ExampleGenerator extends BaseModelClassGenerator implements JavaGenerator {
+
+    private boolean generateForJava5;
+
+    public ExampleGenerator(boolean generateForJava5) {
+        super();
+        this.generateForJava5 = generateForJava5;
+    }
+
+    public List<CompilationUnit> getCompilationUnits() {
+        FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
+        progressCallback.startSubTask(Messages.getString("Progress.6", table.toString()));
+        CommentGenerator commentGenerator = ibatorContext.getCommentGenerator();
+
+        FullyQualifiedJavaType type = introspectedTable.getExampleType();
+        TopLevelClass topLevelClass = new TopLevelClass(type);
+        topLevelClass.setVisibility(JavaVisibility.PUBLIC);
+        commentGenerator.addJavaFileComment(topLevelClass);
+
+        // add default constructor
+        Method method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setConstructor(true);
+        method.setName(type.getShortName());
+        if (generateForJava5) {
+            method.addBodyLine("oredCriteria = new ArrayList<Criteria>();"); //$NON-NLS-1$
+        } else {
+            method.addBodyLine("oredCriteria = new ArrayList();"); //$NON-NLS-1$
+        }
+        
+        commentGenerator.addGeneralMethodComment(method, table);
+        topLevelClass.addMethod(method);
+
+        // add shallow copy constructor if the update by
+        // example methods are enabled - because the parameter
+        // class for update by example methods will subclass this class
+        IbatorRules rules = introspectedTable.getRules();
+        if (rules.generateUpdateByExampleSelective()
+                || rules.generateUpdateByExampleWithBLOBs()
+                || rules.generateUpdateByExampleWithoutBLOBs()) {
+            method = new Method();
+            method.setVisibility(JavaVisibility.PROTECTED);
+            method.setConstructor(true);
+            method.setName(type.getShortName());
+            method.addParameter(new Parameter(type, "example")); //$NON-NLS-1$
+            method.addBodyLine("this.orderByClause = example.orderByClause;"); //$NON-NLS-1$
+            method.addBodyLine("this.oredCriteria = example.oredCriteria;"); //$NON-NLS-1$
+            commentGenerator.addGeneralMethodComment(method, table);
+            topLevelClass.addMethod(method);
+        }
+
+        // add field, getter, setter for orderby clause
+        Field field = new Field();
+        field.setVisibility(JavaVisibility.PROTECTED);
+        field.setType(FullyQualifiedJavaType.getStringInstance());
+        field.setName("orderByClause"); //$NON-NLS-1$
+        commentGenerator.addFieldComment(field, table);
+        topLevelClass.addField(field);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setName("setOrderByClause"); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "orderByClause")); //$NON-NLS-1$
+        method.addBodyLine("this.orderByClause = orderByClause;"); //$NON-NLS-1$
+        commentGenerator.addGeneralMethodComment(method, table);
+        topLevelClass.addMethod(method);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(FullyQualifiedJavaType.getStringInstance());
+        method.setName("getOrderByClause"); //$NON-NLS-1$
+        method.addBodyLine("return orderByClause;"); //$NON-NLS-1$
+        commentGenerator.addGeneralMethodComment(method, table);
+        topLevelClass.addMethod(method);
+
+        // add field and methods for the list of ored criteria
+        field = new Field();
+        field.setVisibility(JavaVisibility.PROTECTED);
+
+        FullyQualifiedJavaType fqjt = FullyQualifiedJavaType
+                .getNewListInstance();
+        if (generateForJava5) {
+            fqjt.addTypeArgument(new FullyQualifiedJavaType("Criteria")); //$NON-NLS-1$
+        }
+
+        field.setType(fqjt);
+        field.setName("oredCriteria"); //$NON-NLS-1$
+        commentGenerator.addFieldComment(field, table);
+        topLevelClass.addField(field);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(fqjt);
+        method.setName("getOredCriteria"); //$NON-NLS-1$
+        method.addBodyLine("return oredCriteria;"); //$NON-NLS-1$
+        commentGenerator.addGeneralMethodComment(method, table);
+        topLevelClass.addMethod(method);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        if (ibatorContext.getSuppressTypeWarnings()) {
+            method.addSuppressTypeWarningsAnnotation();
+        }
+        method.setName("or"); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getCriteriaInstance(), "criteria")); //$NON-NLS-1$
+        method.addBodyLine("oredCriteria.add(criteria);"); //$NON-NLS-1$
+
+        commentGenerator.addGeneralMethodComment(method, table);
+        topLevelClass.addMethod(method);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        if (ibatorContext.getSuppressTypeWarnings()) {
+            method.addSuppressTypeWarningsAnnotation();
+        }
+        method.setName("createCriteria"); //$NON-NLS-1$
+        method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
+        method.addBodyLine("Criteria criteria = createCriteriaInternal();"); //$NON-NLS-1$
+        method.addBodyLine("if (oredCriteria.size() == 0) {"); //$NON-NLS-1$
+        method.addBodyLine("oredCriteria.add(criteria);"); //$NON-NLS-1$
+        method.addBodyLine("}"); //$NON-NLS-1$
+        method.addBodyLine("return criteria;"); //$NON-NLS-1$
+        commentGenerator.addGeneralMethodComment(method, table);
+        topLevelClass.addMethod(method);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PROTECTED);
+        method.setName("createCriteriaInternal"); //$NON-NLS-1$
+        method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
+        method.addBodyLine("Criteria criteria = new Criteria();"); //$NON-NLS-1$
+        method.addBodyLine("return criteria;"); //$NON-NLS-1$
+        commentGenerator.addGeneralMethodComment(method, table);
+        topLevelClass.addMethod(method);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setName("clear"); //$NON-NLS-1$
+        method.addBodyLine("oredCriteria.clear();"); //$NON-NLS-1$
+        commentGenerator.addGeneralMethodComment(method, table);
+        topLevelClass.addMethod(method);
+
+        // now generate the inner class that holds the AND conditions
+        topLevelClass.addInnerClass(getCriteriaInnerClass(topLevelClass,
+                introspectedTable));
+
+        List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
+        if (ibatorContext.getPlugins().modelExampleClassGenerated(topLevelClass, introspectedTable)) {
+            answer.add(topLevelClass);
+        }
+        return answer;
+    }
+
+    private InnerClass getCriteriaInnerClass(TopLevelClass topLevelClass,
+            IntrospectedTable introspectedTable) {
+        Field field;
+        Method method;
+
+        InnerClass answer = new InnerClass(FullyQualifiedJavaType
+                .getCriteriaInstance());
+
+        answer.setVisibility(JavaVisibility.PUBLIC);
+        answer.setStatic(true);
+        ibatorContext.getCommentGenerator().addClassComment(answer,
+                introspectedTable.getFullyQualifiedTable());
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PROTECTED);
+        method.setName("Criteria"); //$NON-NLS-1$
+        method.setConstructor(true);
+        method.addBodyLine("super();"); //$NON-NLS-1$
+        if (generateForJava5) {
+            method.addBodyLine("criteriaWithoutValue = new ArrayList<String>();"); //$NON-NLS-1$
+            method.addBodyLine("criteriaWithSingleValue = new ArrayList<Map<String, Object>>();"); //$NON-NLS-1$
+            method.addBodyLine("criteriaWithListValue = new ArrayList<Map<String, Object>>();"); //$NON-NLS-1$
+            method.addBodyLine("criteriaWithBetweenValue = new ArrayList<Map<String, Object>>();"); //$NON-NLS-1$
+            
+        } else {
+            method.addBodyLine("criteriaWithoutValue = new ArrayList();"); //$NON-NLS-1$
+            method.addBodyLine("criteriaWithSingleValue = new ArrayList();"); //$NON-NLS-1$
+            method.addBodyLine("criteriaWithListValue = new ArrayList();"); //$NON-NLS-1$
+            method.addBodyLine("criteriaWithBetweenValue = new ArrayList();"); //$NON-NLS-1$
+        }
+        answer.addMethod(method);
+
+        List<String> criteriaLists = new ArrayList<String>();
+        criteriaLists.add("criteriaWithoutValue"); //$NON-NLS-1$
+        criteriaLists.add("criteriaWithSingleValue"); //$NON-NLS-1$
+        criteriaLists.add("criteriaWithListValue"); //$NON-NLS-1$
+        criteriaLists.add("criteriaWithBetweenValue"); //$NON-NLS-1$
+
+        for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
+            if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
+                criteriaLists.addAll(addtypeHandledObjectsAndMethods(introspectedColumn,
+                        method, answer));
+            }
+        }
+
+        // now generate the isValid method
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setName("isValid"); //$NON-NLS-1$
+        method.setReturnType(FullyQualifiedJavaType
+                .getBooleanPrimitiveInstance());
+        StringBuilder sb = new StringBuilder();
+        Iterator<String> strIter = criteriaLists.iterator();
+        sb.append("return "); //$NON-NLS-1$
+        sb.append(strIter.next());
+        sb.append(".size() > 0"); //$NON-NLS-1$
+        method.addBodyLine(sb.toString());
+        while (strIter.hasNext()) {
+            sb.setLength(0);
+            OutputUtilities.javaIndent(sb, 1);
+            sb.append("|| "); //$NON-NLS-1$
+            sb.append(strIter.next());
+            sb.append(".size() > 0"); //$NON-NLS-1$
+            if (!strIter.hasNext()) {
+                sb.append(';');
+            }
+            method.addBodyLine(sb.toString());
+        }
+        answer.addMethod(method);
+
+        // now we need to generate the methods that will be used in the SqlMap
+        // to generate the dynamic where clause
+        topLevelClass.addImportedType(FullyQualifiedJavaType
+                .getNewMapInstance());
+        topLevelClass.addImportedType(FullyQualifiedJavaType
+                .getNewListInstance());
+        topLevelClass.addImportedType(FullyQualifiedJavaType
+                .getNewHashMapInstance());
+        topLevelClass.addImportedType(FullyQualifiedJavaType
+                .getNewArrayListInstance());
+
+        field = new Field();
+        field.setVisibility(JavaVisibility.PROTECTED);
+        FullyQualifiedJavaType listOfStrings = FullyQualifiedJavaType
+                .getNewListInstance();
+        if (generateForJava5) {
+            listOfStrings.addTypeArgument(FullyQualifiedJavaType.getStringInstance());
+        }
+        field.setType(listOfStrings);
+        field.setName("criteriaWithoutValue"); //$NON-NLS-1$
+        answer.addField(field);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(field.getType());
+        method.setName(JavaBeansUtil.getGetterMethodName(field.getName(), field
+                .getType()));
+        method.addBodyLine("return criteriaWithoutValue;"); //$NON-NLS-1$
+        answer.addMethod(method);
+
+        FullyQualifiedJavaType listOfMaps = FullyQualifiedJavaType
+                .getNewListInstance();
+        if (generateForJava5) {
+            FullyQualifiedJavaType mapStringObject = FullyQualifiedJavaType.getNewMapInstance();
+            mapStringObject.addTypeArgument(FullyQualifiedJavaType.getStringInstance());
+            mapStringObject.addTypeArgument(FullyQualifiedJavaType.getObjectInstance());
+            listOfMaps.addTypeArgument(mapStringObject);
+        }
+
+        field = new Field();
+        field.setVisibility(JavaVisibility.PROTECTED);
+        field.setType(listOfMaps);
+        field.setName("criteriaWithSingleValue"); //$NON-NLS-1$
+        answer.addField(field);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(field.getType());
+        method.setName(JavaBeansUtil.getGetterMethodName(field.getName(), field
+                .getType()));
+        method.addBodyLine("return criteriaWithSingleValue;"); //$NON-NLS-1$
+        answer.addMethod(method);
+
+        field = new Field();
+        field.setVisibility(JavaVisibility.PROTECTED);
+        field.setType(listOfMaps);
+        field.setName("criteriaWithListValue"); //$NON-NLS-1$
+        answer.addField(field);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(field.getType());
+        method.setName(JavaBeansUtil.getGetterMethodName(field.getName(), field
+                .getType()));
+        method.addBodyLine("return criteriaWithListValue;"); //$NON-NLS-1$
+        answer.addMethod(method);
+
+        field = new Field();
+        field.setVisibility(JavaVisibility.PROTECTED);
+        field.setType(listOfMaps);
+        field.setName("criteriaWithBetweenValue"); //$NON-NLS-1$
+        answer.addField(field);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(field.getType());
+        method.setName(JavaBeansUtil.getGetterMethodName(field.getName(), field
+                .getType()));
+        method.addBodyLine("return criteriaWithBetweenValue;"); //$NON-NLS-1$
+        answer.addMethod(method);
+
+        // now add the methods for simplifying the individual field set methods
+        method = new Method();
+        method.setVisibility(JavaVisibility.PROTECTED);
+        if (ibatorContext.getSuppressTypeWarnings()) {
+            method.addSuppressTypeWarningsAnnotation();
+        }
+        method.setName("addCriterion"); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "condition")); //$NON-NLS-1$
+        method.addBodyLine("if (condition == null) {"); //$NON-NLS-1$
+        method
+                .addBodyLine("throw new RuntimeException(\"Value for condition cannot be null\");"); //$NON-NLS-1$
+        method.addBodyLine("}"); //$NON-NLS-1$
+        method.addBodyLine("criteriaWithoutValue.add(condition);"); //$NON-NLS-1$
+        answer.addMethod(method);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PROTECTED);
+        if (ibatorContext.getSuppressTypeWarnings()) {
+            method.addSuppressTypeWarningsAnnotation();
+        }
+        method.setName("addCriterion"); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "condition")); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getObjectInstance(), "value")); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "property")); //$NON-NLS-1$
+        method.addBodyLine("if (value == null) {"); //$NON-NLS-1$
+        method
+                .addBodyLine("throw new RuntimeException(\"Value for \" + property + \" cannot be null\");"); //$NON-NLS-1$
+        method.addBodyLine("}"); //$NON-NLS-1$
+        if (generateForJava5) {
+            method.addBodyLine("Map<String, Object> map = new HashMap<String, Object>();"); //$NON-NLS-1$
+        } else {
+            method.addBodyLine("Map map = new HashMap();"); //$NON-NLS-1$
+        }
+        
+        method.addBodyLine("map.put(\"condition\", condition);"); //$NON-NLS-1$
+        method.addBodyLine("map.put(\"value\", value);"); //$NON-NLS-1$
+        method.addBodyLine("criteriaWithSingleValue.add(map);"); //$NON-NLS-1$
+        answer.addMethod(method);
+
+        FullyQualifiedJavaType listOfObjects = FullyQualifiedJavaType
+                .getNewListInstance();
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PROTECTED);
+        if (ibatorContext.getSuppressTypeWarnings()) {
+            method.addSuppressTypeWarningsAnnotation();
+        }
+        method.setName("addCriterion"); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "condition")); //$NON-NLS-1$
+        method.addParameter(new Parameter(listOfObjects, "values")); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "property")); //$NON-NLS-1$
+        method.addBodyLine("if (values == null || values.size() == 0) {"); //$NON-NLS-1$
+        method
+                .addBodyLine("throw new RuntimeException(\"Value list for \" + property + \" cannot be null or empty\");"); //$NON-NLS-1$
+        method.addBodyLine("}"); //$NON-NLS-1$
+        if (generateForJava5) {
+            method.addBodyLine("Map<String, Object> map = new HashMap<String, Object>();"); //$NON-NLS-1$
+        } else {
+            method.addBodyLine("Map map = new HashMap();"); //$NON-NLS-1$
+        }
+        
+        method.addBodyLine("map.put(\"condition\", condition);"); //$NON-NLS-1$
+        method.addBodyLine("map.put(\"values\", values);"); //$NON-NLS-1$
+        method.addBodyLine("criteriaWithListValue.add(map);"); //$NON-NLS-1$
+        answer.addMethod(method);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PROTECTED);
+        if (ibatorContext.getSuppressTypeWarnings()) {
+            method.addSuppressTypeWarningsAnnotation();
+        }
+        method.setName("addCriterion"); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "condition")); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getObjectInstance(), "value1")); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getObjectInstance(), "value2")); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "property")); //$NON-NLS-1$
+        method.addBodyLine("if (value1 == null || value2 == null) {"); //$NON-NLS-1$
+        method
+                .addBodyLine("throw new RuntimeException(\"Between values for \" + property + \" cannot be null\");"); //$NON-NLS-1$
+        method.addBodyLine("}"); //$NON-NLS-1$
+        if (generateForJava5) {
+            method.addBodyLine("List<Object> list = new ArrayList<Object>();"); //$NON-NLS-1$
+        } else {
+            method.addBodyLine("List list = new ArrayList();"); //$NON-NLS-1$
+        }
+        
+        method.addBodyLine("list.add(value1);"); //$NON-NLS-1$
+        method.addBodyLine("list.add(value2);"); //$NON-NLS-1$
+        if (generateForJava5) {
+            method.addBodyLine("Map<String, Object> map = new HashMap<String, Object>();"); //$NON-NLS-1$
+        } else {
+            method.addBodyLine("Map map = new HashMap();"); //$NON-NLS-1$
+        }
+        method.addBodyLine("map.put(\"condition\", condition);"); //$NON-NLS-1$
+        method.addBodyLine("map.put(\"values\", list);"); //$NON-NLS-1$
+        method.addBodyLine("criteriaWithBetweenValue.add(map);"); //$NON-NLS-1$
+        answer.addMethod(method);
+
+        FullyQualifiedJavaType listOfDates = FullyQualifiedJavaType
+                .getNewListInstance();
+        if (generateForJava5) {
+            listOfDates.addTypeArgument(FullyQualifiedJavaType.getDateInstance());
+        }
+
+        if (introspectedTable.hasJDBCDateColumns()) {
+            topLevelClass.addImportedType(FullyQualifiedJavaType
+                    .getDateInstance());
+            topLevelClass.addImportedType(FullyQualifiedJavaType
+                    .getNewIteratorInstance());
+            method = new Method();
+            method.setVisibility(JavaVisibility.PROTECTED);
+            method.setName("addCriterionForJDBCDate"); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "condition")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getDateInstance(), "value")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "property")); //$NON-NLS-1$
+            method
+                    .addBodyLine("addCriterion(condition, new java.sql.Date(value.getTime()), property);"); //$NON-NLS-1$
+            answer.addMethod(method);
+
+            method = new Method();
+            method.setVisibility(JavaVisibility.PROTECTED);
+            if (ibatorContext.getSuppressTypeWarnings()) {
+                method.addSuppressTypeWarningsAnnotation();
+            }
+            method.setName("addCriterionForJDBCDate"); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "condition")); //$NON-NLS-1$
+            method.addParameter(new Parameter(listOfDates, "values")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "property")); //$NON-NLS-1$
+            method.addBodyLine("if (values == null || values.size() == 0) {"); //$NON-NLS-1$
+            method
+                    .addBodyLine("throw new RuntimeException(\"Value list for \" + property + \" cannot be null or empty\");"); //$NON-NLS-1$
+            method.addBodyLine("}"); //$NON-NLS-1$
+            if (generateForJava5) {
+                method.addBodyLine("List<java.sql.Date> dateList = new ArrayList<java.sql.Date>();"); //$NON-NLS-1$
+                method.addBodyLine("Iterator<Date> iter = values.iterator();"); //$NON-NLS-1$
+                method.addBodyLine("while (iter.hasNext()) {"); //$NON-NLS-1$
+                method.addBodyLine("dateList.add(new java.sql.Date(iter.next().getTime()));"); //$NON-NLS-1$
+                method.addBodyLine("}"); //$NON-NLS-1$
+            } else {
+                method.addBodyLine("List dateList = new ArrayList();"); //$NON-NLS-1$
+                method.addBodyLine("Iterator iter = values.iterator();"); //$NON-NLS-1$
+                method.addBodyLine("while (iter.hasNext()) {"); //$NON-NLS-1$
+                method.addBodyLine("dateList.add(new java.sql.Date(((Date)iter.next()).getTime()));"); //$NON-NLS-1$
+                method.addBodyLine("}"); //$NON-NLS-1$
+            }
+            method.addBodyLine("addCriterion(condition, dateList, property);"); //$NON-NLS-1$
+            answer.addMethod(method);
+
+            method = new Method();
+            method.setVisibility(JavaVisibility.PROTECTED);
+            method.setName("addCriterionForJDBCDate"); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "condition")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getDateInstance(), "value1")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getDateInstance(), "value2")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "property")); //$NON-NLS-1$
+            method.addBodyLine("if (value1 == null || value2 == null) {"); //$NON-NLS-1$
+            method
+                    .addBodyLine("throw new RuntimeException(\"Between values for \" + property + \" cannot be null\");"); //$NON-NLS-1$
+            method.addBodyLine("}"); //$NON-NLS-1$
+            method
+                    .addBodyLine("addCriterion(condition, new java.sql.Date(value1.getTime()), new java.sql.Date(value2.getTime()), property);"); //$NON-NLS-1$
+            answer.addMethod(method);
+        }
+
+        if (introspectedTable.hasJDBCTimeColumns()) {
+            topLevelClass.addImportedType(FullyQualifiedJavaType
+                    .getDateInstance());
+            topLevelClass.addImportedType(FullyQualifiedJavaType
+                    .getNewIteratorInstance());
+            method = new Method();
+            method.setVisibility(JavaVisibility.PROTECTED);
+            method.setName("addCriterionForJDBCTime"); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "condition")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getDateInstance(), "value")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "property")); //$NON-NLS-1$
+            method
+                    .addBodyLine("addCriterion(condition, new java.sql.Time(value.getTime()), property);"); //$NON-NLS-1$
+            answer.addMethod(method);
+
+            method = new Method();
+            method.setVisibility(JavaVisibility.PROTECTED);
+            if (ibatorContext.getSuppressTypeWarnings()) {
+                method.addSuppressTypeWarningsAnnotation();
+            }
+            method.setName("addCriterionForJDBCTime"); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "condition")); //$NON-NLS-1$
+            method.addParameter(new Parameter(listOfDates, "values")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "property")); //$NON-NLS-1$
+            method.addBodyLine("if (values == null || values.size() == 0) {"); //$NON-NLS-1$
+            method
+                    .addBodyLine("throw new RuntimeException(\"Value list for \" + property + \" cannot be null or empty\");"); //$NON-NLS-1$
+            method.addBodyLine("}"); //$NON-NLS-1$
+            if (generateForJava5) {
+                method.addBodyLine("List<java.sql.Time> timeList = new ArrayList<java.sql.Time>();"); //$NON-NLS-1$
+                method.addBodyLine("Iterator<Date> iter = values.iterator();"); //$NON-NLS-1$
+                method.addBodyLine("while (iter.hasNext()) {"); //$NON-NLS-1$
+                method
+                    .addBodyLine("timeList.add(new java.sql.Time(iter.next().getTime()));"); //$NON-NLS-1$
+                method.addBodyLine("}"); //$NON-NLS-1$
+            } else {
+                method.addBodyLine("List timeList = new ArrayList();"); //$NON-NLS-1$
+                method.addBodyLine("Iterator iter = values.iterator();"); //$NON-NLS-1$
+                method.addBodyLine("while (iter.hasNext()) {"); //$NON-NLS-1$
+                method
+                    .addBodyLine("timeList.add(new java.sql.Time(((Date)iter.next()).getTime()));"); //$NON-NLS-1$
+                method.addBodyLine("}"); //$NON-NLS-1$
+            }
+            method.addBodyLine("addCriterion(condition, timeList, property);"); //$NON-NLS-1$
+            answer.addMethod(method);
+
+            method = new Method();
+            method.setVisibility(JavaVisibility.PROTECTED);
+            method.setName("addCriterionForJDBCTime"); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "condition")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getDateInstance(), "value1")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getDateInstance(), "value2")); //$NON-NLS-1$
+            method.addParameter(new Parameter(FullyQualifiedJavaType
+                    .getStringInstance(), "property")); //$NON-NLS-1$
+            method.addBodyLine("if (value1 == null || value2 == null) {"); //$NON-NLS-1$
+            method
+                    .addBodyLine("throw new RuntimeException(\"Between values for \" + property + \" cannot be null\");"); //$NON-NLS-1$
+            method.addBodyLine("}"); //$NON-NLS-1$
+            method
+                    .addBodyLine("addCriterion(condition, new java.sql.Time(value1.getTime()), new java.sql.Time(value2.getTime()), property);"); //$NON-NLS-1$
+            answer.addMethod(method);
+        }
+
+        for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
+            topLevelClass.addImportedType(introspectedColumn.getFullyQualifiedJavaType());
+
+            // here we need to add the individual methods for setting the
+            // conditions for a field
+            answer.addMethod(getSetNullMethod(introspectedColumn));
+            answer.addMethod(getSetNotNullMethod(introspectedColumn));
+            answer.addMethod(getSetEqualMethod(introspectedColumn));
+            answer.addMethod(getSetNotEqualMethod(introspectedColumn));
+            answer.addMethod(getSetGreaterThanMethod(introspectedColumn));
+            answer.addMethod(getSetGreaterThenOrEqualMethod(introspectedColumn));
+            answer.addMethod(getSetLessThanMethod(introspectedColumn));
+            answer.addMethod(getSetLessThanOrEqualMethod(introspectedColumn));
+
+            if (introspectedColumn.isJdbcCharacterColumn()) {
+                answer.addMethod(getSetLikeMethod(introspectedColumn));
+                answer.addMethod(getSetNotLikeMethod(introspectedColumn));
+            }
+
+            answer.addMethod(getSetInOrNotInMethod(introspectedColumn, true));
+            answer.addMethod(getSetInOrNotInMethod(introspectedColumn, false));
+            answer.addMethod(getSetBetweenOrNotBetweenMethod(introspectedColumn, true));
+            answer.addMethod(getSetBetweenOrNotBetweenMethod(introspectedColumn, false));
+        }
+
+        return answer;
+    }
+
+    /**
+     * This method adds all the extra methods and fields required to support a
+     * user defined type handler on some column.
+     * 
+     * @param introspectedColumn
+     * @param constructor
+     * @param innerClass
+     * @return a list of the names of all Lists added to the class by this
+     *         method
+     */
+    private List<String> addtypeHandledObjectsAndMethods(IntrospectedColumn introspectedColumn,
+            Method constructor, InnerClass innerClass) {
+        List<String> answer = new ArrayList<String>();
+        StringBuilder sb = new StringBuilder();
+
+        // add new private fields and public accessors in the class
+        FullyQualifiedJavaType listOfMaps = FullyQualifiedJavaType
+                .getNewListInstance();
+        if (generateForJava5) {
+            FullyQualifiedJavaType mapStringObject = FullyQualifiedJavaType.getNewMapInstance();
+            mapStringObject.addTypeArgument(FullyQualifiedJavaType.getStringInstance());
+            mapStringObject.addTypeArgument(FullyQualifiedJavaType.getObjectInstance());
+            listOfMaps.addTypeArgument(mapStringObject);
+        }
+
+        sb.setLength(0);
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.append("CriteriaWithSingleValue"); //$NON-NLS-1$
+        answer.add(sb.toString());
+
+        Field field = new Field();
+        field.setVisibility(JavaVisibility.PROTECTED);
+        field.setType(listOfMaps);
+        field.setName(sb.toString());
+        innerClass.addField(field);
+
+        Method method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(field.getType());
+        method.setName(JavaBeansUtil.getGetterMethodName(field.getName(), field
+                .getType()));
+        sb.insert(0, "return "); //$NON-NLS-1$
+        sb.append(';');
+        method.addBodyLine(sb.toString());
+        innerClass.addMethod(method);
+
+        sb.setLength(0);
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.append("CriteriaWithListValue"); //$NON-NLS-1$
+        answer.add(sb.toString());
+
+        field = new Field();
+        field.setVisibility(JavaVisibility.PROTECTED);
+        field.setType(listOfMaps);
+        field.setName(sb.toString());
+        innerClass.addField(field);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(field.getType());
+        method.setName(JavaBeansUtil.getGetterMethodName(field.getName(), field
+                .getType()));
+        sb.insert(0, "return "); //$NON-NLS-1$
+        sb.append(';');
+        method.addBodyLine(sb.toString());
+        innerClass.addMethod(method);
+
+        sb.setLength(0);
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.append("CriteriaWithBetweenValue"); //$NON-NLS-1$
+        answer.add(sb.toString());
+
+        field = new Field();
+        field.setVisibility(JavaVisibility.PROTECTED);
+        field.setType(listOfMaps);
+        field.setName(sb.toString());
+        innerClass.addField(field);
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.setReturnType(field.getType());
+        method.setName(JavaBeansUtil.getGetterMethodName(field.getName(), field
+                .getType()));
+        sb.insert(0, "return "); //$NON-NLS-1$
+        sb.append(';');
+        method.addBodyLine(sb.toString());
+        innerClass.addMethod(method);
+
+        // add constructor initialization
+        sb.setLength(0);
+        sb.append(introspectedColumn.getJavaProperty());
+        if (generateForJava5) {
+            sb.append("CriteriaWithSingleValue = new ArrayList<Map<String, Object>>();"); //$NON-NLS-1$;
+        } else {
+            sb.append("CriteriaWithSingleValue = new ArrayList();"); //$NON-NLS-1$;
+        }
+        constructor.addBodyLine(sb.toString());
+
+        sb.setLength(0);
+        sb.append(introspectedColumn.getJavaProperty());
+        if (generateForJava5) {
+            sb.append("CriteriaWithListValue = new ArrayList<Map<String, Object>>();"); //$NON-NLS-1$
+        } else {
+            sb.append("CriteriaWithListValue = new ArrayList();"); //$NON-NLS-1$
+        }
+        constructor.addBodyLine(sb.toString());
+
+        sb.setLength(0);
+        sb.append(introspectedColumn.getJavaProperty());
+        if (generateForJava5) {
+            sb.append("CriteriaWithBetweenValue = new ArrayList<Map<String, Object>>();"); //$NON-NLS-1$
+        } else {
+            sb.append("CriteriaWithBetweenValue = new ArrayList();"); //$NON-NLS-1$
+        }
+        constructor.addBodyLine(sb.toString());
+
+        // now add the methods for simplifying the individual field set methods
+        method = new Method();
+        method.setVisibility(JavaVisibility.PROTECTED);
+        sb.setLength(0);
+        sb.append("add"); //$NON-NLS-1$
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
+        sb.append("Criterion"); //$NON-NLS-1$
+
+        method.setName(sb.toString());
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "condition")); //$NON-NLS-1$
+        method.addParameter(new Parameter(introspectedColumn.getFullyQualifiedJavaType(), "value")); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "property")); //$NON-NLS-1$
+        method.addBodyLine("if (value == null) {"); //$NON-NLS-1$
+        method
+                .addBodyLine("throw new RuntimeException(\"Value for \" + property + \" cannot be null\");"); //$NON-NLS-1$
+        method.addBodyLine("}"); //$NON-NLS-1$
+        if (generateForJava5) {
+            method.addBodyLine("Map<String, Object> map = new HashMap<String, Object>();"); //$NON-NLS-1$
+        } else {
+            method.addBodyLine("Map map = new HashMap();"); //$NON-NLS-1$
+        }
+        method.addBodyLine("map.put(\"condition\", condition);"); //$NON-NLS-1$
+        method.addBodyLine("map.put(\"value\", value);"); //$NON-NLS-1$
+
+        sb.setLength(0);
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.append("CriteriaWithSingleValue.add(map);"); //$NON-NLS-1$
+        method.addBodyLine(sb.toString());
+        innerClass.addMethod(method);
+
+        FullyQualifiedJavaType listOfObjects = FullyQualifiedJavaType
+                .getNewListInstance();
+        if (generateForJava5) {
+            listOfObjects.addTypeArgument(introspectedColumn.getFullyQualifiedJavaType());
+        }
+
+        sb.setLength(0);
+        sb.append("add"); //$NON-NLS-1$
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
+        sb.append("Criterion"); //$NON-NLS-1$
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PROTECTED);
+        method.setName(sb.toString());
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "condition")); //$NON-NLS-1$
+        method.addParameter(new Parameter(listOfObjects, "values")); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "property")); //$NON-NLS-1$
+        method.addBodyLine("if (values == null || values.size() == 0) {"); //$NON-NLS-1$
+        method
+                .addBodyLine("throw new RuntimeException(\"Value list for \" + property + \" cannot be null or empty\");"); //$NON-NLS-1$
+        method.addBodyLine("}"); //$NON-NLS-1$
+        if (generateForJava5) {
+            method.addBodyLine("Map<String, Object> map = new HashMap<String, Object>();"); //$NON-NLS-1$
+        } else {
+            method.addBodyLine("Map map = new HashMap();"); //$NON-NLS-1$
+        }
+        method.addBodyLine("map.put(\"condition\", condition);"); //$NON-NLS-1$
+        method.addBodyLine("map.put(\"values\", values);"); //$NON-NLS-1$
+
+        sb.setLength(0);
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.append("CriteriaWithListValue.add(map);"); //$NON-NLS-1$
+        method.addBodyLine(sb.toString());
+        innerClass.addMethod(method);
+
+        sb.setLength(0);
+        sb.append("add"); //$NON-NLS-1$
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
+        sb.append("Criterion"); //$NON-NLS-1$
+
+        method = new Method();
+        method.setVisibility(JavaVisibility.PROTECTED);
+        method.setName(sb.toString());
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "condition")); //$NON-NLS-1$
+        method.addParameter(new Parameter(introspectedColumn
+                .getFullyQualifiedJavaType(), "value1")); //$NON-NLS-1$
+        method.addParameter(new Parameter(introspectedColumn
+                .getFullyQualifiedJavaType(), "value2")); //$NON-NLS-1$
+        method.addParameter(new Parameter(FullyQualifiedJavaType
+                .getStringInstance(), "property")); //$NON-NLS-1$
+        method.addBodyLine("if (value1 == null || value2 == null) {"); //$NON-NLS-1$
+        method
+                .addBodyLine("throw new RuntimeException(\"Between values for \" + property + \" cannot be null\");"); //$NON-NLS-1$
+        method.addBodyLine("}"); //$NON-NLS-1$
+        if (generateForJava5) {
+            sb.setLength(0);
+            sb.append("List<"); //$NON-NLS-1$
+            sb.append(introspectedColumn.getFullyQualifiedJavaType().getShortName());
+            sb.append("> list = new ArrayList<"); //$NON-NLS-1$
+            sb.append(introspectedColumn.getFullyQualifiedJavaType().getShortName());
+            sb.append(">();"); //$NON-NLS-1$
+            method.addBodyLine(sb.toString());
+        } else {
+            method.addBodyLine("List list = new ArrayList();"); //$NON-NLS-1$
+        }
+        method.addBodyLine("list.add(value1);"); //$NON-NLS-1$
+        method.addBodyLine("list.add(value2);"); //$NON-NLS-1$
+        if (generateForJava5) {
+            method.addBodyLine("Map<String, Object> map = new HashMap<String, Object>();"); //$NON-NLS-1$
+        } else {
+            method.addBodyLine("Map map = new HashMap();"); //$NON-NLS-1$
+        }
+        method.addBodyLine("map.put(\"condition\", condition);"); //$NON-NLS-1$
+        method.addBodyLine("map.put(\"values\", list);"); //$NON-NLS-1$
+
+        sb.setLength(0);
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.append("CriteriaWithBetweenValue.add(map);"); //$NON-NLS-1$
+        method.addBodyLine(sb.toString());
+        innerClass.addMethod(method);
+
+        return answer;
+    }
+
+    private Method getSetNullMethod(IntrospectedColumn introspectedColumn) {
+        return getNoValueMethod(introspectedColumn, "IsNull", "is null"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSetNotNullMethod(IntrospectedColumn introspectedColumn) {
+        return getNoValueMethod(introspectedColumn, "IsNotNull", "is not null"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSetEqualMethod(IntrospectedColumn introspectedColumn) {
+        return getSingleValueMethod(introspectedColumn, "EqualTo", "="); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSetNotEqualMethod(IntrospectedColumn introspectedColumn) {
+        return getSingleValueMethod(introspectedColumn, "NotEqualTo", "<>"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSetGreaterThanMethod(IntrospectedColumn introspectedColumn) {
+        return getSingleValueMethod(introspectedColumn, "GreaterThan", ">"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSetGreaterThenOrEqualMethod(IntrospectedColumn introspectedColumn) {
+        return getSingleValueMethod(introspectedColumn, "GreaterThanOrEqualTo", ">="); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSetLessThanMethod(IntrospectedColumn introspectedColumn) {
+        return getSingleValueMethod(introspectedColumn, "LessThan", "<"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSetLessThanOrEqualMethod(IntrospectedColumn introspectedColumn) {
+        return getSingleValueMethod(introspectedColumn, "LessThanOrEqualTo", "<="); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSetLikeMethod(IntrospectedColumn introspectedColumn) {
+        return getSingleValueMethod(introspectedColumn, "Like", "like"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSetNotLikeMethod(IntrospectedColumn introspectedColumn) {
+        return getSingleValueMethod(introspectedColumn, "NotLike", "not like"); //$NON-NLS-1$ //$NON-NLS-2$
+    }
+
+    private Method getSingleValueMethod(IntrospectedColumn introspectedColumn,
+            String nameFragment, String operator) {
+        Method method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        method.addParameter(new Parameter(introspectedColumn
+                .getFullyQualifiedJavaType(), "value")); //$NON-NLS-1$
+        StringBuilder sb = new StringBuilder();
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
+        sb.insert(0, "and"); //$NON-NLS-1$
+        sb.append(nameFragment);
+        method.setName(sb.toString());
+        method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
+        sb.setLength(0);
+
+        if (introspectedColumn.isJDBCDateColumn()) {
+            sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
+        } else if (introspectedColumn.isJDBCTimeColumn()) {
+            sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
+        } else if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
+            sb.append("add"); //$NON-NLS-1$
+            sb.append(introspectedColumn.getJavaProperty());
+            sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
+            sb.append("Criterion(\""); //$NON-NLS-1$
+        } else {
+            sb.append("addCriterion(\""); //$NON-NLS-1$
+        }
+
+        sb.append(introspectedColumn.getAliasedActualColumnName());
+        sb.append(' ');
+        sb.append(operator);
+        sb.append("\", "); //$NON-NLS-1$
+
+        if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
+            sb.append("new "); //$NON-NLS-1$
+            sb.append(introspectedColumn.getFullyQualifiedJavaType()
+                    .getPrimitiveTypeWrapper().getShortName());
+            sb.append("(value)"); //$NON-NLS-1$
+        } else {
+            sb.append("value"); //$NON-NLS-1$
+        }
+
+        sb.append(", \""); //$NON-NLS-1$
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.append("\");"); //$NON-NLS-1$
+        method.addBodyLine(sb.toString());
+        method.addBodyLine("return this;"); //$NON-NLS-1$
+
+        return method;
+    }
+
+    /**
+     * Generates methods that set between and not between conditions
+     * 
+     * @param introspectedColumn
+     * @param betweenMethod
+     * @return a generated method for the between or not between method
+     */
+    private Method getSetBetweenOrNotBetweenMethod(IntrospectedColumn introspectedColumn,
+            boolean betweenMethod) {
+        Method method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        FullyQualifiedJavaType type = introspectedColumn
+                .getFullyQualifiedJavaType();
+
+        method.addParameter(new Parameter(type, "value1")); //$NON-NLS-1$
+        method.addParameter(new Parameter(type, "value2")); //$NON-NLS-1$
+        StringBuilder sb = new StringBuilder();
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
+        sb.insert(0, "and"); //$NON-NLS-1$
+        if (betweenMethod) {
+            sb.append("Between"); //$NON-NLS-1$
+        } else {
+            sb.append("NotBetween"); //$NON-NLS-1$
+        }
+        method.setName(sb.toString());
+        method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
+        sb.setLength(0);
+
+        if (introspectedColumn.isJDBCDateColumn()) {
+            sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
+        } else if (introspectedColumn.isJDBCTimeColumn()) {
+            sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
+        } else if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
+            sb.append("add"); //$NON-NLS-1$
+            sb.append(introspectedColumn.getJavaProperty());
+            sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
+            sb.append("Criterion(\""); //$NON-NLS-1$
+        } else {
+            sb.append("addCriterion(\""); //$NON-NLS-1$
+        }
+
+        sb.append(introspectedColumn.getAliasedActualColumnName());
+        if (betweenMethod) {
+            sb.append(" between"); //$NON-NLS-1$
+        } else {
+            sb.append(" not between"); //$NON-NLS-1$
+        }
+        sb.append("\", "); //$NON-NLS-1$
+        if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
+            sb.append("new "); //$NON-NLS-1$
+            sb.append(introspectedColumn.getFullyQualifiedJavaType()
+                    .getPrimitiveTypeWrapper().getShortName());
+            sb.append("(value1), "); //$NON-NLS-1$
+            sb.append("new "); //$NON-NLS-1$
+            sb.append(introspectedColumn.getFullyQualifiedJavaType()
+                    .getPrimitiveTypeWrapper().getShortName());
+            sb.append("(value2)"); //$NON-NLS-1$
+        } else {
+            sb.append("value1, value2"); //$NON-NLS-1$
+        }
+
+        sb.append(", \""); //$NON-NLS-1$
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.append("\");"); //$NON-NLS-1$
+        method.addBodyLine(sb.toString());
+        method.addBodyLine("return this;"); //$NON-NLS-1$
+
+        return method;
+    }
+
+    /**
+     * 
+     * @param introspectedColumn
+     * @param inMethod
+     *            if true generates an "in" method, else generates a "not in"
+     *            method
+     * @return a generated method for the in or not in method
+     */
+    private Method getSetInOrNotInMethod(IntrospectedColumn introspectedColumn, boolean inMethod) {
+        Method method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        FullyQualifiedJavaType type = FullyQualifiedJavaType
+                .getNewListInstance();
+        if (generateForJava5) {
+            if (introspectedColumn.getFullyQualifiedJavaType().isPrimitive()) {
+                type.addTypeArgument(introspectedColumn
+                        .getFullyQualifiedJavaType().getPrimitiveTypeWrapper());
+            } else {
+                type.addTypeArgument(introspectedColumn
+                        .getFullyQualifiedJavaType());
+            }
+        }
+        
+        method.addParameter(new Parameter(type, "values")); //$NON-NLS-1$
+        StringBuilder sb = new StringBuilder();
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
+        sb.insert(0, "and"); //$NON-NLS-1$
+        if (inMethod) {
+            sb.append("In"); //$NON-NLS-1$
+        } else {
+            sb.append("NotIn"); //$NON-NLS-1$
+        }
+        method.setName(sb.toString());
+        method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
+        sb.setLength(0);
+
+        if (introspectedColumn.isJDBCDateColumn()) {
+            sb.append("addCriterionForJDBCDate(\""); //$NON-NLS-1$
+        } else if (introspectedColumn.isJDBCTimeColumn()) {
+            sb.append("addCriterionForJDBCTime(\""); //$NON-NLS-1$
+        } else if (StringUtility.stringHasValue(introspectedColumn.getTypeHandler())) {
+            sb.append("add"); //$NON-NLS-1$
+            sb.append(introspectedColumn.getJavaProperty());
+            sb.setCharAt(3, Character.toUpperCase(sb.charAt(3)));
+            sb.append("Criterion(\""); //$NON-NLS-1$
+        } else {
+            sb.append("addCriterion(\""); //$NON-NLS-1$
+        }
+
+        sb.append(introspectedColumn.getAliasedActualColumnName());
+        if (inMethod) {
+            sb.append(" in"); //$NON-NLS-1$
+        } else {
+            sb.append(" not in"); //$NON-NLS-1$
+        }
+        sb.append("\", values, \""); //$NON-NLS-1$
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.append("\");"); //$NON-NLS-1$
+        method.addBodyLine(sb.toString());
+        method.addBodyLine("return this;"); //$NON-NLS-1$
+
+        return method;
+    }
+
+    private Method getNoValueMethod(IntrospectedColumn introspectedColumn, String nameFragment,
+            String operator) {
+        Method method = new Method();
+        method.setVisibility(JavaVisibility.PUBLIC);
+        StringBuilder sb = new StringBuilder();
+        sb.append(introspectedColumn.getJavaProperty());
+        sb.setCharAt(0, Character.toUpperCase(sb.charAt(0)));
+        sb.insert(0, "and"); //$NON-NLS-1$
+        sb.append(nameFragment);
+        method.setName(sb.toString());
+        method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
+        sb.setLength(0);
+        sb.append("addCriterion(\""); //$NON-NLS-1$
+        sb.append(introspectedColumn.getAliasedActualColumnName());
+        sb.append(' ');
+        sb.append(operator);
+        sb.append("\");"); //$NON-NLS-1$
+        method.addBodyLine(sb.toString());
+        method.addBodyLine("return this;"); //$NON-NLS-1$
+
+        return method;
+    }
+
+    public int getNumberOfSubtasks() {
+        return 1;
+    }
+}

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/PrimaryKeyGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/PrimaryKeyGenerator.java?rev=703569&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/PrimaryKeyGenerator.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/model/PrimaryKeyGenerator.java Fri Oct 10 13:08:10 2008
@@ -0,0 +1,97 @@
+/*
+ *  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.generator.ibatis2.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.ibatis.ibator.api.CommentGenerator;
+import org.apache.ibatis.ibator.api.FullyQualifiedTable;
+import org.apache.ibatis.ibator.api.IbatorPlugin;
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.java.CompilationUnit;
+import org.apache.ibatis.ibator.api.dom.java.Field;
+import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
+import org.apache.ibatis.ibator.api.dom.java.JavaVisibility;
+import org.apache.ibatis.ibator.api.dom.java.Method;
+import org.apache.ibatis.ibator.api.dom.java.TopLevelClass;
+import org.apache.ibatis.ibator.generator.JavaGenerator;
+import org.apache.ibatis.ibator.internal.util.messages.Messages;
+
+/**
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class PrimaryKeyGenerator extends BaseModelClassGenerator implements JavaGenerator {
+
+    public PrimaryKeyGenerator() {
+        super();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ibatis.ibator.generator.ibatis2.model.ModelGenerator#getTopLevelClass(org.apache.ibatis.ibator.api.IntrospectedTable, java.util.List)
+     */
+    public List<CompilationUnit> getCompilationUnits() {
+        FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
+        progressCallback.startSubTask(Messages.getString("Progress.7", table.toString()));
+        IbatorPlugin plugins = ibatorContext.getPlugins();
+        CommentGenerator commentGenerator = ibatorContext.getCommentGenerator();
+        
+        FullyQualifiedJavaType type = introspectedTable.getPrimaryKeyType();
+        TopLevelClass topLevelClass = new TopLevelClass(type);
+        topLevelClass.setVisibility(JavaVisibility.PUBLIC);
+        commentGenerator.addJavaFileComment(topLevelClass);
+
+        String rootClass = getRootClass();
+        if (rootClass != null) {
+            topLevelClass.setSuperClass(new FullyQualifiedJavaType(rootClass));
+            topLevelClass.addImportedType(topLevelClass.getSuperClass());
+        }
+        
+        for (IntrospectedColumn introspectedColumn : introspectedTable.getPrimaryKeyColumns()) {
+            if (RootClassInfo.getInstance(rootClass, warnings).containsProperty(introspectedColumn)) {
+                continue;
+            }
+            
+            Field field = getJavaBeansField(introspectedColumn);
+            if (plugins.modelFieldGenerated(field, topLevelClass, introspectedColumn, introspectedTable)) {
+                topLevelClass.addField(field);
+                topLevelClass.addImportedType(field.getType());
+            }
+            
+            Method method = getJavaBeansGetter(introspectedColumn);
+            if (plugins.modelGetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable)) {
+                topLevelClass.addMethod(method);
+            }
+            
+            method = getJavaBeansSetter(introspectedColumn);
+            if (plugins.modelSetterMethodGenerated(method, topLevelClass, introspectedColumn, introspectedTable)) {
+                topLevelClass.addMethod(method);
+            }
+        }
+
+        List<CompilationUnit> answer = new ArrayList<CompilationUnit>();
+        if (ibatorContext.getPlugins().modelPrimaryKeyClassGenerated(topLevelClass, introspectedTable)) {
+            answer.add(topLevelClass);
+        }
+        return answer;
+    }
+
+    public int getNumberOfSubtasks() {
+        return 1;
+    }
+}



Mime
View raw message