【问题标题】:How to create my own jOOQ result?如何创建我自己的 jOOQ 结果?
【发布时间】:2016-02-17 01:11:31
【问题描述】:

我有一个来自 jOOQ 的 fetch()Result,我将其转换为 Collection,然后对其进行各种操作。

然后我想把它改回import org.jooq.Result。 (我承认我想这样做是因为我希望能够使用像 formatCSV 这样的功能 和 formatJSON 所以如果有更好的方法来实现这一点,我愿意接受!)

我在弄清楚如何实例化新的result 时遇到了麻烦。我尝试了几种不同的方法:

// ResultImpl cannot be resolved to a type
 ResultImpl<R> newResult1 = new ResultImpl<R>( ctx.configuration(), cursorFields );
 ResultImpl<Record2<Long, String>> newResult2 = new ResultImpl<Record2<Long, String>>( ctx.configuration(), cursorFields );
 Result<Record2<Long, String>> newResult3 = new ResultImpl<Record2<Long, String>>();


// Cannot instantiate the type Result<Record2<Long,String>>
Result<Record2<Long, String>> newResult4 = new Result<Record2<Long, String>>();


// The type org.jooq.impl.ResultsImpl is not visible
Configuration configuration;
// ... would make sure configuration was properly initialized
Result newResult5 = new org.jooq.impl.ResultsImpl.ResultsImpl( configuration );

任何帮助将不胜感激!

谢谢!


编辑(2015 年 11 月 16 日/9:16aEST):

我是这样做的:

        Result<Record> tempResult = null;
        tempResult = getResults().into( getResults().fields() );
        tempResult.clear();

        for (Buffer b : bufferPrimary)
            tempResult.add( b.dataRecord );

        return tempResult.formatCSV();

我不喜欢 tempResult 获取所有记录只是为了清除它们。有没有办法将.where( false ) 添加到.into

【问题讨论】:

  • “有没有办法将 .where(false) 添加到 .into” - 没有。这样的where() 方法似乎没有足够好的用例......

标签: java sql jooq


【解决方案1】:

你不能实例化ResultsImpl内部类,因为它是package-private

除非您想使用反射(不要),否则使用

DSL.using(configuration).newResult(cursorFields);

【讨论】:

  • 我修改了原始帖子以显示我最终得到的结果......我不太喜欢它,但它似乎有效。我不喜欢必须清除结果 - 效率低下。
  • @danielc:有趣的解决方法 :) 你知道,你可以在 Stack Overflow 上回答你自己的问题...
猜你喜欢
  • 1970-01-01
  • 2011-02-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-04
  • 2018-02-05
  • 1970-01-01
相关资源
最近更新 更多