Reader small image

You're reading from  jOOQ Masterclass

Product typeBook
Published inAug 2022
Reading LevelBeginner
PublisherPackt
ISBN-139781800566897
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Anghel Leonard
Anghel Leonard
author image
Anghel Leonard

Anghel Leonard is a Chief Technology Strategist and independent consultant with 20+ years of experience in the Java ecosystem. In daily work, he is focused on architecting and developing Java distributed applications that empower robust architectures, clean code, and high-performance. Also passionate about coaching, mentoring and technical leadership. He is the author of several books, videos and dozens of articles related to Java technologies.
Read more about Anghel Leonard

Right arrow

Writing dynamic queries

Commonly, a dynamic query contains no or some fixed parts and some other parts that can be appended at runtime to form a query that corresponds to a certain scenario or use case.

Important Note

In jOOQ, even when they look like static queries (due to jOOQ's API design), every SQL is dynamic; therefore, it can be broken up into query parts that can be fluently glued back in any valid jOOQ query. We already have covered this aspect in Chapter 3, jOOQ Core Concepts, in the Understanding the jOOQ fluent API section.

Dynamically creating an SQL statement on the fly is one of the favorite topics of jOOQ, so let's try to cover some approaches that can be useful in real applications.

Using the ternary operator

The Java ternary operator (?) is probably the simplest approach for shaping a query at runtime. Check out this sample:

public List<ProductRecord> fetchCarsOrNoCars(
       float buyPrice, boolean...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
jOOQ Masterclass
Published in: Aug 2022Publisher: PacktISBN-13: 9781800566897

Author (1)

author image
Anghel Leonard

Anghel Leonard is a Chief Technology Strategist and independent consultant with 20+ years of experience in the Java ecosystem. In daily work, he is focused on architecting and developing Java distributed applications that empower robust architectures, clean code, and high-performance. Also passionate about coaching, mentoring and technical leadership. He is the author of several books, videos and dozens of articles related to Java technologies.
Read more about Anghel Leonard