Saturday, March 2, 2024

Detect Unintended Blocking Calls when Utilizing R2DBC – Java, SQL and jOOQ.


Some time in the past, jOOQ has added the org.jetbrains:annotations dependency to the jOOQ API, with a purpose to annotate return sorts with nullability info. For instance, your complete DSL is non-nullable:

public interface SelectWhereStep<R extends Document>
extends SelectConnectByStep<R> {

    @NotNull @CheckReturnValue
    @Help
    SelectConditionStep<R> the place(Situation situation);

    // ...
}

It is smart to provide this assure particularly to kotlin customers, as they will do away with among the extra advanced sorts involving issues like Choose!<Document!>, which now turns into at the very least Choose<Document!>. Discover additionally the @CheckReturnValue annotation, which IntelliJ makes use of for some introspections.

Different instances are extra apparent, resembling:

public interface ResultQuery<R extends Document> 
extends Fields, Question, Iterable<R>, Writer<R> {

    @Nullable
    @Blocking
    R fetchOne() throws TooManyRowsException;

    @NotNull
    @Blocking
    R fetchSingle() throws NoDataFoundException, TooManyRowsException;

    // ...
}

The distinction between these two sorts of fetch strategies is that fetchOne() expects 0-1 ensuing data, whereas fetchSingle() expects precisely 1 file. Each throw exceptions in any other case, however solely the latter can assure a non-nulllable file worth.

However wait, what’s this @Blocking annotation?

In jOOQ 3.17, we’ve added the org.jetbrains.annotations.Blocking annotation to all jOOQ API that executes a question on prime of JDBC. This doesn’t have an effect on customers of JDBC based mostly jOOQ queries in any respect, however in case you’re utilizing R2DBC for reactive querying with jOOQ, you is perhaps tempted to by accident name certainly one of jOOQ’s many many blocking execution strategies.

No extra! IntelliJ will now complain about such a name being inappropriate:

image

No less than as quickly as you allow the introspection:

image

It’s as much as you to determine whether or not you need this to be a warning or an error, however at the very least, you’ll discover that you just’re about to do one thing improper.

Eclipse doesn’t but help this type of introspection. Should you agree it ought to, you would upvote this concern right here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=578310.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles