mirror of https://github.com/apache/openjpa.git
OPENJPA-462: Adding SQLState in DerbyDictionary to demonstrate specialization
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@603028 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a54f842624
commit
38f41d870e
|
@ -4033,7 +4033,11 @@ public class DBDictionary
|
|||
* {@link StoreException}.<br>
|
||||
* JDBC Drivers are not uniform in return values of SQLState for the same
|
||||
* error and hence each database specific Dictionary can specialize.<br>
|
||||
* Default behavior is to return an empty list.
|
||||
*
|
||||
*
|
||||
* @return an <em>unmodifiable</em> list of Strings representing supposedly
|
||||
* uniform SQL States for a given type of StoreException.
|
||||
* Default behavior is to return an empty list.
|
||||
*/
|
||||
public List/*<String>*/ getSQLStates(int exceptionType) {
|
||||
if (exceptionType>=0 && exceptionType<SQL_STATE_CODES.length)
|
||||
|
|
|
@ -20,9 +20,14 @@ package org.apache.openjpa.jdbc.sql;
|
|||
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.openjpa.util.StoreException;
|
||||
|
||||
/**
|
||||
* Dictionary for Apache Derby (formerly Cloudscape).
|
||||
*/
|
||||
|
@ -93,4 +98,26 @@ public class DerbyDictionary
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds extra SQLState code that Derby JDBC Driver uses. In JDBC 4.0,
|
||||
* SQLState will follow either XOPEN or SQL 2003 convention. A compliant
|
||||
* driver can be queries via DatabaseMetaData.getSQLStateType() to detect
|
||||
* the convention type.<br>
|
||||
* This method is overwritten to highlight that a) the SQL State is ideally
|
||||
* uniform across JDBC Drivers but not practically and b) the overwritten
|
||||
* method must crate a new list to return as the super classes list is
|
||||
* unmodifable.
|
||||
*/
|
||||
public List getSQLStates(int exceptionType) {
|
||||
List original = super.getSQLStates(exceptionType);
|
||||
if (exceptionType == StoreException.LOCK) {
|
||||
// Can not add new codes to unmodifable list of the super class
|
||||
List newStates = new ArrayList(original);
|
||||
newStates.add("40XL1");
|
||||
return newStates;
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue