Author: jgbutler Date: Thu Dec 18 09:45:44 2008 New Revision: 727776 URL: http://svn.apache.org/viewvc?rev=727776&view=rev Log: [ibator] add a plugin method to allow alteration of certain fundamental attributes of code generation
Added: ibatis/trunk/java/tools/ibator/core/buildsupport/org/apache/ibatis/ibator/build/test/ ibatis/trunk/java/tools/ibator/core/buildsupport/org/apache/ibatis/ibator/build/test/TestPlugin.java Modified: ibatis/trunk/java/tools/ibator/core/build/build.xml ibatis/trunk/java/tools/ibator/core/build/setupCmdLine.bat ibatis/trunk/java/tools/ibator/core/build/version.properties ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt ibatis/trunk/java/tools/ibator/core/doc/releasing.txt ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ignoreColumn.html ibatis/trunk/java/tools/ibator/core/htmldoc/reference/pluggingIn.html ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPlugin.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPluginAdapter.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/IbatorPluginAggregator.java ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/execute/miscellaneous/MiscellaneousTests.java ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/ibatorConfig.xml Modified: ibatis/trunk/java/tools/ibator/core/build/build.xml URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/build.xml?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/build/build.xml (original) +++ ibatis/trunk/java/tools/ibator/core/build/build.xml Thu Dec 18 09:45:44 2008 @@ -41,6 +41,7 @@ <path id="emma.runtime.path"> <pathelement location="${work.instrumented}"/> <pathelement location="${work.classes}"/> + <pathelement location="${work.buildsupport}"/> <path refid="emma.lib"/> </path> @@ -77,7 +78,7 @@ </fileset> </copy> - <propertyfile file="version.properties" comment="ibator build version info"> + <propertyfile file="version.properties" comment="Ibator build version info"> <entry key="buildNum" default="0" type="int" operation="+" value="1"/> </propertyfile> </target> Modified: ibatis/trunk/java/tools/ibator/core/build/setupCmdLine.bat URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/setupCmdLine.bat?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/build/setupCmdLine.bat (original) +++ ibatis/trunk/java/tools/ibator/core/build/setupCmdLine.bat Thu Dec 18 09:45:44 2008 @@ -1,6 +1,6 @@ rem Change the values in this file to the proper directories on your machine if defined JAVA_HOME goto java_home_defined -set JAVA_HOME=C:\JavaTools\jdk1.5.0_11 +set JAVA_HOME=C:\JavaTools\jdk1.5.0_17 :java_home_defined Modified: ibatis/trunk/java/tools/ibator/core/build/version.properties URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/version.properties?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/build/version.properties (original) +++ ibatis/trunk/java/tools/ibator/core/build/version.properties Thu Dec 18 09:45:44 2008 @@ -1,4 +1,4 @@ -#ibator build version info -#Tue Dec 16 09:32:54 CST 2008 +#Ibator build version info +#Thu Dec 18 11:42:11 CST 2008 version=1.2.1 -buildNum=667 +buildNum=673 Added: ibatis/trunk/java/tools/ibator/core/buildsupport/org/apache/ibatis/ibator/build/test/TestPlugin.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/buildsupport/org/apache/ibatis/ibator/build/test/TestPlugin.java?rev=727776&view=auto ============================================================================== --- ibatis/trunk/java/tools/ibator/core/buildsupport/org/apache/ibatis/ibator/build/test/TestPlugin.java (added) +++ ibatis/trunk/java/tools/ibator/core/buildsupport/org/apache/ibatis/ibator/build/test/TestPlugin.java Thu Dec 18 09:45:44 2008 @@ -0,0 +1,58 @@ +/* + * 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.build.test; + +import java.util.List; + +import org.apache.ibatis.ibator.api.IbatorPluginAdapter; +import org.apache.ibatis.ibator.api.IntrospectedTable; +import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType; + +/** + * This class is used to test certain plugin features during the Ibator build + * + * @author Jeff Butler + * + */ +public class TestPlugin extends IbatorPluginAdapter { + + /** + * + */ + public TestPlugin() { + } + + /* (non-Javadoc) + * @see org.apache.ibatis.ibator.api.IbatorPlugin#validate(java.util.List) + */ + public boolean validate(List<String> warnings) { + return true; + } + + @Override + public void attributesCalculated(IntrospectedTable introspectedTable) { + StringBuilder sb = new StringBuilder(); + sb.append(introspectedTable.getJavaModelPackage()); + sb.append('.'); + sb.append(introspectedTable.getFullyQualifiedTable().getDomainObjectName()); + sb.append("Criteria"); //$NON-NLS-1$ + + FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); + + introspectedTable.setAttribute(IntrospectedTable.ATTR_EXAMPLE_TYPE, fqjt); + } +} Modified: ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt (original) +++ ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt Thu Dec 18 09:45:44 2008 @@ -10,6 +10,9 @@ 1. Modified plugin methods for model fields, getters, and setters so that the plugin will know which type of class (Primary Key, Base Record, or Record with BLOBs) is being generated. +2. Added methods to IntrospectedTable to get/set attributes. This + allows plugin classes to maintain table based state between + plugin calls. ------------------------------------------------------------------------------- Version 1.2.0: Renamed to Ibator Modified: ibatis/trunk/java/tools/ibator/core/doc/releasing.txt URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/doc/releasing.txt?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/doc/releasing.txt (original) +++ ibatis/trunk/java/tools/ibator/core/doc/releasing.txt Thu Dec 18 09:45:44 2008 @@ -1,29 +1,41 @@ -Releasing ibator: +Releasing Ibator: -1. Build and test the base ibator (make sure to use JDK 5.0) +1. Increment the version number of Ibator in version.properties -2. Move the base JAR and src JAR into the appropriate eclipse project +2. Build and test the base Ibator (make sure to use JDK 5.0) -3. Build the new version of the plugin: +3. Build the new version of the Eclipse feature: + - Copy new ibator.jar and ibator-src.zip into the core plugin + - Increment the version number of the feature + - Increment the version number of any plugin that has changed - Build the doc - - Build the update site + - Add the new version of the feature to site.xml in the IbatorUpdateSite + project + - Build the update site (just the new version, not build all) + - Delete the files artifacts.xml and content.xml generated by the + site builder (these files do not properly categorize the features. + See Eclipse bug 227675 for a possible solution in release 3.5) + - Do SVN Revert on any old plugin versions that were regenerated by the + site build process -4. Zip the contents of the update site +4. Run through the manual test scripts for the Eclipse feature + +5. Zip the contents of the update site (remove project metadata) -5. Commit everything +6. Commit everything -6. Make an SVN label +7. Make an SVN label -7. Put the new base JAR file in /www/people.apache.org/builds/ibatis/alpha +8. Put the new base Ibator zip file in /www/people.apache.org/builds/ibatis/alpha -8. Put the new zipped eclipse site in /www/people.apache.org/builds/ibatis/alpha +9. Put the new zipped eclipse site in /www/people.apache.org/builds/ibatis/alpha -9. Update /www/ibatis.apache.org/doc/tools/ibator from SVN (this updates the documentation) +10. Update /www/ibatis.apache.org/doc/tools/ibator from SVN (this updates the documentation) -10. Update /www/ibatis.apache.org/tools/ibator from SVN (this updates the Eclipse site) +11. Update /www/ibatis.apache.org/tools/ibator from SVN (this updates the Eclipse site) -11. Update the DTD (if required) +12. Update the DTD (if required) -12. Update the web site +13. Update the iBATIS web site -13. Send out the announcement +14. Send out the announcement to dev@ and user@ Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ignoreColumn.html URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ignoreColumn.html?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ignoreColumn.html (original) +++ ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ignoreColumn.html Thu Dec 18 09:45:44 2008 @@ -35,7 +35,18 @@ </table> <h2>Optional Attributes</h2> -<p>None</p> +<table border="1" cellspacing="0" cellpadding="5"> + <tr> + <th>Attribute</th> + <th>Description</th> + </tr> + <tr> + <td>delimitedColumnName</td> + <td>If <code>true</code> then Ibator will perform a case-sensitive exact + match when matching against returned columns from the database. If + <code>false</code> (default) then the name is considered case-insensitive.</td> + </tr> +</table> <h2>Child Elements</h2> <p>None</p> Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/reference/pluggingIn.html URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/reference/pluggingIn.html?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/htmldoc/reference/pluggingIn.html (original) +++ ibatis/trunk/java/tools/ibator/core/htmldoc/reference/pluggingIn.html Thu Dec 18 09:45:44 2008 @@ -37,6 +37,7 @@ then no further methods in the plugin will be called</li> <li>For each table in the configuration: <ol type="a"> + <li><code>attributesCalculated</code> method called</li> <li>DAO Methods:<sup>1,2</sup> <ol type="i"> <li><code>daoXXXMethodGenerated(Method, TopLevelClass, IntrospectedTable)</code> - these methods Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html (original) +++ ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html Thu Dec 18 09:45:44 2008 @@ -28,8 +28,14 @@ <li>Modified plugin methods for model fields, getters, and setters so that the plugin will know which type of class (Primary Key, Base Record, or Record with BLOBs) is being generated.</li> + <li>Added methods to IntrospectedTable to get/set attributes. This + allows plugin classes to maintain table based state between + plugin calls.</li> + <li>Added <code>attributesCalculated</code> method to the plugin API. This + allows plugins to alter some of the fundamental code generation items + (like the name of a generated class, for example).</li> </ul> - + <h2>Version 1.2.0</h2> <h3>Announcements</h3> <ul> Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPlugin.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPlugin.java?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPlugin.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPlugin.java Thu Dec 18 09:45:44 2008 @@ -37,6 +37,7 @@ * <ol> * <li>The setXXX methods are called one time</li> * <li>The validate method is called one time</li> + * <li>The attributesCalculated method is called for each introspected table</li> * <li>The daoXXX methods are called for each introspected table</li> * <li>The modelXXX methods are called for each introspected table</li> * <li>The sqlMapXXX methods are called for each introspected table</li> @@ -87,6 +88,28 @@ void setProperties(Properties properties); /** + * This method is called after the IntrospectedTable calculates all + * the attributes for code generation. Attributes are listed as + * static Strings with the prefix ATTR_ in IntrospectedTable. Plugins + * can implement this method to override any of the default attributes, + * or to add additional attributes for use by other plugin methods. + * <p> + * A good example of overriding an attribute would be the case where + * a user wanted to change the name of one of the generated classes, + * change the target package, or change the name of the generated SQL map file. + * <p> + * <b>Warning:</b> Anything that is listed as an attribute should + * not be changed by one of the other plugin methods. For example, + * if you want to change the name of a generated example class, you + * should not simply change the Type in the + * <code>modelExampleClassGenerated()</code> method. If you do, the + * change will not be reflected in other generated artifacts. + * + * @param introspectedTable + */ + void attributesCalculated(IntrospectedTable introspectedTable); + + /** * This method is called after all the setXXX methods are called, but before any * other method is called. This allows the plugin to determine whether * it can run or not. For example, if the plugin requires certain properties Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPluginAdapter.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPluginAdapter.java?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPluginAdapter.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorPluginAdapter.java Thu Dec 18 09:45:44 2008 @@ -303,4 +303,7 @@ public boolean daoInsertSelectiveMethodGenerated(Method method, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) { return true; } + + public void attributesCalculated(IntrospectedTable introspectedTable) { + } } Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IntrospectedTable.java Thu Dec 18 09:45:44 2008 @@ -17,8 +17,10 @@ package org.apache.ibatis.ibator.api; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType; import org.apache.ibatis.ibator.config.DAOGeneratorConfiguration; @@ -45,6 +47,67 @@ * */ public abstract class IntrospectedTable { + /** + * This attribute must be a class of type java.lang.String + */ + public static final String ATTR_DAO_IMPLEMENTATION_PACKAGE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_DAO_IMPLEMENTATION_PACKAGE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type java.lang.String + */ + public static final String ATTR_DAO_INTERFACE_PACKAGE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_DAO_INTERFACE_PACKAGE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type + * org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType + */ + public static final String ATTR_DAO_IMPLEMENTATION_TYPE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_DAO_IMPLEMENTATION_TYPE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type + * org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType + */ + public static final String ATTR_DAO_INTERFACE_TYPE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_DAO_INTERFACE_TYPE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type java.lang.String + */ + public static final String ATTR_JAVA_MODEL_PACKAGE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_JAVA_MODEL_PACKAGE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type + * org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType + */ + public static final String ATTR_PRIMARY_KEY_TYPE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_PRIMARY_KEY_TYPE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type + * org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType + */ + public static final String ATTR_BASE_RECORD_TYPE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_BASE_RECORD_TYPE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type + * org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType + */ + public static final String ATTR_RECORD_WITH_BLOBS_TYPE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_RECORD_WITH_BLOBS_TYPE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type + * org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType + */ + public static final String ATTR_EXAMPLE_TYPE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_EXAMPLE_TYPE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type java.lang.String + */ + public static final String ATTR_SQL_MAP_PACKAGE = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_SQL_MAP_PACKAGE"; //$NON-NLS-1$ + + /** + * This attribute must be a class of type java.lang.String + */ + public static final String ATTR_SQL_MAP_FILE_NAME = "org.apache.ibatis.ibator.api.IntrospectedTable.ATTR_SQL_MAP_FILE_NAME"; //$NON-NLS-1$ + protected TableConfiguration tableConfiguration; protected FullyQualifiedTable fullyQualifiedTable; protected IbatorContext ibatorContext; @@ -55,11 +118,19 @@ protected boolean hasJDBCDateColumns; protected boolean hasJDBCTimeColumns; + /** + * Attributes may be used by plugins to capture table related state + * between the different plugin calls. Attibutes also are used + * to store commonly accessed items by all code generators + */ + protected Map<String, Object> attributes; + public IntrospectedTable() { super(); primaryKeyColumns = new ArrayList<IntrospectedColumn>(); baseColumns = new ArrayList<IntrospectedColumn>(); blobColumns = new ArrayList<IntrospectedColumn>(); + attributes = new HashMap<String, Object>(); } public FullyQualifiedTable getFullyQualifiedTable() { @@ -241,15 +312,7 @@ } public FullyQualifiedJavaType getPrimaryKeyType() { - StringBuilder sb = new StringBuilder(); - sb.append(getJavaModelPackage()); - sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("Key"); //$NON-NLS-1$ - - FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); - - return fqjt; + return (FullyQualifiedJavaType) getAttribute(ATTR_PRIMARY_KEY_TYPE); } /** @@ -259,14 +322,7 @@ * the value will be calculated regardless of whether the table has these columns or not. */ public FullyQualifiedJavaType getBaseRecordType() { - StringBuilder sb = new StringBuilder(); - sb.append(getJavaModelPackage()); - sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - - FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); - - return fqjt; + return (FullyQualifiedJavaType) getAttribute(ATTR_BASE_RECORD_TYPE); } /** @@ -274,15 +330,7 @@ * @return the type for the example class. */ public FullyQualifiedJavaType getExampleType() { - StringBuilder sb = new StringBuilder(); - sb.append(getJavaModelPackage()); - sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("Example"); //$NON-NLS-1$ - - FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); - - return fqjt; + return (FullyQualifiedJavaType) getAttribute(ATTR_EXAMPLE_TYPE); } /** @@ -291,15 +339,7 @@ * the value will be calculated regardless of whether the table has BLOB columns or not. */ public FullyQualifiedJavaType getRecordWithBLOBsType() { - StringBuilder sb = new StringBuilder(); - sb.append(getJavaModelPackage()); - sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("WithBLOBs"); //$NON-NLS-1$ - - FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); - - return fqjt; + return (FullyQualifiedJavaType) getAttribute(ATTR_RECORD_WITH_BLOBS_TYPE); } /** @@ -310,11 +350,7 @@ * @return the name of the SqlMap file */ public String getSqlMapFileName() { - StringBuilder sb = new StringBuilder(); - sb.append(fullyQualifiedTable.getSqlMapNamespace()); - sb.append("_SqlMap.xml"); //$NON-NLS-1$ - - return sb.toString(); + return (String) getAttribute(ATTR_SQL_MAP_FILE_NAME); } /** @@ -323,38 +359,15 @@ * @return the package for the SqlMap for the current table */ public String getSqlMapPackage() { - SqlMapGeneratorConfiguration config = ibatorContext.getSqlMapGeneratorConfiguration(); - - StringBuilder sb = new StringBuilder(config.getTargetPackage()); - if (StringUtility.isTrue(config.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES))) { - sb.append(fullyQualifiedTable.getSubPackage()); - } - - return sb.toString(); + return (String) getAttribute(ATTR_SQL_MAP_PACKAGE); } public FullyQualifiedJavaType getDAOImplementationType() { - StringBuilder sb = new StringBuilder(); - sb.append(getDAOImplementationPackage()); - sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("DAOImpl"); //$NON-NLS-1$ - - FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); - - return fqjt; + return (FullyQualifiedJavaType) getAttribute(ATTR_DAO_IMPLEMENTATION_TYPE); } public FullyQualifiedJavaType getDAOInterfaceType() { - StringBuilder sb = new StringBuilder(); - sb.append(getDAOInterfacePackage()); - sb.append('.'); - sb.append(fullyQualifiedTable.getDomainObjectName()); - sb.append("DAO"); //$NON-NLS-1$ - - FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); - - return fqjt; + return (FullyQualifiedJavaType) getAttribute(ATTR_DAO_INTERFACE_TYPE); } public boolean hasAnyColumns() { @@ -364,43 +377,15 @@ } public String getDAOInterfacePackage() { - DAOGeneratorConfiguration config = ibatorContext.getDaoGeneratorConfiguration(); - - StringBuilder sb = new StringBuilder(); - sb.append(config.getTargetPackage()); - if (StringUtility.isTrue(config.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES))) { - sb.append(fullyQualifiedTable.getSubPackage()); - } - - return sb.toString(); + return (String) getAttribute(ATTR_DAO_INTERFACE_PACKAGE); } public String getDAOImplementationPackage() { - DAOGeneratorConfiguration config = ibatorContext.getDaoGeneratorConfiguration(); - - StringBuilder sb = new StringBuilder(); - if (StringUtility.stringHasValue(config.getImplementationPackage())) { - sb.append(config.getImplementationPackage()); - } else { - sb.append(config.getTargetPackage()); - } - if (StringUtility.isTrue(config.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES))) { - sb.append(fullyQualifiedTable.getSubPackage()); - } - - return sb.toString(); + return (String) getAttribute(ATTR_DAO_IMPLEMENTATION_PACKAGE); } public String getJavaModelPackage() { - JavaModelGeneratorConfiguration config = ibatorContext.getJavaModelGeneratorConfiguration(); - - StringBuilder sb = new StringBuilder(); - sb.append(config.getTargetPackage()); - if (StringUtility.isTrue(config.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES))) { - sb.append(fullyQualifiedTable.getSubPackage()); - } - - return sb.toString(); + return (String) getAttribute(ATTR_JAVA_MODEL_PACKAGE); } public void setTableConfiguration(TableConfiguration tableConfiguration) { @@ -462,6 +447,166 @@ } } + public Object getAttribute(String name) { + return attributes.get(name); + } + + public void removeAttribute(String name) { + attributes.remove(name); + } + + public void setAttribute(String name, Object value) { + attributes.put(name, value); + } + + public void calculateAttributes() { + calculateDAOImplementationPackage(); + calculateDAOInterfacePackage(); + calculateDAOImplementationType(); + calculateDAOInterfaceType(); + + calculateJavaModelPackage(); + calculatePrimaryKeyType(); + calculateBaseRecordType(); + calculateRecordWithBLOBsType(); + calculateExampleType(); + + calculateSqlMapPackage(); + calculateSqlMapFileName(); + + ibatorContext.getPlugins().attributesCalculated(this); + } + + private void calculateDAOImplementationPackage() { + DAOGeneratorConfiguration config = ibatorContext.getDaoGeneratorConfiguration(); + + StringBuilder sb = new StringBuilder(); + if (StringUtility.stringHasValue(config.getImplementationPackage())) { + sb.append(config.getImplementationPackage()); + } else { + sb.append(config.getTargetPackage()); + } + if (StringUtility.isTrue(config.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES))) { + sb.append(fullyQualifiedTable.getSubPackage()); + } + + setAttribute(ATTR_DAO_IMPLEMENTATION_PACKAGE, sb.toString()); + } + + private void calculateDAOInterfacePackage() { + DAOGeneratorConfiguration config = ibatorContext.getDaoGeneratorConfiguration(); + + StringBuilder sb = new StringBuilder(); + sb.append(config.getTargetPackage()); + if (StringUtility.isTrue(config.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES))) { + sb.append(fullyQualifiedTable.getSubPackage()); + } + + setAttribute(ATTR_DAO_INTERFACE_PACKAGE, sb.toString()); + } + + private void calculateDAOImplementationType() { + StringBuilder sb = new StringBuilder(); + sb.append(getDAOImplementationPackage()); + sb.append('.'); + sb.append(fullyQualifiedTable.getDomainObjectName()); + sb.append("DAOImpl"); //$NON-NLS-1$ + + FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); + + setAttribute(ATTR_DAO_IMPLEMENTATION_TYPE, fqjt); + } + + private void calculateDAOInterfaceType() { + StringBuilder sb = new StringBuilder(); + sb.append(getDAOInterfacePackage()); + sb.append('.'); + sb.append(fullyQualifiedTable.getDomainObjectName()); + sb.append("DAO"); //$NON-NLS-1$ + + FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); + + setAttribute(ATTR_DAO_INTERFACE_TYPE, fqjt); + } + + private void calculateJavaModelPackage() { + JavaModelGeneratorConfiguration config = ibatorContext.getJavaModelGeneratorConfiguration(); + + StringBuilder sb = new StringBuilder(); + sb.append(config.getTargetPackage()); + if (StringUtility.isTrue(config.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES))) { + sb.append(fullyQualifiedTable.getSubPackage()); + } + + setAttribute(ATTR_JAVA_MODEL_PACKAGE, sb.toString()); + } + + private void calculatePrimaryKeyType() { + StringBuilder sb = new StringBuilder(); + sb.append(getJavaModelPackage()); + sb.append('.'); + sb.append(fullyQualifiedTable.getDomainObjectName()); + sb.append("Key"); //$NON-NLS-1$ + + FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); + + setAttribute(ATTR_PRIMARY_KEY_TYPE, fqjt); + } + + private void calculateBaseRecordType() { + StringBuilder sb = new StringBuilder(); + sb.append(getJavaModelPackage()); + sb.append('.'); + sb.append(fullyQualifiedTable.getDomainObjectName()); + + FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); + + setAttribute(ATTR_BASE_RECORD_TYPE, fqjt); + } + + private void calculateRecordWithBLOBsType() { + StringBuilder sb = new StringBuilder(); + sb.append(getJavaModelPackage()); + sb.append('.'); + sb.append(fullyQualifiedTable.getDomainObjectName()); + sb.append("WithBLOBs"); //$NON-NLS-1$ + + FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); + + setAttribute(ATTR_RECORD_WITH_BLOBS_TYPE, fqjt); + } + + private void calculateExampleType() { + StringBuilder sb = new StringBuilder(); + sb.append(getJavaModelPackage()); + sb.append('.'); + sb.append(fullyQualifiedTable.getDomainObjectName()); + sb.append("Example"); //$NON-NLS-1$ + + FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(sb.toString()); + + setAttribute(ATTR_EXAMPLE_TYPE, fqjt); + } + + private void calculateSqlMapPackage() { + SqlMapGeneratorConfiguration config = ibatorContext.getSqlMapGeneratorConfiguration(); + + StringBuilder sb = new StringBuilder(config.getTargetPackage()); + if (StringUtility.isTrue(config.getProperty(PropertyRegistry.ANY_ENABLE_SUB_PACKAGES))) { + sb.append(fullyQualifiedTable.getSubPackage()); + } + + setAttribute(ATTR_SQL_MAP_PACKAGE, sb.toString());; + } + + private void calculateSqlMapFileName() { + StringBuilder sb = new StringBuilder(); + sb.append(fullyQualifiedTable.getSqlMapNamespace()); + sb.append("_SqlMap.xml"); //$NON-NLS-1$ + + setAttribute(ATTR_SQL_MAP_FILE_NAME, sb.toString()); + } + /** * This method can be used to initialize the generators before they * will be called. Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/config/IbatorContext.java Thu Dec 18 09:45:44 2008 @@ -494,6 +494,7 @@ for (IntrospectedTable introspectedTable : introspectedTables) { callback.checkCancel(); + introspectedTable.calculateAttributes(); generatedJavaFiles.addAll(introspectedTable.getGeneratedJavaFiles()); generatedXmlFiles.addAll(introspectedTable.getGeneratedXmlFiles()); Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/IbatorPluginAggregator.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/IbatorPluginAggregator.java?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/IbatorPluginAggregator.java (original) +++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/internal/IbatorPluginAggregator.java Thu Dec 18 09:45:44 2008 @@ -944,4 +944,10 @@ return rc; } + + public void attributesCalculated(IntrospectedTable introspectedTable) { + for (IbatorPlugin plugin : plugins) { + plugin.attributesCalculated(introspectedTable); + } + } } Modified: ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/execute/miscellaneous/MiscellaneousTests.java URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/execute/miscellaneous/MiscellaneousTests.java?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/execute/miscellaneous/MiscellaneousTests.java (original) +++ ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/execute/miscellaneous/MiscellaneousTests.java Thu Dec 18 09:45:44 2008 @@ -34,7 +34,7 @@ import ibatortest.generated.miscellaneous.dao.MyObjectDAO; import ibatortest.generated.miscellaneous.dao.RegexrenameDAO; import ibatortest.generated.miscellaneous.model.MyObject; -import ibatortest.generated.miscellaneous.model.MyObjectExample; +import ibatortest.generated.miscellaneous.model.MyObjectCriteria; import ibatortest.generated.miscellaneous.model.MyObjectKey; import ibatortest.generated.miscellaneous.model.Regexrename; @@ -223,7 +223,7 @@ int rows = dao.deleteMyObjectByPrimaryKey(key); assertEquals(1, rows); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); List answer = dao.selectMyObjectByExample(example); assertEquals(0, answer.size()); } catch (SQLException e) { @@ -255,16 +255,16 @@ dao.insertMyObject(record); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); List answer = dao.selectMyObjectByExample(example); assertEquals(2, answer.size()); - example = new MyObjectExample(); + example = new MyObjectCriteria(); example.createCriteria().andLastnameLike("J%"); int rows = dao.deleteMyObjectByExample(example); assertEquals(1, rows); - example = new MyObjectExample(); + example = new MyObjectCriteria(); answer = dao.selectMyObjectByExample(example); assertEquals(1, answer.size()); } catch (SQLException e) { @@ -368,7 +368,7 @@ record.setId2(3); dao.insertMyObject(record); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); fn = new FirstName(); fn.setValue("B%"); example.createCriteria().andFirstnameLike(fn); @@ -448,7 +448,7 @@ record.setId2(3); dao.insertMyObject(record); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); fn = new FirstName(); fn.setValue("B%"); example.createCriteria().andFirstnameNotLike(fn); @@ -528,7 +528,7 @@ record.setId2(3); dao.insertMyObject(record); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); fn = new FirstName(); fn.setValue("B%"); example.createCriteria().andFirstnameLike(fn).andId2EqualTo(3); @@ -612,7 +612,7 @@ ids.add(1); ids.add(3); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); example.createCriteria().andId2In(ids); example.setOrderByClause("ID1, ID2"); @@ -701,7 +701,7 @@ record.setId2(3); dao.insertMyObject(record); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); example.createCriteria().andId2Between(1, 3); example.setOrderByClause("ID1, ID2"); @@ -737,7 +737,7 @@ dao.insertMyObject(record); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); example.createCriteria().andTimefieldEqualTo(myTime); List<MyObject> results = dao.selectMyObjectByExample(example); assertEquals(1, results.size()); @@ -798,7 +798,7 @@ MyObject newRecord = new MyObject(); newRecord.setLastname("Barker"); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); fn = new FirstName(); fn.setValue("B%"); example.createCriteria().andFirstnameLike(fn); @@ -847,7 +847,7 @@ newRecord.setId1(3); newRecord.setId2(4); - MyObjectExample example = new MyObjectExample(); + MyObjectCriteria example = new MyObjectCriteria(); example.createCriteria() .andId1EqualTo(3) .andId2EqualTo(4); Modified: ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/ibatorConfig.xml URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/ibatorConfig.xml?rev=727776&r1=727775&r2=727776&view=diff ============================================================================== --- ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/ibatorConfig.xml (original) +++ ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/ibatorConfig.xml Thu Dec 18 09:45:44 2008 @@ -261,6 +261,7 @@ <ibatorContext id="miscellaneousTests" targetRuntime="Ibatis2Java5"> <ibatorPlugin type="org.apache.ibatis.ibator.plugins.EqualsHashCodePlugin" /> + <ibatorPlugin type="org.apache.ibatis.ibator.build.test.TestPlugin" /> <commentGenerator> <property name="suppressDate" value="true"/>