mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-22 15:10:02 +00:00
DB2: SqlCodeTranslator must check exception chain
This commit is contained in:
1 parent
1d11666945
commit
90f6d0707f
1 file changed
+28
-3
@@ -31,14 +31,39 @@ public class SqlCodeTranslator implements SqlExceptionTranslator {
|
|||||||
this.map = Collections.emptyMap();
|
this.map = Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private DataErrorType getErrorType(SQLException e) {
|
||||||
public PersistenceException translate(String message, SQLException e) {
|
|
||||||
|
|
||||||
DataErrorType errorType = map.get(e.getSQLState());
|
DataErrorType errorType = map.get(e.getSQLState());
|
||||||
if (errorType == null) {
|
if (errorType == null) {
|
||||||
// fall back to error code
|
// fall back to error code
|
||||||
errorType = map.get(String.valueOf(e.getErrorCode()));
|
errorType = map.get(String.valueOf(e.getErrorCode()));
|
||||||
}
|
}
|
||||||
|
return errorType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PersistenceException translate(String message, SQLException e) {
|
||||||
|
|
||||||
|
DataErrorType errorType = getErrorType(e);
|
||||||
|
// for DB2 we must inspect the sql exception chain to determine which
|
||||||
|
// persistence error occurred in a batch execution. We also concatenate
|
||||||
|
// the error messages to improve error analysis.
|
||||||
|
SQLException chain = e.getNextException();
|
||||||
|
if (chain != null) {
|
||||||
|
StringBuilder sb = new StringBuilder(message);
|
||||||
|
int i = 1;
|
||||||
|
while (chain != null && i < 100000) { // prevents from endless loop
|
||||||
|
sb.append("\n\t#").append(i++).append(": ").append(chain.getMessage());
|
||||||
|
if (errorType == null) {
|
||||||
|
errorType = getErrorType(chain);
|
||||||
|
if (errorType != null) {
|
||||||
|
sb.append(" (causing error)"); // mark the line, where we found a matching error code
|
||||||
|
}
|
||||||
|
}
|
||||||
|
chain = chain.getNextException();
|
||||||
|
}
|
||||||
|
message = sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
if (errorType != null) {
|
if (errorType != null) {
|
||||||
switch (errorType) {
|
switch (errorType) {
|
||||||
case AcquireLock:
|
case AcquireLock:
|
||||||
|
|||||||
Reference in new issue
Block a user