6.6. jOOQ Coding Rules
6.6.1. Table/Field References
Generated constants must be used. Tables and columns must not be referenced using strings.
java
// Correct (using generated constants)
dsl.selectFrom(USERS).where(USERS.EMAIL.eq(email));
// Incorrect (using strings)
dsl.selectFrom(DSL.table("users")).where(DSL.field("email").eq(email));6.6.2. Record to DTO Conversion
Logic for converting Records to DTOs must be written as a static factory method in the DTO.
java
public record UserResponse(
Long id,
String name,
String email,
OffsetDateTime createdAt
) {
public static UserResponse from(UsersRecord record) {
return new UserResponse(
record.getId(),
record.getName(),
record.getEmail(),
record.getCreatedAt()
);
}
}6.6.3. Batch Processing
Batch operations must be used when processing large volumes of data.
java
public void insertBatch(List<CreateUserRequest> requests) {
var inserts = requests.stream()
.map(req -> dsl.insertInto(USERS)
.set(USERS.NAME, req.name())
.set(USERS.EMAIL, req.email()))
.toList();
dsl.batch(inserts).execute();
}6.6.4. Prohibited Patterns
| Prohibited Pattern | Correct Pattern |
|---|---|
DSL.table("users") (string table reference) | USERS (generated constant) |
DSL.field("name") (string field reference) | USERS.NAME (generated constant) |
dsl.execute("SELECT ...") (raw SQL) | Use DSL API |
| Direct use of DSLContext in Controller | Use only in the Repository layer |
Declaring @Transactional in Repository | Declare in the Service layer |
Required
The jOOQ type-safe DSL API must be used. The use of string-based SQL or raw queries will result in a non-conformance determination during TQS certification review.