|
| 1 | +///usr/bin/env jbang "$0" "$@" ; exit $? |
| 2 | +//JAVA 25+ |
| 3 | +//DEPS org.jooq:jooq:3.20.11 |
| 4 | + |
| 5 | +import org.jooq.*; |
| 6 | +import org.jooq.impl.DSL; |
| 7 | +import javax.sql.DataSource; |
1 | 8 | import java.util.*; |
2 | 9 |
|
3 | 10 | /// Proof: jdbc-vs-jooq |
4 | 11 | /// Source: content/enterprise/jdbc-vs-jooq.yaml |
5 | | -/// |
6 | | -/// Note: Uses stub types to prove the fluent API compiles without jOOQ dependency. |
7 | | -@interface Table {} |
8 | | - |
9 | | -// Minimal stubs for jOOQ-style API |
10 | | -enum SQLDialect { POSTGRES } |
11 | | -interface Field<T> { |
12 | | - Condition eq(T val); |
13 | | - Condition and(Condition c); |
14 | | - Condition gt(T val); |
15 | | -} |
16 | | -interface Condition {} |
17 | | -interface TableField<R, T> extends Field<T> {} |
18 | | -interface Record {} |
19 | | -interface SelectJoinStep<R> { SelectConditionStep<R> where(Condition c); } |
20 | | -interface SelectConditionStep<R> { <E> List<E> fetchInto(Class<E> cls); } |
21 | | -interface SelectSelectStep<R> { SelectJoinStep<R> from(Object table); } |
22 | | -interface DSLContext { |
23 | | - <R extends Record> SelectSelectStep<R> select(Object... fields); |
| 12 | +class User { |
| 13 | + Long id; String name; String email; |
24 | 14 | } |
25 | 15 |
|
26 | | -record UserTable( |
27 | | - Field<String> DEPARTMENT, |
28 | | - Field<Integer> SALARY, |
29 | | - Field<Long> ID, |
30 | | - Field<String> NAME, |
31 | | - Field<String> EMAIL |
32 | | -) {} |
| 16 | +// Simulating the generated jOOQ table fields (normally produced by jOOQ codegen) |
| 17 | +class USERS { |
| 18 | + static final Field<String> DEPARTMENT = DSL.field(DSL.name("department"), String.class); |
| 19 | + static final Field<Integer> SALARY = DSL.field(DSL.name("salary"), Integer.class); |
| 20 | + static final Field<Long> ID = DSL.field(DSL.name("id"), Long.class); |
| 21 | + static final Field<String> NAME = DSL.field(DSL.name("name"), String.class); |
| 22 | + static final Field<String> EMAIL = DSL.field(DSL.name("email"), String.class); |
| 23 | + static final Table<?> TABLE = DSL.table(DSL.name("users")); |
| 24 | +} |
33 | 25 |
|
34 | | -record User(Long id, String name, String email) {} |
| 26 | +List<User> findByDept(DataSource ds, String department, int minSalary) { |
| 27 | + DSLContext dsl = DSL.using(ds, SQLDialect.POSTGRES); |
35 | 28 |
|
36 | | -class Db { |
37 | | - static final UserTable USERS = new UserTable( |
38 | | - null, null, null, null, null); |
39 | | - static DSLContext dsl; |
| 29 | + return dsl |
| 30 | + .select(USERS.ID, USERS.NAME, USERS.EMAIL) |
| 31 | + .from(USERS.TABLE) |
| 32 | + .where(USERS.DEPARTMENT.eq(department) |
| 33 | + .and(USERS.SALARY.gt(minSalary))) |
| 34 | + .fetchInto(User.class); |
40 | 35 | } |
41 | 36 |
|
42 | | -void main() { |
43 | | - // Structural proof only — real jOOQ requires runtime dependency |
44 | | -} |
| 37 | +void main() {} |
0 commit comments