openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From allee8...@apache.org
Subject svn commit: r1496128 - /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java
Date Mon, 24 Jun 2013 17:23:56 GMT
Author: allee8285
Date: Mon Jun 24 17:23:56 2013
New Revision: 1496128

URL: http://svn.apache.org/r1496128
Log:
OPENJPA-2391 - commit patch contributed by Di Lau.

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

Modified: openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java?rev=1496128&r1=1496127&r2=1496128&view=diff
==============================================================================
--- openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java
(original)
+++ openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/HSQLDictionary.java
Mon Jun 24 17:23:56 2013
@@ -18,6 +18,7 @@
  */
 package org.apache.openjpa.jdbc.sql;
 
+import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -27,7 +28,6 @@ import java.sql.Types;
 import java.util.Arrays;
 
 import org.apache.commons.lang.StringUtils;
-import org.hsqldb.Trace;
 import org.apache.openjpa.jdbc.identifier.DBIdentifier;
 import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
 import org.apache.openjpa.jdbc.schema.Column;
@@ -51,6 +51,7 @@ public class HSQLDictionary extends DBDi
 
     private int dbMajorVersion;
     private int dbMinorVersion;
+    private int violation_of_unique_index_or_constraint;
 
     private SQLBuffer _oneBuffer = new SQLBuffer(this).append("1");
 
@@ -118,6 +119,25 @@ public class HSQLDictionary extends DBDi
         if (dbMajorVersion > 1 && dbMinorVersion > 0) {
             nextSequenceQuery += " LIMIT 1";
         }
+        String packageName;
+        String fieldName;
+        if (dbMajorVersion > 1) {
+            // default value for "X_23505"
+            violation_of_unique_index_or_constraint = 104;
+            packageName = "org.hsqldb.error.ErrorCode";
+            fieldName = "X_23505";
+        } else {
+            // default value for "VIOLATION_OF_UNIQUE_INDEX"
+            violation_of_unique_index_or_constraint = 9; 
+            packageName = "org.hsqldb.Trace";
+            fieldName = "VIOLATION_OF_UNIQUE_INDEX";
+        }
+        try {
+            Class<?> cls = Class.forName(packageName);
+            Field fld = cls.getField(fieldName);
+            violation_of_unique_index_or_constraint = fld.getInt(null);
+        } catch (Exception e) {
+        }
     }
 
     /**
@@ -381,7 +401,7 @@ public class HSQLDictionary extends DBDi
         Object failed) {
         OpenJPAException ke = super.newStoreException(msg, causes, failed);
         if (ke instanceof ReferentialIntegrityException
-            && causes[0].getErrorCode() == -Trace.VIOLATION_OF_UNIQUE_INDEX) {
+            && causes[0].getErrorCode() == -violation_of_unique_index_or_constraint)
{
             ((ReferentialIntegrityException) ke).setIntegrityViolation
                 (ReferentialIntegrityException.IV_UNIQUE);
         }



Mime
View raw message