openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From allee8...@apache.org
Subject svn commit: r1371269 - /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Date Thu, 09 Aug 2012 16:01:32 GMT
Author: allee8285
Date: Thu Aug  9 16:01:32 2012
New Revision: 1371269

URL: http://svn.apache.org/viewvc?rev=1371269&view=rev
Log:
OPENJPA-2242 - Extends procedure call parameter String cast length if value length is greater
than the default length

Modified:
    openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=1371269&r1=1371268&r2=1371269&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Thu Aug  9 16:01:32 2012
@@ -222,7 +222,7 @@ public class DB2Dictionary
             // if the literal is a string, use the default char col size
             // in the cast statement.
             if (String.class.equals(c))
-                selectSQL.append("(" + characterColumnSize + ")");
+                selectSQL.append("(" + getCastStringColumnSize(val) + ")");
 
             selectSQL.append(")");
         }
@@ -767,7 +767,7 @@ public class DB2Dictionary
         String type = getTypeName(getJDBCType(JavaTypes.getTypeCode(val
             .getType()), false));
         if (String.class.equals(val.getType()))
-            type = type + "(" + characterColumnSize + ")";
+            type = type + "(" + getCastStringColumnSize(val) + ")";
         fstring = "CAST(? AS " + type + ")";
         return fstring;
     }
@@ -895,7 +895,7 @@ public class DB2Dictionary
                 // case "(?" - convert to "CAST(? AS type"
                 String typeName = getTypeName(type);
                 if (String.class.equals(val.getType()))
-                    typeName = typeName + "(" + characterColumnSize + ")";
+                    typeName = typeName + "(" + getCastStringColumnSize(val) + ")";
                 String str = "CAST(? AS " + typeName + ")";
                 buf.replaceSqlString(sqlString.length() - 1,
                         sqlString.length(), str);
@@ -1044,6 +1044,20 @@ public class DB2Dictionary
         }
     }
 
+    private int getCastStringColumnSize(Object val) {
+        int colSize = characterColumnSize;
+        if (val instanceof Lit) {
+            String literal = (String) ((Lit) val).getValue();
+            if (literal != null) {
+                int literalLen = literal.length();
+                if (literalLen > characterColumnSize) {
+                    colSize = literalLen;
+                }
+            }
+        }
+        return colSize;
+    }
+
     @Override
     public void insertBlobForStreamingLoad(Row row, Column col, 
             JDBCStore store, Object ob, Select sel) throws SQLException {
@@ -1075,7 +1089,7 @@ public class DB2Dictionary
         throws SQLException {
         //NO-OP
     }
-    
+
     /**
      * Set the given date value as a parameter to the statement.
      */



Mime
View raw message