You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by al...@apache.org on 2012/08/09 18:01:34 UTC
svn commit: r1371270 -
/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Author: allee8285
Date: Thu Aug 9 16:01:34 2012
New Revision: 1371270
URL: http://svn.apache.org/viewvc?rev=1371270&view=rev
Log:
OPENJPA-2242 - Extends procedure call parameter String cast length if value length is greater than the default length
Modified:
openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
Modified: openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java
URL: http://svn.apache.org/viewvc/openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java?rev=1371270&r1=1371269&r2=1371270&view=diff
==============================================================================
--- openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java (original)
+++ openjpa/branches/2.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java Thu Aug 9 16:01:34 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.
*/