Vasily,

> Your example works only with simple select from one table, I presume.
> I am rarely dealing with such queries, so it won't be a solution for me.

Why wouldn't that work for a "complex" query? You could place a named
parameter wherever you can put Field, today, additionally. And instead
of binding one parameter at a time using .bind(...).bind(...), I'll
also add a SelectBindStep.bind(Map<Parameter<?>, ?>) method... Or are
your queries even more complex than what I imagine? :-)

Maybe I'm missing something? This approach is actually quite similar
to your suggestion. Once named parameters can be specified, they can
also be extracted like today's Query.getBindValues()

> By the way, even more helpful feature would be the ability to declare type
> of query result, isolating type safety issues in a selected place.
> I construct a complex query returning a known set of columns and I would
> have liked to declare a record class for that result. Currently I have not
> found how to make a JOOQ query which would return me records of that type,
> it seems only simple queries agains a single predefined table can be
> strongly typed. It would be nice to define a record class describing a
> result set and tell JOOQ that a query is mapped to that record class and get
> strongly typed query.
> Any possible schema mismatch if any whould then be contained in a single
> place.

That's a very good idea.

Currently, there is the ResultQuery.fetchInto(Class<?>) method, which
is documented in Record.into(Class<?>). It allows for projecting
results onto user-defined classes, which have no dependencies on jOOQ.
The mapping is done either using JPA-annotations, or using naming
conventions. It would be easy to add a method like <R extends
TableRecord> R ResultQuery.fetchInto(Table<R>), where you can use your
custom Table, TableRecord implementations for increased type-safety.
Is that what you have in mind?

I filed this as feature request #916:
https://sourceforge.net/apps/trac/jooq/ticket/916

By the way: one way you could also achieve this is by creating views,
if that's acceptable.

Cheers
Lukas

Reply via email to