如何创建我自己的 jOOQ 结果?

How to create my own jOOQ result?

我有一个来自 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 );

如有任何帮助,我们将不胜感激!

谢谢!


编辑 (16-NOV-2015/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

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

除非您想求助于反射(不要),否则请使用

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