I'm still missing something. My code is
private final DataType<LocalDate> dateType =
SQLDataType.DATE.asConvertedDataType(new
LocalDateConverter());
private final Field<LocalDate> dateField =
DSL.field(DSL.name("jooqtest", "dt"), dateType);
@Test
public void testDate() throws Exception {
try (DSLContext ctx = DSL.using(connectionProvider,
SQLDialect.POSTGRES)) {
ResultQuery query = ctx.resultQuery("select dt from jooqtest
limit 1");
Record record = ctx.fetchOne(query);
switch(record.field(0).getDataType().getSQLType()) {
case Types.DATE:
Object obj = record.get(dateField);
System.out.println("object class: " +
obj.getClass().getName());
break;
default:
System.out.println("type: " +
dateField.getDataType().getSQLDataType());
}
}
and I get
object class: java.sql.Date
instead of org.joda.time.LocalDate. I used the switch statement to ensure
I'm specifying the correct SQLDataType.x.asConvertedDataType() value. The
converter is a straightforward converter from java.sql.Date to
org.joda.time.LocalDate.
I tried a couple other combinations. If I change the code to
Object obj = record.get(0, new LocalDateConverter());
or
Object obj = record.get(record.field(0), new
LocalDateConverter());
it works but if I change it to
Object obj = record.get(dateField, new
LocalDateConverter());
I get a compilation error. That doesn't surprise me but I don't know why
the first bit of code didn't work then.
On Tue, Mar 20, 2018 at 2:54 AM, Lukas Eder <[email protected]> wrote:
>
>
> 2018-03-19 17:24 GMT+01:00 Bear Giles <[email protected]>:
>
>> Yes, the forcedType should go a long way towards cleaning up our code.
>> You should probably mention it in the javadoc for DataType, Binding, and
>> Converter. :-)
>>
>
> That is a very good idea! I've created a feature request for this:
> https://github.com/jOOQ/jOOQ/issues/7331
>
>
>> What did you have in mind? The connection details and schema are
>> provided by the user at runtime so our options are limited but we could set
>> up an empty schema if necessary. Would that generate the standard classes
>> with converters we specify or is it all hidden in schema-specific calls? Or
>> were you thinking of setting a runtime flag?
>>
>
> The idea is that generated code is really just a convenience for something
> you can create dynamically at runtime:
>
> DataType<MyType> type = SQLDataType.VARCHAR.asConvertedDataType(new
> MyTypeConverter());
> Field<MyType> field = field(name("my_table", "my_field"), type);
>
>
> I hope this clarifies the idea a bit.
> Lukas
>
> --
> 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/mVAv6TQfApg/unsubscribe.
> To unsubscribe from this group and all its topics, 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.