Re: rewrite an insert query at runtime to populate a field with dynamic value

2024-06-07 Thread Dominik Hirt
Hi Alf, thanks for your message. I didn't realise that there was also this option. thanks for the hint, it makes implementation much easier and now works without reflection: private void setModifiedBy(RecordContext ctx) { Field modifiedByField = ctx.recordType().field("modified_by",

Re: rewrite an insert query at runtime to populate a field with dynamic value

2024-06-05 Thread Alf Lervåg
Just curious, is it possible to check if the field is available from the RecordContext by using ctx.recordType().field("modified_by")?Alf Lervåg1. juni 2024 kl. 20:55 skrev Dominik Hirt :If you're using jooq records, you could use a RecordListener like I do for a similar case. My from field is

Re: rewrite an insert query at runtime to populate a field with dynamic value

2024-06-02 Thread Lukas Eder
On Sat, Jun 1, 2024 at 8:55 PM Dominik Hirt wrote: > private Boolean hasModifiedBy(Record dbRecord) { >Boolean result = Boolean.FALSE; > >Method[] methods = dbRecord.getClass().getDeclaredMethods(); >for (Method method : methods) { > if (method.getName().equals("getModifiedBy"))

Re: rewrite an insert query at runtime to populate a field with dynamic value

2024-06-01 Thread Dominik Hirt
If you're using jooq records, you could use a RecordListener like I do for a similar case. My *from* field is *modified_by* and I populate it automatically: /** This RecordListener serves as an interceptor for the record.store() calls and inserts a ‘modified_by’ field if one exists. As it is

Re: rewrite an insert query at runtime to populate a field with dynamic value

2024-05-31 Thread Lukas Eder
Hello, Assuming you cannot use triggers for some reason, one simple way to do this is to: - Intercept all INSERT queries with an ExecuteListener - Use the experimental query object model (QOM) API to set QOM.Insert::$columns and QOM.Insert::$values, if QOM.Insert::$into is the right target table

rewrite an insert query at runtime to populate a field with dynamic value

2024-05-30 Thread 'Gang Luo' via jOOQ User Group
I have a table Foo defined as create table FOO { name varchar(123), from varchar(123) default null } I am using JOOQ 3.16 and already have following code `db.insertInto(Foo).set(Foo.name, "xxx").execute()` everywhere. Now I want to find a way to re-write that query to effectively be