On Tuesday, February 12, 2013 3:49:25 PM UTC+1, Lukas Eder wrote:

> 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. 
> Or did you mean the order when accessing fields through reflection? 
>

Ah, I didn't think about the difference between class bytecode and 
reflection. I guess it makes sense when the fields can be returned in any 
order from reflection but the execution of initializers is still in 
"source" order.
 

> > 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?
 

> > 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? 
>

Right now, I need an actual type. So Foo has FooRecord. I can't make Foo 
fill, say, DefaultRecord where DefaultRecord is a type shared by many 
dynamic tables.

> 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.
 

> > 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?
 

> > 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.

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).

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.


Reply via email to