How to force a type on a perticular column during code generation

131 views
Skip to first unread message

venkatesha murthy

unread,
May 24, 2013, 11:15:43 AM5/24/13
to jooq...@googlegroups.com
Hi

Please help me on how i can a force a perticular data type in java code generated for a column

For ex: if the db is oracle 11g and column is COL_X NUMBER(8); 
if i need to interpret this as BigDecimal always. {We my change the precision to 20 or something later nd so i dont want to keep changin the calling code etc}

thanks
Murthy

Lukas Eder

unread,
May 24, 2013, 11:28:06 AM5/24/13
to jooq...@googlegroups.com
Hello,

There is an undocumented feature that allows you to override the data type jOOQ generates on a per-column basis. I've recently answered a similar question on Stack Overflow:

Essentially, you can force a DataType upon all columns matching a regular expression as such:

<forcedType>
    <name>NUMERIC</name>
    <expressions>YOUR_COLUMN_MATCHING_EXPRESSION_HERE</expressions>
</forcedType>

The content in <name/> has to be any type from SQLDataType. Let me know if this works for you

Cheers
Lukas


2013/5/24 venkatesha murthy <venkatesh...@gmail.com>
Murthy

--
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/groups/opt_out.
 
 

venkatesha murthy

unread,
May 24, 2013, 2:03:59 PM5/24/13
to jooq...@googlegroups.com
Thanks Lucas for the response

However i needed to force BigDecimal (i.e NUMERIC) upon a column called DAY_KEY which is a part of table say IP_AGGR.
As its a NUMBER(8) in oracle its always becoming Integer even with the above suggested forcedType as used below.  Please help.
<forcedTypes>
<forcedType>
<name>NUMERIC</name>
<expressions>.*\.DAY_KEY.*</expressions>
</forcedType>
</forcedTypes>
</database>
<generate>
<records>false</records>
</generate>

venkatesha murthy

unread,
May 24, 2013, 3:50:16 PM5/24/13
to jooq...@googlegroups.com
Hi Lukas

I missed sying that iam using jooq-2.6.1

thanx
murthy


--
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/kdUfWI1DEzQ/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.

Lukas Eder

unread,
May 25, 2013, 3:32:49 AM5/25/13
to jooq...@googlegroups.com
Yes, you're right. I've tried and it doesn't work on 3.1-SNAPSHOT either. The code generator cannot "shake off" the precision and scale information from the original type contained in the database. Forcing the type to NUMBER(20) doesn't work either as the additional precision information is ignored by the code generator.

I have registered #2486 for jOOQ 3.1 to fix this:

This should allow to rewrite a type to a specific other type using optional precision, scale, and length information. For instance:

<forcedType>
    <name>NUMBER(20)</name>
    <expressions>(?i:(.*?.)?T_AUTHOR.ID)</expressions>
</forcedType>

In the mean time, I'm afraid that you would have to patch AbstractTypedElementDefinition yourself to fix this problem.

Cheers
Lukas



2013/5/24 venkatesha murthy <venkatesh...@gmail.com>
Hi 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 jooq-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages