Mocking non-Table fields?

629 views
Skip to first unread message

Deven Phillips

unread,
Jun 16, 2014, 2:11:18 PM6/16/14
to jooq...@googlegroups.com
I saw this:


and the related issue:


But I don't think it addresses the question I have...


I am creating a query:

create.select(
        CUSTOMER.NAME.as("name"), 
        CUSTOMER.CODE.as("code"), 
        concat(val("/v3/customer/"), CUSTOMER.CODE, val("/vdc")).as("vdc"))
    .where(CUSTOMER.CODE.eq(code));

When I create a MockDataProvider, I can use CUSTOMER.CODE and CUSTOMER.NAME as field identifiers, but how do I identify the calculated field in the MockDataProvider?

E.g.:

Result<CustomerRecord> result = create.newResult(CUSTOMER);
result.add(create.newRecord(CUSTOMER));
result.get(0).setValue(CUSTOMER.NAME, "John Doe");
result.get(0).setValue(CUSTOMER.CODE, "29793408");
result.get(0).setValue(*****What can I put here?!?!*****, "/v3/customer/29793408/vdc");

Any help would be greatly appreciated!!

Deven

Lukas Eder

unread,
Jun 16, 2014, 2:22:35 PM6/16/14
to jooq...@googlegroups.com
When you select "name", "code" and "vdc", you will also have to provide values for exactly the same fields, e.g. fieldByName("name"), fieldByName("code"), etc... Field identifiers are case-sensitive in jOOQ.


--
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 jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Deven Phillips

unread,
Jun 16, 2014, 2:24:45 PM6/16/14
to jooq...@googlegroups.com
Lukas,

    Yes, and in other iterations I have done that like:

result.get(0).setValue(CUSTOMER.NAME.as("name"), "John Doe");

But that still doesn't answer my real question of how to handle the calculated field? Or did I not understand you completely?

Thanks,

Deven

Lukas Eder

unread,
Jun 16, 2014, 2:28:52 PM6/16/14
to jooq...@googlegroups.com
You have to provide a value for a field whose name is "vdc".

I understand the source of confusion now, though. You're creating a Result<CustomerRecord>, when you really want to create a Result<Record3<String, String, String>> for this very specific query.

Use DSLContext.newRecord(Field, Field, Field) to construct such records.

Deven Phillips

unread,
Jun 16, 2014, 2:31:01 PM6/16/14
to jooq...@googlegroups.com
OK, I can follow that, but how do I create an instance of type "Field" with a name "vdc" and type of "String"? So far, I just see that I would have to create an anonymous implementation of the Field interface and implement all of the methods... Is there a better way?

Thanks in advance and thanks for the fast replies!!

Deven

Deven Phillips

unread,
Jun 16, 2014, 2:34:02 PM6/16/14
to jooq...@googlegroups.com
Also, trying to do something like:

Result<Record3<Field<String>, Field<String>, Field<String>>> result = create.newResult(*****WHAT DO I PUT HERE*****);

That's problematic as well...

Deven

Lukas Eder

unread,
Jun 16, 2014, 2:34:16 PM6/16/14
to jooq...@googlegroups.com
2014-06-16 20:31 GMT+02:00 Deven Phillips <deven.p...@gmail.com>:
OK, I can follow that, but how do I create an instance of type "Field" with a name "vdc" and type of "String"? So far, I just see that I would have to create an anonymous implementation of the Field interface and implement all of the methods... Is there a better way?

Thousands of ways :-)
For instance, DSL.fieldByName, as suggested previously:

 
Thanks in advance and thanks for the fast replies!!

No worries. I happen to do something quite boring next to answering mails just now ;-)

Lukas Eder

unread,
Jun 16, 2014, 2:36:18 PM6/16/14
to jooq...@googlegroups.com
Indeed, the missing methods required to create such a Result will be added in jOOQ 3.4.0. You've already found the relevant issue for that:

You have at least these two options:
- Upgrading to a version checked out and built from GitHub
- Creating new org.jooq.impl.ResultImpl instances through reflection

Deven Phillips

unread,
Jun 16, 2014, 2:40:47 PM6/16/14
to jooq...@googlegroups.com
Aha!!!! And enlightenment is found... Thank you!

You were EXCEPTIONALLY helpful.. I greatly appreciate the assistance!

Deven

Lukas Eder

unread,
Jun 16, 2014, 6:01:51 PM6/16/14
to jooq...@googlegroups.com
Great, glad I could help you today,

Cheers
Lukas
Reply all
Reply to author
Forward
0 new messages