ibatis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgbut...@apache.org
Subject svn commit: r740917 - in /ibatis/trunk/java/tools/ibator/core: build/ doc/ htmldoc/ src/org/apache/ibatis/ibator/api/dom/xml/ src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/
Date Wed, 04 Feb 2009 22:14:44 GMT
Author: jgbutler
Date: Wed Feb  4 22:14:44 2009
New Revision: 740917

URL: http://svn.apache.org/viewvc?rev=740917&view=rev
Log:
[ibator] Fix for IBATIS-579 - don't allow column names to break across lines in generated
XML

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/whatsNew.html
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/xml/TextElement.java
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BaseColumnListElementGenerator.java
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BlobColumnListElementGenerator.java
    ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/InsertElementGenerator.java

Modified: ibatis/trunk/java/tools/ibator/core/build/version.properties
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/build/version.properties?rev=740917&r1=740916&r2=740917&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/build/version.properties (original)
+++ ibatis/trunk/java/tools/ibator/core/build/version.properties Wed Feb  4 22:14:44 2009
@@ -1,4 +1,4 @@
 #Ibator build version info
-#Tue Feb 03 20:33:04 CST 2009
+#Wed Feb 04 16:05:31 CST 2009
 version=1.2.2
-buildNum=703
+buildNum=707

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=740917&r1=740916&r2=740917&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt (original)
+++ ibatis/trunk/java/tools/ibator/core/doc/ReleaseNotes.txt Wed Feb  4 22:14:44 2009
@@ -3,6 +3,8 @@
 
 Bugs:
 1. Fixed NPE when no DAOs are generated
+2. Fixed IBATIS-579 - don't allow column names with spaces to break
+   across lines
 
 Enhancements:
 1. IBATIS-569 - Make it easier to override IbatorRules in plugins

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=740917&r1=740916&r2=740917&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html (original)
+++ ibatis/trunk/java/tools/ibator/core/htmldoc/whatsNew.html Wed Feb  4 22:14:44 2009
@@ -20,6 +20,8 @@
 <h3>Bugs Fixed</h3>
 <ul>
   <li>NPE when no DAOs are generated.</li>
+  <li>IBATIS-579 - Don't allow column names that contain spaces to
+      break across lines in generated XML.</li>
 </ul>
 
 <h3>Enhancements</h3>

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/xml/TextElement.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/xml/TextElement.java?rev=740917&r1=740916&r2=740917&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/xml/TextElement.java
(original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/api/dom/xml/TextElement.java
Wed Feb  4 22:14:44 2009
@@ -15,11 +15,6 @@
  */
 package org.apache.ibatis.ibator.api.dom.xml;
 
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.StringTokenizer;
-
 import org.apache.ibatis.ibator.api.dom.OutputUtilities;
 
 /**
@@ -43,65 +38,9 @@
      */
     @Override
     public String getFormattedContent(int indentLevel) {
-        return formatLongString(content, 100, indentLevel);
-    }
-
-    /**
-     * Utility method. Takes a long string and breaks it into multiple lines of
-     * whose width is no longer that the specified maximum line length.
-     * 
-     * @param s
-     *            the String to be formatted
-     * @param maxLineLength
-     *            the maximum line length
-     * @param indentLevel
-     *            the required indent level of all lines
-     * @return the formatted String
-     */
-    private static String formatLongString(String s, int maxLineLength,
-            int indentLevel) {
-
         StringBuilder sb = new StringBuilder();
         OutputUtilities.xmlIndent(sb, indentLevel);
-        sb.append(s);
-        if (sb.length() <= maxLineLength || s.indexOf(' ') == -1) {
-            // line is short, or has no spaces - return as is
-            return sb.toString();
-        }
-        
-        List<String> lines = new ArrayList<String>();
-        StringTokenizer st = new StringTokenizer(s, " "); //$NON-NLS-1$
-        
-        sb.setLength(0);
-        OutputUtilities.xmlIndent(sb, indentLevel);
-        sb.append(st.nextToken());
-        while (st.hasMoreTokens()) {
-            String token = st.nextToken();
-
-            if (sb.length() + token.length() + 1 > maxLineLength) {
-                lines.add(sb.toString());
-                sb.setLength(0);
-                OutputUtilities.xmlIndent(sb, indentLevel + 1);
-                sb.append(token);
-            } else {
-                sb.append(' ');
-                sb.append(token);
-            }
-        }
-
-        if (sb.toString().trim().length() > 0) {
-            lines.add(sb.toString());
-        }
-
-        sb.setLength(0);
-        Iterator<String> iter = lines.iterator();
-        while (iter.hasNext()) {
-            sb.append(iter.next());
-            if (iter.hasNext()) {
-                OutputUtilities.newLine(sb);
-            }
-        }
-
+        sb.append(content);
         return sb.toString();
     }
 }

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BaseColumnListElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BaseColumnListElementGenerator.java?rev=740917&r1=740916&r2=740917&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BaseColumnListElementGenerator.java
(original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BaseColumnListElementGenerator.java
Wed Feb  4 22:14:44 2009
@@ -15,6 +15,8 @@
  */
 package org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements;
 
+import java.util.Iterator;
+
 import org.apache.ibatis.ibator.api.IntrospectedColumn;
 import org.apache.ibatis.ibator.api.dom.xml.Attribute;
 import org.apache.ibatis.ibator.api.dom.xml.TextElement;
@@ -41,21 +43,25 @@
 
         ibatorContext.getCommentGenerator().addComment(answer);
 
-        boolean comma = false;
         StringBuilder sb = new StringBuilder();
-        
-        for (IntrospectedColumn introspectedColumn : introspectedTable.getNonBLOBColumns())
{
-            if (comma) {
+        Iterator<IntrospectedColumn> iter = introspectedTable.getNonBLOBColumns().iterator();
+        while (iter.hasNext()) {
+            sb.append(iter.next().getSelectListPhrase());
+            
+            if (iter.hasNext()) {
                 sb.append(", "); //$NON-NLS-1$
-            } else {
-                comma = true;
             }
+            
+            if (sb.length() > 80) {
+                answer.addElement(new TextElement(sb.toString()));
+                sb.setLength(0);
+            }
+        }
 
-            sb.append(introspectedColumn.getSelectListPhrase());
+        if (sb.length() > 0) {
+            answer.addElement((new TextElement(sb.toString())));
         }
         
-        answer.addElement((new TextElement(sb.toString())));
-
         if (ibatorContext.getPlugins().sqlMapBaseColumnListElementGenerated(answer, introspectedTable))
{
             parentElement.addElement(answer);
         }

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BlobColumnListElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BlobColumnListElementGenerator.java?rev=740917&r1=740916&r2=740917&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BlobColumnListElementGenerator.java
(original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/BlobColumnListElementGenerator.java
Wed Feb  4 22:14:44 2009
@@ -15,6 +15,8 @@
  */
 package org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements;
 
+import java.util.Iterator;
+
 import org.apache.ibatis.ibator.api.IntrospectedColumn;
 import org.apache.ibatis.ibator.api.dom.xml.Attribute;
 import org.apache.ibatis.ibator.api.dom.xml.TextElement;
@@ -41,20 +43,25 @@
 
         ibatorContext.getCommentGenerator().addComment(answer);
 
-        boolean comma = false;
         StringBuilder sb = new StringBuilder();
         
-        for (IntrospectedColumn introspectedColumn : introspectedTable.getBLOBColumns())
{
-            if (comma) {
+        Iterator<IntrospectedColumn> iter = introspectedTable.getBLOBColumns().iterator();
+        while (iter.hasNext()) {
+            sb.append(iter.next().getSelectListPhrase());
+            
+            if (iter.hasNext()) {
                 sb.append(", "); //$NON-NLS-1$
-            } else {
-                comma = true;
             }
+            
+            if (sb.length() > 80) {
+                answer.addElement(new TextElement(sb.toString()));
+                sb.setLength(0);
+            }
+        }
 
-            sb.append(introspectedColumn.getSelectListPhrase());
+        if (sb.length() > 0) {
+            answer.addElement((new TextElement(sb.toString())));
         }
-        
-        answer.addElement((new TextElement(sb.toString())));
 
         if (ibatorContext.getPlugins().sqlMapBlobColumnListElementGenerated(answer, introspectedTable))
{
             parentElement.addElement(answer);

Modified: ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/InsertElementGenerator.java
URL: http://svn.apache.org/viewvc/ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/InsertElementGenerator.java?rev=740917&r1=740916&r2=740917&view=diff
==============================================================================
--- ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/InsertElementGenerator.java
(original)
+++ ibatis/trunk/java/tools/ibator/core/src/org/apache/ibatis/ibator/generator/ibatis2/sqlmap/elements/InsertElementGenerator.java
Wed Feb  4 22:14:44 2009
@@ -15,8 +15,13 @@
  */
 package org.apache.ibatis.ibator.generator.ibatis2.sqlmap.elements;
 
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import org.apache.ibatis.ibator.api.FullyQualifiedTable;
 import org.apache.ibatis.ibator.api.IntrospectedColumn;
+import org.apache.ibatis.ibator.api.dom.OutputUtilities;
 import org.apache.ibatis.ibator.api.dom.java.FullyQualifiedJavaType;
 import org.apache.ibatis.ibator.api.dom.xml.Attribute;
 import org.apache.ibatis.ibator.api.dom.xml.TextElement;
@@ -71,29 +76,43 @@
 
         valuesClause.append("values ("); //$NON-NLS-1$
 
-        boolean comma = false;
-        for (IntrospectedColumn introspectedColumn : introspectedTable.getAllColumns()) {
+        List<String> valuesClauses = new ArrayList<String>();
+        Iterator<IntrospectedColumn> iter = introspectedTable.getAllColumns().iterator();
+        while (iter.hasNext()) {
+            IntrospectedColumn introspectedColumn = iter.next();
             if (introspectedColumn.isIdentity()) {
                 // cannot set values on identity fields
                 continue;
             }
-
-            if (comma) {
+            
+            insertClause.append(introspectedColumn.getEscapedColumnName());
+            valuesClause.append(introspectedColumn.getIbatisFormattedParameterClause());
+            if (iter.hasNext()) {
                 insertClause.append(", "); //$NON-NLS-1$
                 valuesClause.append(", "); //$NON-NLS-1$
-            } else {
-                comma = true; // turn on comma for next time
             }
-
-            insertClause.append(introspectedColumn.getEscapedColumnName());
-            valuesClause.append(introspectedColumn.getIbatisFormattedParameterClause());
+            
+            if (valuesClause.length() > 80) {
+                answer.addElement(new TextElement(insertClause.toString()));
+                insertClause.setLength(0);
+                OutputUtilities.xmlIndent(insertClause, 1);
+                
+                valuesClauses.add(valuesClause.toString());
+                valuesClause.setLength(0);
+                OutputUtilities.xmlIndent(valuesClause, 1);
+            }
         }
+        
         insertClause.append(')');
-        valuesClause.append(')');
-
         answer.addElement(new TextElement(insertClause.toString()));
-        answer.addElement(new TextElement(valuesClause.toString()));
-
+        
+        valuesClause.append(')');
+        valuesClauses.add(valuesClause.toString());
+        
+        for (String clause : valuesClauses) {
+            answer.addElement(new TextElement(clause));
+        }
+        
         if (gk != null && !gk.isBeforeInsert()) {
             IntrospectedColumn introspectedColumn = introspectedTable.getColumn(gk.getColumn());
             // if the column is null, then it's a configuration error. The



Mime
View raw message