[jOOQ/jOOQ#11485] Translate common error codes

This commit is contained in:
Lukas Eder 2023-08-18 16:37:16 +02:00
parent 196f524d66
commit 719b8bddcb
2 changed files with 22 additions and 1 deletions

View File

@ -157,12 +157,19 @@ public class DataAccessException extends RuntimeException {
if (e.getSQLState() != null)
return SQLStateClass.fromCode(e.getSQLState());
else if (e.getSQLState() == null && "org.sqlite.SQLiteException".equals(e.getClass().getName()))
else if (e.getSQLState() == null && causePrefix(e, "org.sqlite"))
return SQLStateClass.fromSQLiteVendorCode(e.getErrorCode());
else if (e.getSQLState() == null && causePrefix(e, "io.trino"))
return SQLStateClass.fromTrinoVendorCode(e.getErrorCode());
else
return SQLStateClass.NONE;
}
private static final boolean causePrefix(SQLException e, String prefix) {
return e.getClass().getName().startsWith(prefix)
|| e.getCause() != null && e.getCause().getClass().getName().startsWith(prefix);
}
/**
* Decode the {@link R2dbcException#getSqlState()} into
* {@link SQLStateClass}.

View File

@ -201,6 +201,20 @@ public enum SQLStateClass {
return SQLStateClass.OTHER;
}
@NotNull
static SQLStateClass fromTrinoVendorCode(int errorCode) {
// See https://github.com/trinodb/trino/blob/master/core/trino-spi/src/main/java/io/trino/spi/StandardErrorCode.java
switch (errorCode) {
case 1: return C42_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION;
case 9:
case 19: return C22_DATA_EXCEPTION;
case 16: return C23_INTEGRITY_CONSTRAINT_VIOLATION;
}
return SQLStateClass.OTHER;
}