【问题标题】:Why there is no orderBy(Collection<Field> fields) method in jooq?为什么 jooq 中没有 orderBy(Collection<Field> fields) 方法?
【发布时间】:2018-03-22 20:58:33
【问题描述】:

在 Jooq api 中有

...
SelectSeekStepN<R> orderBy(Collection<? extends SortField<?>> fields);

SelectSeekStepN<R> orderBy(Field<?>... fields);
...

为什么没有

SelectSeekStepN<R> orderBy(Collection<? extends Field<?>> 

这使得它实际上与groupBy() 方法agruments 不一致。

有方法:

SelectHavingStep<R> groupBy(GroupField... fields);
SelectHavingStep<R> groupBy(Collection<? extends GroupField> fields);

每个Field 都实现了GroupField,所以我可以使用Collection&lt;Field&gt; 参数调用它。

【问题讨论】:

    标签: database jooq


    【解决方案1】:

    在jOOQ 3.10之前,已经有了签名的方法

    orderBy(Collection<? extends SortField<?>>)
    

    很遗憾你不能使用它,因为SortField 不是Field 的超类型。这在 jOOQ 3.10 中使用 #6327 修复,当时引入了新的 OrderField 类型,它是之前两种类型的超类型。对现有的 orderBy 方法进行了改进,现在可以接受您的集合的超类型:

    orderBy(Collection<? extends OrderField<?>>)
    

    ...这意味着您现在可以将List&lt;Field&lt;?&gt;&gt; 传递给该方法。

    【讨论】:

    • 似乎这种不一致性在 3.10 中使用由Field 实现的OrderField 接口修复。
    • 在 3.10 之前的版本中,我无法将 Collection&lt;Field&gt; 传递给 orderBy()Field 没有实现 SortField。 (但我可以通过 Field[],因为有 orderBy(Field[].. fields) - 这很奇怪)现在在 3.10 中我可以通过 Collection&lt;Field&gt;,因为 API 中有一个新方法:orderBy(Collection&lt;? extends OrderField&gt; fields)Field 现在实现 OrderField( 3.9 中没有OrderField 接口)。
    • 哦,我明白了,对不起。是的,当然,你完全正确。这就是引入OrderField 的原因 :) 我会修复答案...
    猜你喜欢
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-19
    • 2012-10-01
    • 2019-05-25
    • 2022-01-15
    • 2017-06-19
    相关资源
    最近更新 更多