mirror of https://github.com/apache/openjpa.git
OPENJPA-2391 - commit patch contributed by Di Lau.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1496128 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
123e28821e
commit
c7b4e05b1e
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.openjpa.jdbc.sql;
|
package org.apache.openjpa.jdbc.sql;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DatabaseMetaData;
|
import java.sql.DatabaseMetaData;
|
||||||
|
@ -27,7 +28,6 @@ import java.sql.Types;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.hsqldb.Trace;
|
|
||||||
import org.apache.openjpa.jdbc.identifier.DBIdentifier;
|
import org.apache.openjpa.jdbc.identifier.DBIdentifier;
|
||||||
import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
|
import org.apache.openjpa.jdbc.kernel.exps.FilterValue;
|
||||||
import org.apache.openjpa.jdbc.schema.Column;
|
import org.apache.openjpa.jdbc.schema.Column;
|
||||||
|
@ -51,6 +51,7 @@ public class HSQLDictionary extends DBDictionary {
|
||||||
|
|
||||||
private int dbMajorVersion;
|
private int dbMajorVersion;
|
||||||
private int dbMinorVersion;
|
private int dbMinorVersion;
|
||||||
|
private int violation_of_unique_index_or_constraint;
|
||||||
|
|
||||||
private SQLBuffer _oneBuffer = new SQLBuffer(this).append("1");
|
private SQLBuffer _oneBuffer = new SQLBuffer(this).append("1");
|
||||||
|
|
||||||
|
@ -118,6 +119,25 @@ public class HSQLDictionary extends DBDictionary {
|
||||||
if (dbMajorVersion > 1 && dbMinorVersion > 0) {
|
if (dbMajorVersion > 1 && dbMinorVersion > 0) {
|
||||||
nextSequenceQuery += " LIMIT 1";
|
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 DBDictionary {
|
||||||
Object failed) {
|
Object failed) {
|
||||||
OpenJPAException ke = super.newStoreException(msg, causes, failed);
|
OpenJPAException ke = super.newStoreException(msg, causes, failed);
|
||||||
if (ke instanceof ReferentialIntegrityException
|
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) ke).setIntegrityViolation
|
||||||
(ReferentialIntegrityException.IV_UNIQUE);
|
(ReferentialIntegrityException.IV_UNIQUE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue