Tuesday, September 6, 2022
HomeProgrammingA Transient Overview over the Most Widespread jOOQ Sorts – Java, SQL...

A Transient Overview over the Most Widespread jOOQ Sorts – Java, SQL and jOOQ.


For brand spanking new customers working with jOOQ for the primary time, the variety of sorts within the jOOQ API may be overwhelming. The SQL language doesn’t have many such “seen” sorts, though if you consider SQL the best way jOOQ does, then they’re there simply the identical, however hidden from customers through an English type syntax.

This overview will record an important jOOQ sorts in a cheat sheet kind.

Configuration sorts

The Configuration is the one most essential configuration sort, which accommodates references to all different varieties of configuration, Settings, customized SPI implementations, JDBC or R2DBC Connection, and so on. SPIs embrace:

And lots of extra, which you’ll see from the Configuration Javadoc

It’s made out there from each Scope sort within the API, see under for particulars

Scopes

The Scope sorts are varied sorts which are created “within the scope” of a Configuration, and as such can present entry to the entire Configuration‘s contained objects and SPIs. This design permits for very versatile, programmatic dependency injection all through the internals of jOOQ. Among the most essential Scope sorts embrace:

For different sorts, seek advice from the Scope Javadoc.

Settings

Settings are largely scalar flags that specify detailed behaviour in jOOQ. Some choose examples embrace:

As of jOOQ 3.17, there are over 160 such settings, so we will’t record all of them right here. For extra particulars, seek advice from the Settings Javadoc.

DSL sorts

The DSL API is an important API to work with jOOQ. It is available in 2 flavours.

The static DSL

The static DSL accommodates entry factors to each sort of QueryPart building DSLs, together with:

… and much more. All of those sorts are constructed statically, and as such, they don’t have any Configuration connected.

The “context” DSL

The “context” DSL, represented by the DSLContext sort, solely presents establishing QueryPart sorts that revenue from being created “within the context” of a Configuration. That is primarily simply together with:

A Question that has been constructed from the DSLContext sort may be executed immediately through the use of Question.execute() or ResultQuery.fetch(), or many different execution strategies, together with asynchronous or reactive ones.

Step sorts

All through the DSL API, you will note so-called “Step” sorts, i.e. sorts with a “Step” suffix, comparable to e.g. SelectFromStep, which is the “Step” that provides entry to the Choose DSL’s FROM clause.

You need to by no means reference these sorts immediately, nor see them in your personal code. They’re intermediate DSL artifacts

QueryPart sorts

QueryPart is the widespread base sort of all the jOOQ expression tree, or mannequin API. Each sort that you just assemble with the DSL API will lengthen QueryPart, for instance:

QueryPart p1 = TABLE;
QueryPart p2 = TABLE.COLUMN;
QueryPart p3 = TABLE.COLUMN.eq(1);

The above expressions produce a extra particular sort than QueryPart, which we’ll clarify after, however all of them lengthen QueryPart.

A QueryPart is a sort that may be rendered within the context of a Configuration utilizing DSLContext::render

String sql = ctx.render(TABLE.COLUMN.eq(1));

A very powerful QueryPart subtypes embrace:

Desk

A Desk can be utilized in a FROM clause of a SELECT assertion, or as a goal of a DML assertion, and extra. There are numerous totally different desk sorts, together with:

There are a lot of extra attainable desk expressions in jOOQ, all implementing the Desk sort. An instance of utilizing Desk expressions is:

Desk<?> joined = CUSTOMER
    .be a part of(ADDRESS)
    .on(ADDRESS.CUSTOMER_ID.eq(CUSTOMER.CUSTOMER_ID));

Whereas most jOOQ statements gained’t work with such native variables, it’s all the time attention-grabbing to do not forget that with jOOQ, each question is a dynamic SQL question, and each SQL fragment is a totally self contained expression tree in Java, which may be assigned to any native variable or returned from a technique, and so on.

Subject

A Subject is a column expression, which can be utilized in plenty of locations all through the jOOQ API, in every single place the place column expressions can be utilized, together with:

And way more.

Situation

A Situation is only a Subject<Boolean> with some extra API particular to Situation constructing, together with the potential for calling Situation::and, Situation::or, and others. Numerous clauses settle for Situation explicitly, together with:

And extra.

Row

A Row or row worth expression is used to mannequin a tuple of values each for:

Such tuples are helpful to create a structural sort that teams Subject expressions into teams of re-usable objects. Some dialects additionally assist nominal variants of this, referred to as UDT (Person Outlined Kind), and jOOQ can emulate UDTs through embeddable sorts.

Choose

A Choose is a particular sort of ResultQuery, which can be utilized as:

ResultQuery

A ResultQuery is a Question that may produce File values in varied assortment varieties (e.g. Stream, End result, Writer, CompletionStage, and so on.). It may be created from varied Question sorts by including the RETURNING clause

Question

A Question is a Assertion that may be executed, that means:

  • A SQL string is generated
  • A PreparedStatement is ready
  • Bind values are sure
  • The PreparedStatement is executed
  • Presumably, a ResultSet is fetched.

With a purpose to execute a Question, it should be connected to a Configuration, which is finished most simply by creating the Question from a DSLContext.

Assertion

A Assertion (not the JDBC Assertion!) is a QueryPart that represents a procedural assertion in:

All Question implementations can be utilized as Assertion in such a procedural context.

QOM Sorts

The QOM (Question Object Mannequin) sorts are an experimental set of sorts publicly declaring the interior mannequin API, which could be very helpful for tree traversal and SQL transformation

End result sorts

When executing a ResultQuery, there are several types of End result supported by jOOQ, End result being the default:

End result

The End result sort is a Record<File> with a whole lot of mapping comfort API. It fashions an eagerly fetched JDBC ResultSet, which accommodates all the outcomes from the database and no extra reference to the ResultSet itself. That is helpful when the end result set is reasonably sized.

Cursor

The Cursor sort is an Iterable<File> with comparable mapping comfort API because the End result sort, however it accommodates an open JDBC ResultSet, permitting for fetching information from the server in a lazy manner. That is helpful when the end result set is large.

File

A File is a base sort for a database report. It permits subject primarily based entry of particular person attributes in addition to mapping comfort into customized information sorts. It specialises as:

Bookmark this

Discovered this record helpful? Bookmark it, as we’ll add extra sorts sooner or later in case new essential ideas come up.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments