Home Programming Detect Unintentional Blocking Calls when Utilizing R2DBC – Java, SQL and jOOQ.

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

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

[ad_1]

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 data. For instance, your complete DSL is non-nullable:

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

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

    // ...
}

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

Different circumstances are extra apparent, equivalent to:

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 primarily based jOOQ queries in any respect, however for those who’re utilizing R2DBC for reactive querying with jOOQ, you is likely to be tempted to by accident name one in every of jOOQ’s many many blocking execution strategies.

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

image

Not 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 not less than, you’ll discover that you simply’re about to do one thing fallacious.

Eclipse doesn’t but assist this sort of introspection. Should you agree it ought to, you can upvote this situation right here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=578310.

[ad_2]

Supply hyperlink

LEAVE A REPLY

Please enter your comment!
Please enter your name here