Hi Lukas,

Thank you for your suggestions these are very useful indeed: the first 
mapping alternative already reads much fluently;
the second is even fancier and I'm tempted by it.

I've just tried both and (of course) they work ;) What keeps me of using 
the second option immediately are the possible
less descriptive (column) names coming from the database tables... 

Concerning the thread safety issue, I will have to study how to best do 
this in the bigger picture of the layer talking to
jOOQ. How do jOOQ users generally handle this?

Best regards,

Gian

On Monday, March 30, 2015 at 6:28:38 PM UTC+2, Lukas Eder wrote:
>
> Hi GIan
>
> Please find my comments inline
>
> 2015-03-30 10:57 GMT+02:00 Gian <[email protected] <javascript:>>:
>
>> Good morning all,
>>
>> As I am learning/evaluating jOOQ I'm wondering whether the approach below
>> for creating pojos out of routine calls is 'acceptable' when using jOOQ 
>> or
>> whether you have better alternatives...
>>
>> I want to hide the jOOQ layer from the layers above.
>>
>> public UsersRepositoryImpl() throws SQLException {
>>     context = Connection.getDslContext();
>>     searchUsers = new SearchPublic();
>>
>> Watch out with this line. A Routine instance is actually an instance of a 
> routine call. This will not be thread-safe usage of SearchPublic...
>
>> @Override
>> public List<User> findAll() {
>>     searchUsers.execute(context.configuration());
>>     Result<Record> searchResults = searchUsers.getORefList();
>>     for (Record r : searchResults) {
>>         User user = new User();
>>         user.setId(((BigInteger) r.getValue(PER_ID)).longValue());
>>         user.setFullName((String) r.getValue(FULLNAME));
>>         user.setOffice((String) r.getValue(OFFICE));
>>         user.setPhone((r.getValue(PHONE)).toString());
>>         users.add(user);
>>     }
>>     return users;
>> }
>>
>> You can do it this way. Note that there are a couple of other options 
> that you can explore, such as jOOQ's built-in data type conversion. Some 
> examples:
>
>         user.setId(r.getValue(PER_ID, long.class));
>
>         user.setPhone(r.getValue(PHONE, String.class));
>
> Also, if you follow strict naming conventions between the columns returned 
> from the database and the attributes in your POJO, you can use jOOQ's 
> DefaultRecordMapper to implement the above mapping. This is documented here:
>
> - 
> http://www.jooq.org/javadoc/latest/org/jooq/impl/DefaultRecordMapper.html
> - 
> http://www.jooq.org/doc/latest/manual/sql-execution/fetching/recordmapper/
>
> This chapter explains how you can override the DefaultRecordMapper:
>
> - 
> http://www.jooq.org/doc/latest/manual/sql-execution/fetching/pojos-with-recordmapper-provider
>
> With this in place, you can then map records to users like this:
>
> @Override
> public List<User> findAll() {
>     searchUsers.execute(context.configuration());
>     return searchUsers.getORefList().into(User.class);
> }
>
> But again, this will require following strict naming conventions, which 
> doesn't seem to be the case in your example.
>
> Hope this helps,
> Lukas
>
>

-- 
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