diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java index 77640bb47..7f77d77af 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/DB2Dictionary.java @@ -442,4 +442,39 @@ public class DB2Dictionary append(" ").append(rowClause); return buf; } -} + + /** Append exception information from SQLCA to the exsisting + * exception meassage + */ + public String appendExtendedExceptionMsg(String msg, SQLException sqle){ + final String GETSQLCA ="getSqlca"; + String exceptionMsg = new String(); + try { + Method sqlcaM2 = sqle.getNextException().getClass() + .getMethod(GETSQLCA,null); + Object sqlca = sqlcaM2.invoke(sqle.getNextException(), + new Object[] {}); + Method getSqlErrpMethd = sqlca.getClass(). + getMethod("getSqlErrp", null); + Method getSqlWarnMethd = sqlca.getClass(). + getMethod("getSqlWarn", null); + Method getSqlErrdMethd = sqlca.getClass(). + getMethod("getSqlErrd", null); + exceptionMsg = exceptionMsg.concat( "SQLCA OUTPUT" + + "[Errp=" +getSqlErrpMethd.invoke(sqlca,new Object[]{}) + + ", Errd=" + Arrays.toString((int[]) + (getSqlErrdMethd.invoke(sqlca, new Object[]{})))); + String Warn = new String((char[])getSqlWarnMethd. + invoke(sqlca, new Object[]{})); + if(Warn.trim().length() != 0) + exceptionMsg = exceptionMsg.concat(", Warn=" +Warn + "]" ); + else + exceptionMsg = exceptionMsg.concat( "]" ); + msg = msg.concat(exceptionMsg); + return msg; + } catch (Throwable t) { + return sqle.getMessage(); + } + } + + } \ No newline at end of file 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 a9b95468a..f05c8f59c 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 @@ -2470,7 +2470,14 @@ public class DBDictionary buf.append(getTypeName(type)); buf.append(post); } - + + /** Append any database specific exception message to + * the exsisting exception message + */ + public String appendExtendedExceptionMsg(String msg, SQLException sqle) { + return msg; + } + /////////// // DDL SQL /////////// diff --git a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLExceptions.java b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLExceptions.java index 3decfede9..c9cc8b145 100644 --- a/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLExceptions.java +++ b/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/SQLExceptions.java @@ -87,6 +87,7 @@ public class SQLExceptions { Object failed, DBDictionary dict) { if (msg == null) msg = se.getClass().getName(); + msg = dict.appendExtendedExceptionMsg(msg,se); SQLException[] ses = getSQLExceptions(se); if (dict == null) return new StoreException(msg).setFailedObject(failed).