2

I have a Result from a jOOQ fetch() that I turn into a Collection and then do various manipulations on it.

I then want to turn it back into a import org.jooq.Result. (I confess I want to do this because I want to be able to use functions like formatCSV and formatJSON so if there is a better way to achieve this, I'm open to it!)

I'm having trouble figuring out how to instantiate the new result though. I've tried several different means:

// 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 );

Any help would be appreciated!

Thanks!


edit (16-NOV-2015/9:16aEST):

Here is how I did it:

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

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

        return tempResult.formatCSV();

I don't like that the tempResult gets all the records only to clear them out. Is there a way to add a .where( false ) to the .into?

danielc
  • 509
  • 6
  • 19
  • *"Is there a way to add a .where( false ) to the .into"* - no there isn't. There doesn't seem to be a good enough use-case for such a `where()` method.... – Lukas Eder Nov 16 '15 at 14:33

1 Answers1

4

You cannot instantiate the ResultsImpl internal class, because it is package-private.

Unless you'd like to resort to using reflection (don't), use

DSL.using(configuration).newResult(cursorFields);
Community
  • 1
  • 1
Lukas Eder
  • 211,314
  • 129
  • 689
  • 1,509
  • I modified the original post to show what I ended up with... I don't really like it, but it seems to work. What I don't like is having to clear the results - it's inefficient. – danielc Nov 16 '15 at 14:13
  • @danielc: Interesting workaround :) You know, you can answer your own questions here on Stack Overflow... – Lukas Eder Nov 16 '15 at 14:33