Hello Lukas,
yes, i would use them, but the jOOQ's records are representing the Database-Layer and each jOOQ record represents a Table. For example:
AuthorRecord represents Table Product
BookRecord represents Table Book
In a SaaS Application we typically need to have an intermediate Layer (DTOs / Domain Transfer Objects) that are containing relationships data,
and this Layer is between the REST-Endpoints and the Database-Layer.
So for example. The Frontend sends a REST POST Request to the backend to insert data. This POST Request contains the data as JSON and
represented by the DTO, so it can contain all relevant data to insert an Author with his Books in one REST-Request instead of many separate REST-Request
and we can also guarantee Transaction-Safety (either the complete REST-Request is inserted into the database or we rollback). This JSON would look like this:
{
"name": "George Orwell",
books: [{
"title": "1984"
}]
}
Now the REST-Layer will parse this JSON and create the AuthorDTO from it. While Parsing the JSON the Setter-Methods of the AuthorDTO are called.
The AuthorDTO contains relationships to other DTOs as well.
public class AuthorDTO {
private String name;
private String birthyear;
private List<BookDTO> books;
}
When the DTOs are Plain Pojos, we will loose the information which of the fields have really be given by the frontend to the backend in the JSON.
After JSON-Derserialization took place we can not know it anymore.
When we later convert the DTOs to the Jooq-Records, we need to have this information present.
Also it is important to separate DTOs from the Database-Layer, because in the DTOs we can decide which fields should be hidden from the frontend
(password-field in the User-Table for example).
In my implementation i did use the Jooq Generated Pojos and the self-written DTOs extend a common base class (AbstractDTO),
so they both save the modified fields. That way in the DAO-Abstraction i can map the changed-fields correctly from the DTOs to the Jooq-Pojos,
and only send the modified fields to the database in the Update-Case. In the Insert-Case all fields are sent to the database.
That way the backend-developers hopefully do not need to fetch records from the database and send them to the frontend, only for the frontend
to change exactly one field to send the update back to the backend (Roundtrip).
Instead the Frontend can fire-and-forget sent the Update to the backend and the one field in the database is updated, without the Frontend needing
to know the complete model as it exists in the database.
Thats the benefit from having the modified-fields and pushing them trough all the layers (REST, DTO, Database)