适用于版本: Dev (3.21) | 最新 (3.20) | 3.19 | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11

类型安全

适用于 ✅ 开源版   ✅ 专业版   ✅ 企业版

由集合运算符组合的度数小于 22 的两个子查询需要具有相同的度数,并且在大多数数据库中也需要具有相同的类型。 jOOQ 3.0 引入了 Typesafe Record[N] 类型,有助于编译时检查这些约束

// Some sample SELECT statements
Select<Record2<Integer, String>>  s1 = select(BOOK.ID, BOOK.TITLE).from(BOOK);
Select<Record1<Integer>>          s2 = selectOne();
Select<Record2<Integer, Integer>> s3 = select(one(), zero());
Select<Record2<Integer, String>>  s4 = select(one(), inline("abc"));

// Let's try to combine them:
s1.union(s2); // Doesn't compile because of a degree mismatch. Expected: Record2<...>, got: Record1<...>
s1.union(s3); // Doesn't compile because of a type mismatch. Expected: <Integer, String>, got: <Integer, Integer>
s1.union(s4); // OK. The two Record[N] types match

反馈

您对此页面有任何反馈吗? 我们很乐意倾听!

The jOOQ Logo