You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ibatis.apache.org by jg...@apache.org on 2009/02/23 21:58:14 UTC

svn commit: r747134 - in /ibatis/trunk/java/tools/ibator/core: build/ doc/ htmldoc/ htmldoc/configreference/ htmldoc/generatedobjects/ htmldoc/reference/ src/org/apache/ibatis/ibator/api/ src/org/apache/ibatis/ibator/logging/ src/org/apache/ibatis/ibat...

Author: jgbutler
Date: Mon Feb 23 20:58:13 2009
New Revision: 747134

URL: http://svn.apache.org/viewvc?rev=747134&view=rev
Log:
[Ibator] New example plugin for case insensitive LIKE searches

Added:
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/plugins/CaseInsensitiveLikePlugin.java
Modified:
    ibatis/trunk/java/tools/ibator/core/build/version.properties
    ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt
    ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ibatorPlugin.html
    ibatis/trunk/java/tools/ibator/core/htmldoc/generatedobjects/extendingExampleClass.html
    ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html
    ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorRunner.java
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.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/version.properties
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/version.properties?rev=747134&r1=747133&r2=747134&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/build/version.properties (original)
+++ ibatis/trunk/java/tools/ibator/core/build/version.properties Mon Feb 23 20:58:13 2009
@@ -1,4 +1,4 @@
 #Ibator build version info
-#Thu Feb 19 17:02:37 CST 2009
+#Mon Feb 23 14:36:25 CST 2009
 version=1.2.2
-buildNum=711
+buildNum=714

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=747134&r1=747133&r2=747134&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt (original)
+++ ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt Mon Feb 23 20:58:13 2009
@@ -13,6 +13,7 @@
    AVE! for the idea and the initial patch
 4. Added some additional command line arguments
 5. Added logging
+6. Added Case Insensitive LIKE example Plugin
 
 -------------------------------------------------------------------------------
 Version 1.2.1:

Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ibatorPlugin.html
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ibatorPlugin.html?rev=747134&r1=747133&r2=747134&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ibatorPlugin.html (original)
+++ ibatis/trunk/java/tools/ibator/core/htmldoc/configreference/ibatorPlugin.html Mon Feb 23 20:58:13 2009
@@ -40,6 +40,12 @@
     <th>Description</th>
   </tr>
   <tr>
+    <td valign="top"><code>(package).CaseInsensitiveLikePlugin</code></td>
+    <td>This plugin adds methods to the Example class (actually to the Criteria innser class)
+        to support case insensitive LIKE searches.  This demonstrates adding functionality to
+        the example classes via a plugin, rather than extending the class.</td>
+  </tr>
+  <tr>
     <td valign="top"><code>(package).EqualsHashCodePlugin</code></td>
     <td>This plugin adds <code>equals</code> and <code>hashCode</code> methods to the
         Java model objects generated by Ibator.

Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/generatedobjects/extendingExampleClass.html
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/generatedobjects/extendingExampleClass.html?rev=747134&r1=747133&r2=747134&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/htmldoc/generatedobjects/extendingExampleClass.html (original)
+++ ibatis/trunk/java/tools/ibator/core/htmldoc/generatedobjects/extendingExampleClass.html Mon Feb 23 20:58:13 2009
@@ -70,6 +70,14 @@
 <p>Once the basic class is created, adding additional predicates is a matter
 of adding additional methods the the extended <code>Criteria</code> class.</p>
 
+<h2>Extending vs. Plugging In</h2>
+<p>If you find that you are extending the example classes frequently, it might be
+more convenient for you to create an Ibator Plugin to generate the additional
+functionality rather than hand coding the extended classes.  The example below (under
+the heading "Single Parameter Predicates") can also be accomplished with a plugin
+as demonstrated by the class
+<code>org.apache.ibatis.ibator.plugins.CaseInsensitiveLikePlugin</code>.</p>
+
 <h2>Adding Predicates</h2>
 <p>Ibator generates a dynamic SQL fragment that allows virtually unlimited
 where clauses to be created at run-time.  To accomplish this, the generated SQL

Modified: ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html?rev=747134&r1=747133&r2=747134&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html (original)
+++ ibatis/trunk/java/tools/ibator/core/htmldoc/reference/logging.html Mon Feb 23 20:58:13 2009
@@ -46,7 +46,8 @@
 if Log4J is in the runtime classpath, you may specify the <code>-forceJavaLogging</code>
 command line argument, or specify the following line of code when running
 Ibator from Java:</p>
-<p><code>org.apache.ibatis.ibator.logging.LogFactory.selectJavaLogging();</code></p>  
+<p><code>org.apache.ibatis.ibator.logging.LogFactory.forceJavaLogging();</code></p>
+<p><b>Important:</b> You should specify the above line of code <i>before</i> any other Ibator code.</p>
 
 <h2>Configuring Log4J Logging</h2>
 <p>The following is a sample Log4J configuration file:</p>
@@ -81,16 +82,16 @@
 # Specify the handlers to create in the root logger
 # (all loggers are children of the root logger)
 handlers = java.util.logging.ConsoleHandler
-    
+
 # Set the default logging level for the root logger
 .level = INFO
-    
+
 # Set the default logging level for new ConsoleHandler instances
 java.util.logging.ConsoleHandler.level = ALL
-    
+
 # Set the default formatter for new ConsoleHandler instances
 java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
-    
+
 # Set the default logging level for the logger named org.apache.ibatis.ibator
 org.apache.ibatis.ibator.level = FINE
 </pre>

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=747134&r1=747133&r2=747134&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html (original)
+++ ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html Mon Feb 23 20:58:13 2009
@@ -27,12 +27,12 @@
 <h3>Enhancements</h3>
 <ul>
   <li>IBATIS-569 - Modified the IbatorRules implementation to make it easier
-      for plugins to provide custom implementations of IbatorRules.  See the 
+      for plugins to provide custom implementations of IbatorRules.  See the
       Javadoc for the new class
       <code>org.apache.ibatis.ibator.internal.rules.IbatorRulesDelegate</code>
       for more information.</li>
   <li>IBATIS-571 - Added support for automatically delimiting SQL keywords
-      if they are used as column names in tables.  See the 
+      if they are used as column names in tables.  See the
       <a href="configreference/ibatorContext.html">&lt;ibatorContext&gt;</a> page
       for more information.</li>
   <li>IBATIS-577 - Define SQL fragments for column lists to improve
@@ -45,6 +45,10 @@
   <li>Added logging statements for use in debug. See the
      <a href="reference/logging.html">Logging</a> page
       for more information.</li>
+  <li>Added new example plugin to demonstrate adding case insensitive LIKE
+      support to generated Example classes. See the
+     <a href="configreference/ibatorPlugin.html">&lt;ibatorPlugin&gt;</a> page
+      for more information.</li>
 </ul>
 
 <h2>Version 1.2.1</h2>

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorRunner.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorRunner.java?rev=747134&r1=747133&r2=747134&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorRunner.java (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/IbatorRunner.java Mon Feb 23 20:58:13 2009
@@ -174,7 +174,7 @@
             } else if (VERBOSE.equalsIgnoreCase(args[i])) {
                 arguments.put(VERBOSE, "Y"); //$NON-NLS-1$
             } else if (FORCE_JAVA_LOGGING.equalsIgnoreCase(args[i])) {
-                LogFactory.selectJavaLogging();
+                LogFactory.forceJavaLogging();
             } else if (CONTEXT_IDS.equalsIgnoreCase(args[i])) {
                 if ((i + 1) < args.length) {
                     arguments.put(CONTEXT_IDS, args[i + 1]);

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.java?rev=747134&r1=747133&r2=747134&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.java (original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/logging/LogFactory.java Mon Feb 23 20:58:13 2009
@@ -68,7 +68,7 @@
      * intend to use this method you should call it before calling any other
      * Ibator method.
      */
-    public static synchronized void selectJavaLogging() {
+    public static synchronized void forceJavaLogging() {
         try {
             IbatorObjectFactory.internalClassForName("java.util.logging.Logger"); //$NON-NLS-1$
             Class<?> implClass = IbatorObjectFactory.internalClassForName(

Added: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/plugins/CaseInsensitiveLikePlugin.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/plugins/CaseInsensitiveLikePlugin.java?rev=747134&view=auto
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/plugins/CaseInsensitiveLikePlugin.java (added)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/plugins/CaseInsensitiveLikePlugin.java Mon Feb 23 20:58:13 2009
@@ -0,0 +1,109 @@
+/*
+ *  Copyright 2009 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.plugins;
+
+import java.util.List;
+
+import org.apache.ibatis.ibator.api.IbatorPluginAdapter;
+import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.IntrospectedTable;
+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;
+
+/**
+ * This plugin demonstrates adding methods to the example class to
+ * enable case-insensitive LIKE searches.  It shows hows to construct
+ * new methods and add them to an existing class.
+ * 
+ * This plugin only adds methods for String fields mapped to a JDBC
+ * character type (CHAR, VARCHAR, etc.)
+ * 
+ * @author Jeff Butler
+ *
+ */
+public class CaseInsensitiveLikePlugin extends IbatorPluginAdapter {
+
+    /**
+     * 
+     */
+    public CaseInsensitiveLikePlugin() {
+        super();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ibatis.ibator.api.IbatorPlugin#validate(java.util.List)
+     */
+    public boolean validate(List<String> warnings) {
+        return true;
+    }
+
+    @Override
+    public boolean modelExampleClassGenerated(TopLevelClass topLevelClass,
+            IntrospectedTable introspectedTable) {
+        
+        InnerClass criteria = null;
+        // first, find the Criteria inner class
+        for (InnerClass innerClass : topLevelClass.getInnerClasses()) {
+            if ("Criteria".equals(innerClass.getType().getShortName())) {
+                criteria = innerClass;
+                break;
+            }
+        }
+        
+        if (criteria == null) {
+            // can't find the inner class for some reason, bail out.
+            return true;
+        }
+        
+        for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns()) {
+            if (!introspectedColumn.isJdbcCharacterColumn()
+                    || !introspectedColumn.isStringColumn()) {
+                continue;
+            }
+            
+            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("LikeInsensitive");
+            method.setName(sb.toString());
+            method.setReturnType(FullyQualifiedJavaType.getCriteriaInstance());
+
+            sb.setLength(0);
+            sb.append("addCriterion(\"upper("); //$NON-NLS-1$
+            sb.append(introspectedColumn.getAliasedActualColumnName());
+            sb.append(") like\", value.toUpperCase(), \"");
+            sb.append(introspectedColumn.getJavaProperty());
+            sb.append("\");"); //$NON-NLS-1$
+            method.addBodyLine(sb.toString());
+            method.addBodyLine("return this;"); //$NON-NLS-1$
+            
+            criteria.addMethod(method);
+        }
+        
+        return true;
+    }
+}

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=747134&r1=747133&r2=747134&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 Mon Feb 23 20:58:13 2009
@@ -921,4 +921,88 @@
             fail(e.getMessage());
         }
     }
+
+    @SuppressWarnings("unchecked")
+    public void testMyObjectSelectByExampleLikeInsensitive() {
+        MyObjectDAO dao = getMyObjectDAO();
+
+        try {
+            MyObject record = new MyObject();
+            FirstName fn = new FirstName();
+            fn.setValue("Fred");
+            record.setFirstname(fn);
+            record.setLastname("Flintstone");
+            record.setId1(1);
+            record.setId2(1);
+            dao.insertMyObject(record);
+
+            record = new MyObject();
+            fn = new FirstName();
+            fn.setValue("Wilma");
+            record.setFirstname(fn);
+            record.setLastname("Flintstone");
+            record.setId1(1);
+            record.setId2(2);
+            dao.insertMyObject(record);
+
+            record = new MyObject();
+            fn = new FirstName();
+            fn.setValue("Pebbles");
+            record.setFirstname(fn);
+            record.setLastname("Flintstone");
+            record.setId1(1);
+            record.setId2(3);
+            dao.insertMyObject(record);
+
+            record = new MyObject();
+            fn = new FirstName();
+            fn.setValue("Barney");
+            record.setFirstname(fn);
+            record.setLastname("Rubble");
+            record.setId1(2);
+            record.setId2(1);
+            dao.insertMyObject(record);
+
+            record = new MyObject();
+            fn = new FirstName();
+            fn.setValue("Betty");
+            record.setFirstname(fn);
+            record.setLastname("Rubble");
+            record.setId1(2);
+            record.setId2(2);
+            dao.insertMyObject(record);
+
+            record = new MyObject();
+            fn = new FirstName();
+            fn.setValue("Bamm Bamm");
+            record.setFirstname(fn);
+            record.setLastname("Rubble");
+            record.setId1(2);
+            record.setId2(3);
+            dao.insertMyObject(record);
+
+            MyObjectCriteria example = new MyObjectCriteria();
+            example.createCriteria().andLastnameLike("RU%");
+            example.setOrderByClause("ID1, ID2");
+            List answer = dao.selectMyObjectByExample(example);
+            assertEquals(0, answer.size());
+            
+            example.clear();
+            example.createCriteria().andLastnameLikeInsensitive("RU%");
+            answer = dao.selectMyObjectByExample(example);
+            assertEquals(3, answer.size());
+            
+            MyObject returnedRecord = (MyObject) answer.get(0);
+            assertEquals(2, returnedRecord.getId1().intValue());
+            assertEquals(1, returnedRecord.getId2().intValue());
+            returnedRecord = (MyObject) answer.get(1);
+            assertEquals(2, returnedRecord.getId1().intValue());
+            assertEquals(2, returnedRecord.getId2().intValue());
+            returnedRecord = (MyObject) answer.get(2);
+            assertEquals(2, returnedRecord.getId1().intValue());
+            assertEquals(3, returnedRecord.getId2().intValue());
+        } catch (SQLException e) {
+            fail(e.getMessage());
+        }
+    }
 }

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=747134&r1=747133&r2=747134&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/ibatorConfig.xml (original)
+++ ibatis/trunk/java/tools/ibator/core/testJava5/ibatortest/ibatorConfig.xml Mon Feb 23 20:58:13 2009
@@ -261,6 +261,7 @@
 
   <ibatorContext id="miscellaneousTests" targetRuntime="Ibatis2Java5">
     <ibatorPlugin type="org.apache.ibatis.ibator.plugins.EqualsHashCodePlugin" />
+    <ibatorPlugin type="org.apache.ibatis.ibator.plugins.CaseInsensitiveLikePlugin" />
     <ibatorPlugin type="org.apache.ibatis.ibator.plugins.RenameExampleClassPlugin" >
       <property name="searchString" value="Example$"/>
       <property name="replaceString" value="Criteria"/>