>> > 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. > > It's also in 2.6.2, isn't it?
In this particular case, I was referring to #2154, which will be included in 3.0 and 2.7. https://github.com/jOOQ/jOOQ/issues/2154 The generated getters and setters in records are currently accessing values by field reference, rather than by index. That unnecessarily wastes some CPU cycles, translating the field reference back to the (well-known) index. >> > 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... > > I used this code: > > factory.create() > .select( PK, VALUE, ID ) > .from( dynamicTable ); > > but in this case, the query always returns RecordImpl, not what > dynamicTable.getRecordType() says. > > It took me some time to understand how I can move the "select(...)" part > into dynamicTable. Yes, as soon as you specify a projection (SELECT), jOOQ will make no assumptions about the R-type and blindly return RecordImpl. I'm not 100% happy with Table.getRecordType() and the fact that it is only used *sometimes* with a somewhat fuzzy definition of "sometimes". On an API level, this problem results from the fact that the SQL syntax is defined in an "English-language-way", not in a "logical processing way". Having the projection before the table expression makes it quite difficult to correctly express R-types. One option that you might find useful is to explicitly force the R-type upon the Result, of course: http://www.jooq.org/javadoc/latest/org/jooq/ResultQuery.html#fetchInto(org.jooq.Table) http://www.jooq.org/javadoc/latest/org/jooq/Result.html#into(org.jooq.Table) http://www.jooq.org/javadoc/latest/org/jooq/Record.html#into(org.jooq.Table) >> > 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 > > When you say "fixed", you mean it returns "List<Field>" now? No, I mean that the visibility is reduced to package-private :-) It should not have been visible in the first place. >> > 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? > > Let me try ... no, I can't cast from Select<> to SelectFinalStep (which > contains the method). > > I would have to call getDelegate() without the case but I can't because it's > an internal method. > > That's what I hate about Java: Sometimes, it just doesn't let you do > something that would work because of some stupid, unrelated rule :-( I think > rules are good but there must always be a way to override it. No no, in this case, the jOOQ API has a flaw. I'm very sure about this. It pretends that it can perform a DSL operation, which its DSL implementation really cannot do. At least not in 2.6 > Test case: > > Two tables, each with a PK (Long) and one or two VARCHAR columns: > > create table T1 ( ID BIGINT, V1 VARCHAR(100), V2 VARCHAR(100) ); > create table T2 ( ID BIGINT, V1 VARCHAR(100), V3 VARCHAR(100) ); > > Now create this query from the table's metadata: > > select ID, V1, 1 from T1 where V1 like ? > union all > select ID, V2, 1 from T1 where V2 like ? > union all > select ID, V1, 2 from T2 where V1 like ? > union all > select ID, V3, 2 from T2 where V3 like ? > > i.e. find all columns with the name V* and query them for a value in such a > way that you can get the PK and the actual value and the table (1 == T1, 2 > == T2). Thanks for the test case. I'll try to reproduce and see what's going on. I've registered #2190 for this: https://github.com/jOOQ/jOOQ/issues/2190 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.
