Hello Aaron,

Comments inline...

> Java doesn't guarantee the order of fields in a class. So there is no
> guarantee that the fields declared in the table type are added to the table
> instance in the order in which they are declared in the source.

Hmm, that would be quite a killer for jOOQ-generated code. What made
you think so? Both static and instance initialisers must be executed
in lexicographic order as defined in the Java source code.

The JLS specifies how class and instance fields are to be initialised:
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2
http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.6
... and other chapters.

Or did you mean the order when accessing fields through reflection?

> For
> performance reasons, I'd really like to access fields by index rather than
> by name. That's a minor issue and easy to fix.

Yes, jOOQ 3.0 generated record classes will do that, too.

> But maybe it would be better
> when the code generator would collect all fields of a table in an array and
> add that in one go to fixate the order.

Yes, I was planning to do that. Those internal table constructors
should probably initialise an empty Field<?>[], and fields should
register themselves at their well-known position.

> That said, I created a dynamic table and that works pretty. It needs about
> twice as much code as my original solution, though :-/ What I'd really like
> to be able to create a record type from a table instance ignoring generics
> and things like that. I'm not sure if that was possible with the current
> design of jOOQ and what it would mean.

Could you elaborate on that, please?

> A bigger problem is org.jooq.impl.AbstractSubSelect.getRecordType() because
> it ignores my dynamic record type since I can't use "select *" and without
> the factory/config changes I proposed earlier, this is a dead end.

An example would help. I'm not sure where you're running into problems, here...

> The next attempt was to add the fields I need in the constructor of my
> class. Since I'm querying many tables, I need a way to tell the result
> processor which row is from which table. For that, I'm adding a value
> column. Sadly,
>
> getFieldList().add( Factory.val( tableId ) );
>
> doesn't work because FieldList is an internal type. Casting to
> List<Field<?>> solved that.

Yes, that type leaked to the outside world, as getFieldList() was
protected. That should be fixed in jOOQ 3.0

> That got me pretty far until I tried to UNION ALL my individual queries
> which fails with:
>
> java.lang.ClassCastException: org.jooq.impl.Union cannot be cast to
> org.jooq.SimpleSelectQuery
>         at
> org.jooq.impl.SimpleSelectImpl.getQuery(SimpleSelectImpl.java:103)
>         at
> org.jooq.impl.SimpleSelectImpl.unionAll(SimpleSelectImpl.java:343)
>         at
> com.avanon.blu.jooq.dao.gbl.QuickSearchQueryBuilder.extendQuery(QuickSearchQueryBuilder.java:48)

Yes... this originates from a very early design problem that I hope to
be able to adress with this issue here:
https://github.com/jOOQ/jOOQ/issues/1658

There are too many similar types implementing org.jooq.Select in jOOQ
2.x. These two refactoring steps should have resolved these things in
jOOQ 3.0:
https://github.com/jOOQ/jOOQ/issues/1880
https://github.com/jOOQ/jOOQ/issues/2060

> The queries are created with:
>
>     private void extendQuery( Table<?> table, Field<?> field ) {
>
>         QuickSearchTable dynamicTable = new QuickSearchTable( map, table,
> field );
>
>         @SuppressWarnings( { "rawtypes", "unchecked" } )
>         Select<QuickSearchRecord> step = (Select) create
>             .selectFrom( dynamicTable )
>             .where( field.like( pattern ) )
>         ;
>
>         if( null == query ) {
>             query = step;
>         } else {
>             query = query.unionAll( step );
>         }
>     }
>
> Why can't I create a union of queries created with selectFrom()?

The aforementioned design issue keeps you from doing it. Does it work
when calling getQuery() on query and step?

Cheers
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to