2014-11-26 11:29 GMT+01:00 Sascha Herrmann <[email protected]>:
> On second thought:
>
> you can combine converters and bindings .... Binding<T, X> and
>> Converter<X, U>
>
>
> How do I do that? Specify both in the XML?
>
Yes, you can specify both <converter/> and <binding/>
> Binding<T,X> also needs to return a Converter<T,X>, right?
>
Exactly. This is mostly because jOOQ internally needs to get a hold of a
Class<X> instance. Also, all of jOOQ's default binding implementation has
been moved into the new org.jooq.impl.DefaultBinding type, which accepts
custom converters. The idea is that everything keeps working as it always
did, except that users have now much more power inside of jOOQ than they
used to have with simple Converters.
> And this would only work if I keep <dateAsTimestamp/>, right?
>
No, you can replace <dateAsTimestamp/> and do everything with your own
Bindings if you prefer that. Except that <dateAsTimestamp/> rewrote the
SQLDataType as a side-effect, which you cannot do with Bindings, as the <T>
type will remain unchanged.
> If T and X are both java.sql.Timestamp then the SQLDataType needs to be
> TIMESTAMP and the only way to get this is specifying <dateAsTimestamp/>?
> But at some point <dateAsTimestamp/> is going, right?
>
Yes. There's an oversight that we'll fix via #3806. One way to get rid of
<dateAsTimestamp/> already today is this one:
// This is what our class should really be like:
class DateAsTimestampBinding implements Binding<java.sql.Date,
java.sql.Timestamp> {
// internally, operate only on java.sql.Timestamp
}
// Reuse your existing converter
class TimestampToJodaConverter<java.sql.Timestamp, JodaDateTime> {
// ...
}
Now, if we had correctly implemented the DateAsTimestampBinding (in order
to work without the current <dateAsTimestamp/> functionality), then you
could simply register that binding together with your converter and
everything should work
> Sascha
>
> Am Mittwoch, 26. November 2014 11:07:39 UTC+1 schrieb Sascha Herrmann:
>
>> Hi!
>>
>> Thanks for your quick reply. Yes I have removed the <dateAsTimestamp/>
>> (because of the deprecation warning in the generator) and wanted to go with
>> a Binding (after looking at your code in DateAsTimestampBinding and the
>> manual.
>> Just to complete the understanding of the Binding concept ... the whole
>> interaction with low level JDBC is restricted to the methods in the
>> Binding. I can create a Binding with some types <T,U> and then do something
>> completely different on JDBC level in the Binding?
>>
>
Yes. Apart from this Oracle bug, a main driving force for this feature is
support for arbitrary vendor-specific data types, mostly for the PostgreSQL
database. Here's an example of how to bind Jackson data types to the
PostgreSQL "JSON" type (which needs some explicit bind variable casting:
*?::json* or *CAST(? AS JSON)* )
http://stackoverflow.com/a/27146852/521799
It's a cool and versatile concept. But I haven't wrapped my head around it
>> yet. :o)
>>
>
Yes, it's not really very useful for the Oracle database, actually...
--
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.