HOME

TheInfoList



OR:

jOOQ Object Oriented Querying, commonly known as jOOQ, is a light database-mapping
software library In computer science, a library is a collection of non-volatile resources used by computer programs, often for software development. These may include configuration data, documentation, help data, message templates, pre-written code and subr ...
in
Java Java (; id, Jawa, ; jv, ꦗꦮ; su, ) is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea to the north. With a population of 151.6 million people, Java is the world's most ...
that implements the
active record pattern In software engineering, the active record pattern is an architectural pattern. It is found in software that stores in-memory object data in relational databases. It was named by Martin Fowler in his 2003 book ''Patterns of Enterprise Application ...
. Its purpose is to be both relational and
object oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
by providing a
domain-specific language A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging f ...
to construct queries from classes generated from a
database schema The database schema is the structure of a database described in a formal language supported by the database management system (DBMS). The term "schema" refers to the organization of data as a blueprint of how the database is constructed (divide ...
.


Paradigm

jOOQ claims that SQL should come first in any database integration. Thus, it does not introduce a new textual
query language Query languages, data query languages or database query languages (DQL) are computer languages used to make queries in databases and information systems. A well known example is the Structured Query Language (SQL). Types Broadly, query language ...
, but rather allows for constructing plain SQL from jOOQ objects and code generated from a database schema. jOOQ uses
JDBC Java Database Connectivity (JDBC) is an application programming interface (API) for the programming language Java, which defines how a client may access a database. It is a Java-based data access technology used for Java database connectivity. I ...
to call the underlying SQL queries. While it provides
abstraction Abstraction in its main sense is a conceptual process wherein general rules and concepts are derived from the usage and classification of specific examples, literal ("real" or "concrete") signifiers, first principles, or other methods. "An abst ...
on top of JDBC, jOOQ does not have as much functionality and complexity as standard
object–relational mapping Object–relational mapping (ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between type systems using object-oriented programming languages. This creates, in effect, a "virtual object databas ...
libraries such as
EclipseLink EclipseLink is the open source Eclipse Persistence Services Project from the Eclipse Foundation. The software provides an extensible framework that allows Java developers to interact with various data services, including databases, web services, ...
or
Hibernate Hibernation is a state of minimal activity and metabolic depression undergone by some animal species. Hibernation is a seasonal heterothermy characterized by low body-temperature, slow breathing and heart-rate, and low metabolic rate. It most ...
. jOOQ's closeness to SQL has advantages over typical object–relational mapping libraries. SQL has many features that cannot be used in an
object oriented Object-oriented programming (OOP) is a programming paradigm based on the concept of " objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of pr ...
programming paradigm Programming paradigms are a way to classify programming languages based on their features. Languages can be classified into multiple paradigms. Some paradigms are concerned mainly with implications for the execution model of the language, suc ...
; this set of differences is referred to as the
object–relational impedance mismatch The object–relational impedance mismatch is a set of conceptual and technical difficulties that are often encountered when a relational database management system (RDBMS) is being served by an application program (or multiple application program ...
. By being close to SQL, jOOQ helps to prevent syntax errors and type mapping problems. Also, variable binding is taken care of. It is also possible in jOOQ to create very complex queries, that involve aliasing, unions, nested selects and complex joins. jOOQ also supports database-specific features, such as UDTs, enum types,
stored procedure A stored procedure (also termed proc, storp, sproc, StoPro, StoredProc, StoreProc, sp, or SP) is a subroutine available to applications that access a relational database management system (RDBMS). Such procedures are stored in the database data di ...
s and native functions.


Example

A nested query selecting from an aliased table -- Select authors with books that are sold out SELECT * FROM AUTHOR a WHERE EXISTS (SELECT 1 FROM BOOK WHERE BOOK.STATUS = 'SOLD OUT' AND BOOK.AUTHOR_ID = a.ID); And its equivalent in jOOQ DSL: // Use the aliased table in the select statement create.selectFrom(table("AUTHOR").as("a")) .where(exists(selectOne() .from(table("BOOK")) .where(field("BOOK.STATUS").equal(field("BOOK_STATUS.SOLD_OUT"))) .and(field("BOOK.AUTHOR_ID").equal(field("a.ID"))))); Or more simply, using code generation from the
database In computing, a database is an organized collection of data stored and accessed electronically. Small databases can be stored on a file system, while large databases are hosted on computer clusters or cloud storage. The design of databases span ...
metadata Metadata is "data that provides information about other data", but not the content of the data, such as the text of a message or the image itself. There are many distinct types of metadata, including: * Descriptive metadata – the descriptive ...
to generate constants: // Use the aliased table in the select statement final Author a = AUTHOR.as("a"); create.selectFrom(a) .where(exists(selectOne() .from(BOOK) .where(BOOK.STATUS.equal(BOOK_STATUS.SOLD_OUT)) .and(BOOK.AUTHOR_ID.equal(a.ID))));


See also

* Apache Calcite *
List of object–relational mapping software This is a list of well-known object–relational mapping software. It is not up-to-date or all-inclusive. Java * Apache Cayenne, open-source for Java * Apache OpenJPA, open-source for Java *DataNucleus, open-source JDO and JPA implementation (for ...
*
SQL/OLB SQL/OLB, or ''Object Language Bindings'', is a standard for embedding SQL in Java, commonly known by its prior name as SQLJ (part 0). Besides describing the syntax and semantics of SQLJ, which are typically given relative to JDBC, the standard also ...


References


External links


jOOQ Home



JSR-341



Linq4j

Quaere

QueryDSL
{{Java (Sun) Object-relational mapping Java (programming language) libraries Java enterprise platform