>
> > My guess is that I could use ExecuteListener for that but which method 
> would 
> > be the best place to assign the PK? 
>
> So I'm guessing that your generator is implemented in Java and you 
> cannot use triggers to fill in the PK value... What is the reason why 
> you wouldn't implement PK generation in a DAO layer "on top" of jOOQ, 
> supplying the correct PK value to jOOQ? 
>

Because that's boring :-)

No, really, I use a central PK generator for all instances, so it would 
make sense to inject it in a single place, too. Plus it's something that 
needs to be done all the time - it would be thousands of lines of code that 
devs wouldn't have to write.

I also don't want to encourage developers to clone database rows by 
overwriting the PK and calling "store()". If they don't see how the PK is 
assigned, they're not going to try to mess with it - I hope.
 

> If you really want to do this with jOOQ, ExecuteListener might be a 
> good place to start.


Good. This leads to two questions:

1. How do I know this is an insert statement? I could check 
"ctx.getSQL().startsWith("INSERT")" but maybe there is a better way?

2. How do I find the PK columns in the statement? In my DB, it's always the 
first column. Is the column order guaranteed? Or can I ask the context for 
the index to which a org.jooq.TableField was bound?

Regards,

A. Digulla

Reply via email to