Thanks Lukas
On Tue, Sep 3, 2013 at 1:39 AM, Lukas Eder <[email protected]> wrote: > > 2013/9/2 Dan <[email protected]> > >> It would be great if it were easy to have a Record implementation that >> delegated to another, especially for the generated record classes. >> >> Example use case 1: I have a record that maps to a few rows joined >> together from 2-3 tables. I can set fields on it using the (verbose) >> non-typesafe methods, but it would be great to use generated setFoo(), >> setBar(), etc methods. I can't go record.into(FirstTable.class).setFoo() >> because that creates a copy - it would be great if I could easily go >> FirstTable.wrap(record).setFoo(x) and have that setFoo() method delegate to >> the underlying wrapped record, SecondTable.wrap(record).setBar(y) affects >> the same record, and so on. >> > > Yes, these kinds of one-to-one relations would often be useful if known to > jOOQ. There had been quite a few discussions around this subject in the > recent past. Currently, jOOQ does not add such cleverness to records. > However, if your join product is guaranteed to be "updatable", why not just > create a database view and make these things transparent to jOOQ? > I remember looking into creating a view and realising mysql couldn't handle insert/update/delete fully properly. Currently I am porting code from a PHP ORM into JOOQ so looking to get things up and running - doesn't necessarily have to be done in the same fashion. In the old code base, one could represent "inheritance" by having table B join to table A in a 1:1 relationship (they shared primary keys) and that would be abstracted away (very similar to a view). I guess a related question is this: Is there a simple way to implement the Record interface? E.g. where one could override key methods such as getValue(field) and have the rest work correctly. (The full interface is huge) If I could even just construct a record with a list of Fields that might be enough for my purposes, but any constructors that work that way are all package private on on package private classes. > >> Example use case 2: Disambiguate fields. If I go dsl.select()... with >> some joins, and the table field names clash, jooq / sql will not complain >> because when generating the SQL jooq disambiguates the field names with >> tables. However in the returned records, it seems that table names are >> ignored and whatever fields came last clobber earlier fields (usually one >> would prefer the other way round, but that's not 100% of the time either). >> > > That shouldn't be the case. If you have an exact match of table name / > field name, you should get the right value, even if field names clash. Can > you provide a test case to reproduce the issue? > I'll try to reproduce this again and make sure I wasn't doing something wrong. This observation is unrelated to what I'm trying to do above. > > >> Being able to get a specific "view" of the record would again be very >> helpful, e.g. FooTable.wrap(record).getId() vs >> BarTable.wrap(record).getId(). Of course that doesn't disambiguate the case >> of table aliasing but that should be easily handled with modest extensions >> to this concept. I think this would be more convenient than being forced >> to explicitly list all the fields to select() and aliasing the clashing >> ones. >> > > There's > http://www.jooq.org/javadoc/latest/org/jooq/Record.html#into(org.jooq.Table), > instead of Table.wrap(Record). Does this help? > As far as I can tell that creates copies of the source record, not views. > > 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. > -- 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.
