From 1e4aa60859d0a2a6ef90ab1d6c56dfb90ea7805b Mon Sep 17 00:00:00 2001 From: Fay Wang Date: Tue, 21 Oct 2008 02:03:26 +0000 Subject: [PATCH] OPENJPA-745 raise string right truncation error for Sybase git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@706493 13f79535-47bb-0310-9956-ffa450edef68 --- .../openjpa/jdbc/kernel/JDBCStoreManager.java | 1 + .../org/apache/openjpa/jdbc/sql/DBDictionary.java | 5 +++++ .../apache/openjpa/jdbc/sql/SybaseDictionary.java | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java index f3f85b7d3..7fda2073b 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java @@ -920,6 +920,7 @@ public class JDBCStoreManager _conn = connectInternal(); if (ref) _conn.ref(); + _dict.initializeSettings(_conn); } catch (SQLException se) { throw SQLExceptions.getStore(se, _dict); } finally { diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java index c0593f502..e51b0d9ef 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DBDictionary.java @@ -200,6 +200,7 @@ public class DBDictionary public String selectWords = null; public String fixedSizeTypeNames = null; public String schemaCase = SCHEMA_CASE_UPPER; + public boolean setStringRightTruncationOn = true; // sql public String validationSQL = null; @@ -4561,4 +4562,8 @@ public class DBDictionary length)); return name; } + + public void initializeSettings(Connection conn) + throws SQLException { + } } diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java index 272ee64ea..cb293b7b8 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SybaseDictionary.java @@ -268,6 +268,20 @@ public class SybaseDictionary throws SQLException { return new SybaseConnection(super.decorate(conn)); } + + public void initializeSettings(Connection conn) + throws SQLException { + // In order for Sybase to raise the truncation exception when the + // string length is greater than the column length for Char, VarChar, + // Binary, VarBinary, the "set string_rtruncation on" must be executed. + // This setting is effective for the duration of current connection. + if (setStringRightTruncationOn) { + String str = "set string_rtruncation on"; + PreparedStatement stmnt = prepareStatement(conn, str); + stmnt.execute(); + stmnt.close(); + } + } /** * Connection wrapper to cache the {@link Connection#getCatalog} result,