On Tuesday, February 12, 2013 12:09:38 PM UTC+1, digulla wrote:
As usual, the devil is in the details. After trying this, I ran into a few
obstacles:
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. 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. 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.
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.
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.
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.
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)
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()?
Regards,
A. Digulla
--
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.