[jOOQ/jOOQ#15732] Reverse engineer error message to detect SQLStateClass
This commit is contained in:
parent
7d4e9c89f0
commit
debdd1ffe0
@ -76,7 +76,8 @@ import io.r2dbc.spi.R2dbcException;
|
||||
*/
|
||||
public class DataAccessException extends RuntimeException {
|
||||
|
||||
SQLStateClass sqlStateClass;
|
||||
SQLStateClass sqlStateClass;
|
||||
SQLStateSubclass sqlStateSubclass;
|
||||
|
||||
/**
|
||||
* Constructor for DataAccessException.
|
||||
@ -196,6 +197,14 @@ public class DataAccessException extends RuntimeException {
|
||||
return SQLStateClass.NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link SQLStateSubclass}.
|
||||
*/
|
||||
public DataAccessException sqlStateSubclass(SQLStateSubclass c) {
|
||||
this.sqlStateSubclass = c;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode the {@link SQLException#getSQLState()} or
|
||||
* {@link R2dbcException#getSqlState()} from {@link #getCause()} into
|
||||
@ -204,7 +213,10 @@ public class DataAccessException extends RuntimeException {
|
||||
*/
|
||||
@NotNull
|
||||
public SQLStateSubclass sqlStateSubclass() {
|
||||
return SQLStateSubclass.fromCode(sqlState());
|
||||
if (sqlStateSubclass != null)
|
||||
return sqlStateSubclass;
|
||||
else
|
||||
return SQLStateSubclass.fromCode(sqlState());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -38,6 +38,9 @@
|
||||
package org.jooq.exception;
|
||||
|
||||
import static org.jooq.exception.SQLStateClass.C22_DATA_EXCEPTION;
|
||||
import static org.jooq.exception.SQLStateClass.C23_INTEGRITY_CONSTRAINT_VIOLATION;
|
||||
import static org.jooq.exception.SQLStateSubclass.C22000_NO_SUBCLASS;
|
||||
import static org.jooq.exception.SQLStateSubclass.C23000_NO_SUBCLASS;
|
||||
|
||||
import java.sql.SQLDataException;
|
||||
import java.sql.SQLException;
|
||||
@ -64,7 +67,7 @@ public class DataException extends DataAccessException {
|
||||
public DataException(String message) {
|
||||
super(message);
|
||||
|
||||
sqlStateClass(C22_DATA_EXCEPTION);
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -77,6 +80,11 @@ public class DataException extends DataAccessException {
|
||||
public DataException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private final void init() {
|
||||
sqlStateClass(C22_DATA_EXCEPTION);
|
||||
sqlStateSubclass(C22000_NO_SUBCLASS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,6 +38,7 @@
|
||||
package org.jooq.exception;
|
||||
|
||||
import static org.jooq.exception.SQLStateClass.C23_INTEGRITY_CONSTRAINT_VIOLATION;
|
||||
import static org.jooq.exception.SQLStateSubclass.C23000_NO_SUBCLASS;
|
||||
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
|
||||
@ -62,7 +63,7 @@ public class IntegrityConstraintViolationException extends DataAccessException {
|
||||
public IntegrityConstraintViolationException(String message) {
|
||||
super(message);
|
||||
|
||||
sqlStateClass(C23_INTEGRITY_CONSTRAINT_VIOLATION);
|
||||
init();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,6 +76,11 @@ public class IntegrityConstraintViolationException extends DataAccessException {
|
||||
public IntegrityConstraintViolationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private final void init() {
|
||||
sqlStateClass(C23_INTEGRITY_CONSTRAINT_VIOLATION);
|
||||
sqlStateSubclass(C23000_NO_SUBCLASS);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user