Error Handler
Basically, exception
in execution time will be thrown by each particular jdbc
driver or reactive SQL driver
, it can be spaghetti code, dealing with exception
, then jooqx
is able to centralize any exception with properly
SQL state
that thanks to DataAccessException
in jOOQ
.
It is easy to configure when building executor
With JDBC SQL client
Jooqx jooqx = Jooqx.builder()
.setVertx(vertx)
.setDSL(dslContext)
.setSqlClient(pool)
.setErrorConverter(new JDBCErrorConverter())
.build();
With JDBC PostgreSQL client
Jooqx jooqx = Jooqx.builder()
.setVertx(vertx)
.setDSL(dslContext)
.setSqlClient(pool)
.setErrorConverter(new PgErrorConverter())
.build();
Integrating with your existing application exception
So more, you can integrate seamlessly with your existing application exception. For example:
enum ErrorCode {
DUPLICATE
}
class YourAppError extends RuntimeException {
final ErrorCode errorCode;
YourAppError(ErrorCode errorCode, Exception rootCause) {
super(rootCause);
this.errorCode = errorCode;
}
}
And then, when init jooqx
, just register it
SQLErrorConverter errorConverter = new JDBCErrorConverter()
.andThen(dataAccessException -> new YourAppError(ErrorCode.DUPLICATE, dataAccessException));
Jooqx jooqx = Jooqx.builder()
.setVertx(vertx)
.setDSL(dslContext)
.setSqlClient(pool)
.setErrorConverter(errorConverter)
.build();