Saturday, May 4, 2024
HomeProgrammingDetect Unintended Blocking Calls when Utilizing R2DBC – Java, SQL and jOOQ.

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, so as to annotate return sorts with nullability info. For instance, all the DSL is non-nullable:

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

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

    // ...
}

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

Different circumstances are extra apparent, reminiscent of:

public interface ResultQuery<R extends File> 
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 varieties of fetch strategies is that fetchOne() expects 0-1 ensuing information, 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 primarily based jOOQ queries in any respect, however in case you’re utilizing R2DBC for reactive querying with jOOQ, you is likely to be tempted to by accident name considered 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 resolve whether or not you need this to be a warning or an error, however at the least, you’ll discover that you simply’re about to do one thing incorrect.

Eclipse doesn’t but help this type of introspection. For those who agree it ought to, you could possibly 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

Most Popular

Recent Comments