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? Binding<T,X> also needs to 
return a Converter<T,X>, right?
And this would only work if I keep <dateAsTimestamp/>, right? 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?

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?
>
> It's a cool and versatile concept. But I haven't wrapped my head around it 
> yet. :o)
>
> Sascha.
>
> Am Mittwoch, 26. November 2014 10:10:25 UTC+1 schrieb Lukas Eder:
>>
>> Hi Sascha,
>>
>> Thanks for your report. This might be an issue with the combination of 
>> <dateAsTimestamp/> and your own custom binding, which we should resolve on 
>> our side. I've created an issue for this:
>> https://github.com/jOOQ/jOOQ/issues/3806
>>
>> Are you still using <dateAsTimestamp/> ?
>>
>> The way it works:
>>
>> - dateAsTimestamp has been retrofitted to produce 
>> a org.jooq.impl.DateAsTimestampBinding on the column, plus it still 
>> rewrites the type from SQLDataType.DATE to SQLDataType.TIMESTAMP.
>> - org.jooq.impl.DateAsTimestampBinding contains the fix for the 
>> performance issue that we're discussing here
>> - you can combine converters and bindings, such that Binding<T, X> and 
>> Converter<X, U> convert between
>>   o <T> (the database type, java.sql.Timestamp in this case), 
>>   o <X> (an intermediate type, again java.sql.Timestamp in this case),
>>   o <U> (the user type, JodaDateTime in this case)
>>
>> In any case, the issue here is that either because you have deactivated 
>> <dateAsTimestamp/>, or because of #3806, your SQLDataType.DATE is no longer 
>> rewritten to SQLDataType.TIMESTAMP. When initialising the 
>> Field<JodaDateTime>, <T> is bound to java.sql.Date, while your binding 
>> expects <T> to be bound to java.sql.Timestamp.
>>
>> I see two options:
>>
>> 1. Leave everything in the code generation configuration as it was, it 
>> should work with <dateAsTimestamp/> and your custom converter
>> 2. Write two different bindings, one for <T> = java.sql.Date and one for 
>> <T> = java.sql.Timestamp. Both implementations can be the same, using only 
>> java.sql.Timestamp internally when interacting with JDBC. In fact, you 
>> should then probably delegate both implementations to 
>> org.jooq.impl.DateAsTimestampBinding
>>
>> Let me know if this helps, or if there is still some confusion around 
>> this feature. I'm aware that it is not immediately intuitive...
>>
>> Lukas
>>
>> 2014-11-25 19:45 GMT+01:00 Sascha Herrmann <[email protected]>:
>>
>>> Hi!
>>>
>>> Downloaded 3.5. But I am running into problems with my binding.
>>>
>>> As I said, we're using Joda's DateTime as Java object class for DATE and 
>>> TIMESTAMP. In 3.4 we used a simple converter (<Timestamp, DateTime>) for 
>>> that, combined with setting "<dateAsTimestamp>true</dateAsTimestamp>" in 
>>> the xml.
>>>
>>> Now I tried to do the same with a binding which uses the old converter:
>>>
>>> public class DateTimeBinding
>>>>       implements Binding<Timestamp, DateTime> {
>>>> ....
>>>>   /** The converter. */
>>>>   private DateTimeConverter converter = new DateTimeConverter( );
>>>>
>>>>   /**
>>>>    * @see org.jooq.Binding<java.sql.Timestamp, 
>>>> org.joda.time.DateTime>#converter()
>>>>    */
>>>>   @Override
>>>>   public Converter<Timestamp, DateTime> converter( ) {
>>>>     return converter;
>>>>   }
>>>> .....
>>>
>>>
>>> Then in my settings:
>>>
>>>        <customTypes>
>>>>         <customType>
>>>>           <name>JodaDateTime</name>
>>>>           <type>org.joda.time.DateTime</type>
>>>>           
>>>> <binding>com.ge.med.medora.fiber.dbaccess.DateTimeBinding</binding>
>>>>         </customType>
>>>>       </customTypes>
>>>> ....
>>>>         <forcedType>
>>>>           <name>JodaDateTime</name>
>>>>           <types>DATE|TIMESTAMP.*</types>
>>>>         </forcedType>
>>>
>>>
>>>
>>> During compilation I run into errors. The generator generated something 
>>> like:
>>>
>>>
>>> public final 
>>>> org.jooq.TableField<.....tables.records.PatientRegistrationRecord, 
>>>> org.joda.time.DateTime> PTRG_ARRIVAL_DATE = 
>>>> createField("PTRG_ARRIVAL_DATE", 
>>>> org.jooq.impl.SQLDataType.DATE.nullable(false), this, "", new 
>>>> ..........DateTimeBinding());
>>>
>>>
>>> which doesn't compile.
>>>
>>> Previously the converter created:
>>>
>>> public final 
>>>> org.jooq.TableField<.....tables.records.PatientRegistrationRecord, 
>>>> org.joda.time.DateTime> PTRG_ARRIVAL_DATE = 
>>>> createField("PTRG_ARRIVAL_DATE", org.jooq.impl.SQLDataType.TIMESTAMP, 
>>>> this, 
>>>> "", new .....DateTimeConverter());
>>>
>>>
>>> which did compile.
>>>
>>> Can you spot what's going wrong?
>>>
>>> Thanks,
>>>
>>> Sascha
>>>
>>> -- 
>>> 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.
>>>
>>
>>

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