FYI, until jOOQ 3.4 comes out, the reflection method worked perfectly for 
me. Here is my Scala implementation I added in to my database unit test 
base trait:

  def newResult[R <: Record](configuration: Configuration, fields: 
Array[Field[_]]): Result[R] = {
    val constructor = Class.forName("org.jooq.impl.ResultImpl")
      .getDeclaredConstructor(classOf[Configuration], 
classOf[Array[Field[_]]])
    constructor.setAccessible(true)
    constructor.newInstance(configuration, fields).asInstanceOf[Result[R]]
  }

Regards,
Raman



On Thursday, March 20, 2014 4:37:15 AM UTC-4, Lukas Eder wrote:
>
> Hi Guillaume,
>
> Thanks for pointing this out. You're right, this is missing. There should 
> be overloaded methods like:
>
> <T1> Result<Record1<T1>>     newResult(Field<T1> field1);
>
> <T2> Result<Record2<T1, T2>> newResult(Field<T1> field1, Field<T2> field2);
>
>
> Similar methods exist for constructing records, but not for constructing 
> Results. I have registered issue #3139 for this:
> https://github.com/jOOQ/jOOQ/issues/3139
>
> As a workaround, you can patch jOOQ to construct such Result objects 
> yourself. If you look at the existing newResult() method, it only does:
>
>     @Override
>     public <R extends Record> Result<R> newResult(Table<R> table) {
>         return new ResultImpl<R>(configuration, table.fields());
>     }
>
> So you could make the ResultImpl accessible through reflection, and pass 
> your own set of fields to the constructor.
>
> Hope this helps,
> Lukas
>
> 2014-03-19 23:02 GMT+01:00 <[email protected] <javascript:>>:
>
>> Hi !
>>
>> I'm trying to setup unit tests with jOOQ using MockDataProvider and 
>> MockConnection.
>> I'm having issues setting up a simple unit test where my query does not 
>> return a simple Record.
>>
>> The documentation http://www.jooq.org/doc/3.2/manual/tools/jdbc-mocking/uses 
>> the following:
>>
>>             Result<AuthorRecord> result = create.newResult(AUTHOR);
>>             result.add(create.newRecord(AUTHOR));
>>             result.get(0).setValue(AUTHOR.ID, 1);
>>             result.get(0).setValue(AUTHOR.LAST_NAME, "Orwell");
>>             mock[0] = new MockResult(1, result); 
>>
>>   
>> However, if my jOOQ query is a simple 
>>
>> create.select(DSL.count()).from(AUTHOR))
>>
>> How should I mock the result? I cannot use create.newResult(?)since the 
>> count isn't a Field in any Record.
>> I haven't found a simple way to create a MockResult instance based on a 
>> bunch of fields that are not part of a Record object.
>> Are there any examples of this online?
>>
>> Thanks !
>> Guillaume
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "jOOQ User Group" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups "jOOQ 
User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to