aesthetic improvements to pdf docs

This commit is contained in:
Gavin King 2023-07-14 22:28:13 +02:00
parent ec8d574e4a
commit be75adbec8
3 changed files with 31 additions and 20 deletions

View File

@ -652,14 +652,14 @@ Using the JPA-standard APIs, this would be a `CriteriaBuilder`, and we get it fr
[source,java] [source,java]
---- ----
CriteriaBuilder cb = entityManagerFactory.getCriteriaBuilder(); CriteriaBuilder builder = entityManagerFactory.getCriteriaBuilder();
---- ----
But if we have a `SessionFactory`, we get something much better, a `HibernateCriteriaBuilder`: But if we have a `SessionFactory`, we get something much better, a `HibernateCriteriaBuilder`:
[source,java] [source,java]
---- ----
HibernateCriteriaBuilder cb = sessionFactory.getCriteriaBuilder(); HibernateCriteriaBuilder builder = sessionFactory.getCriteriaBuilder();
---- ----
The `HibernateCriteriaBuilder` extends `CriteriaBuilder` and adds many operations that JPQL doesn't have. The `HibernateCriteriaBuilder` extends `CriteriaBuilder` and adds many operations that JPQL doesn't have.
@ -672,7 +672,7 @@ Either:
[source,java] [source,java]
---- ----
HibernateCriteriaBuilder cb = HibernateCriteriaBuilder builder =
entityManagerFactory.unwrap(SessionFactory.class).getCriteriaBuilder(); entityManagerFactory.unwrap(SessionFactory.class).getCriteriaBuilder();
---- ----
@ -680,7 +680,7 @@ Or simply:
[source,java] [source,java]
---- ----
HibernateCriteriaBuilder cb = HibernateCriteriaBuilder builder =
(HibernateCriteriaBuilder) entityManagerFactory.getCriteriaBuilder(); (HibernateCriteriaBuilder) entityManagerFactory.getCriteriaBuilder();
---- ----
==== ====
@ -689,18 +689,18 @@ We're ready to create a criteria query.
[source,java] [source,java]
---- ----
CriteriaQuery<Book> query = cb.createQuery(Book.class); CriteriaQuery<Book> query = builder.createQuery(Book.class);
Root<Book> book = query.from(Book.class); Root<Book> book = query.from(Book.class);
Predicate where = cb.conjunction(); Predicate where = builder.conjunction();
if (titlePattern != null) { if (titlePattern != null) {
where = cb.and(where, cb.like(book.get(Book_.title), titlePattern)); where = builder.and(where, builder.like(book.get(Book_.title), titlePattern));
} }
if (namePattern != null) { if (namePattern != null) {
Join<Book,Author> author = book.join(Book_.author); Join<Book,Author> author = book.join(Book_.author);
where = cb.and(where, cb.like(author.get(Author_.name), namePattern)); where = builder.and(where, builder.like(author.get(Author_.name), namePattern));
} }
query.select(book).where(where) query.select(book).where(where)
.orderBy(cb.asc(book.get(Book_.title))); .orderBy(builder.asc(book.get(Book_.title)));
---- ----
Here, as before, the classes `Book_` and `Author_` are generated by Hibernate's <<metamodel-generator,JPA Metamodel Generator>>. Here, as before, the classes `Book_` and `Author_` are generated by Hibernate's <<metamodel-generator,JPA Metamodel Generator>>.
@ -739,9 +739,9 @@ Update, insert, and delete queries work similarly:
[source,java] [source,java]
---- ----
CriteriaDelete<Book> delete = cb.createCriteriaDelete(Book.class); CriteriaDelete<Book> delete = builder.createCriteriaDelete(Book.class);
Root<Book> book = delete.from(Book.class); Root<Book> book = delete.from(Book.class);
delete.where(cb.lt(cb.year(book.get(Book_.publicationDate)), 2000)); delete.where(builder.lt(builder.year(book.get(Book_.publicationDate)), 2000));
session.createMutationQuery(delete).executeUpdate(); session.createMutationQuery(delete).executeUpdate();
---- ----
@ -750,11 +750,11 @@ session.createMutationQuery(delete).executeUpdate();
It's even possible to transform a HQL query string to a criteria query, and modify the query programmatically before execution: It's even possible to transform a HQL query string to a criteria query, and modify the query programmatically before execution:
[source,java] [source,java]
---- ----
HibernateCriteriaBuilder cb = sessionFactory.getCriteriaBuilder(); HibernateCriteriaBuilder builder = sessionFactory.getCriteriaBuilder();
var query = cb.createQuery("from Book where year(publicationDate) > 2000", Book.class); var query = builder.createQuery("from Book where year(publicationDate) > 2000", Book.class);
var root = (Root<Book>) query.getRootList().get(0); var root = (Root<Book>) query.getRootList().get(0);
query.where(cb.like(root.get(Book_.title), cb.literal("Hibernate%"))); query.where(builder.like(root.get(Book_.title), builder.literal("Hibernate%")));
query.orderBy(cb.asc(root.get(Book_.title)), cb.desc(root.get(Book_.isbn))); query.orderBy(builder.asc(root.get(Book_.title)), builder.desc(root.get(Book_.isbn)));
List<Book> matchingBooks = session.createSelectionQuery(query).getResultList(); List<Book> matchingBooks = session.createSelectionQuery(query).getResultList();
---- ----
==== ====
@ -992,13 +992,13 @@ Consider the following code:
[source,java] [source,java]
---- ----
var cb = sessionFactory.getCriteriaBuilder(); var builder = sessionFactory.getCriteriaBuilder();
var query = cb.createTupleQuery(); var query = builder.createTupleQuery();
var book = query.from(Book.class); var book = query.from(Book.class);
var bookTitle = book.get(Book_.title); var bookTitle = book.get(Book_.title);
var bookIsbn = book.get(Book_.isbn); var bookIsbn = book.get(Book_.isbn);
var bookPrice = book.get(Book_.price); var bookPrice = book.get(Book_.price);
query.select(cb.tuple(bookTitle, bookIsbn, bookPrice)); query.select(builder.tuple(bookTitle, bookIsbn, bookPrice));
var resultList = session.createSelectionQuery(query).getResultList(); var resultList = session.createSelectionQuery(query).getResultList();
for (var result: resultList) { for (var result: resultList) {
String title = result.get(bookTitle); String title = result.get(bookTitle);

View File

@ -609,11 +609,11 @@ JPA provides a `@Lob` annotation which specifies that a field should be persiste
**** ****
What the spec actually says is that the field should be persisted What the spec actually says is that the field should be persisted
> as a large object to a database-supported large object type. > ...as a large object to a database-supported large object type.
It's quite unclear what this means, and the spec goes on to say that It's quite unclear what this means, and the spec goes on to say that
> the treatment of the `Lob` annotation is provider-dependent > ...the treatment of the `Lob` annotation is provider-dependent...
which doesn't help much. which doesn't help much.
**** ****
@ -627,6 +627,7 @@ So unless you specifically need to use these JDBC LOB APIs, you _don't_ need the
Instead, as we just saw in <<column-lengths>>, all you need is to specify a large enough column `length` to accommodate the data you plan to write to that column. Instead, as we just saw in <<column-lengths>>, all you need is to specify a large enough column `length` to accommodate the data you plan to write to that column.
[%unbreakable]
[WARNING] [WARNING]
// .PostgreSQL `BYTEA` and `TEXT` // .PostgreSQL `BYTEA` and `TEXT`
==== ====

View File

@ -62,10 +62,20 @@ sidebar:
title: title:
align: center align: center
admonition: admonition:
label:
vertical-align: top
padding: [4, 8, 4, 8]
column-rule: column-rule:
style: solid style: solid
width: 3 width: 3
color: #f0f0f0 color: #f0f0f0
icon:
tip:
stroke-color: #FFC300
warning:
stroke-color: #FF5733
caution:
stroke-color: #FF5733
heading: heading:
font: font:
color: #b22222 color: #b22222