Hi Jouni, >> What would you need this information for? Maybe there is another way >> to know this. > > I have record manipulation on one layer and storing is done on other layer. > Storing part can do different type of logging depending on the operation > (=insert, update, nothing).
If this is purely about logging, you might find the ExecuteListener API useful for your purpose: http://www.jooq.org/doc/2.5/manual/sql-execution/execute-listeners/ http://www.jooq.org/javadoc/latest/org/jooq/ExecuteListener.html For instance, you could perform this check: public class MyListener extends DefaultExecuteListener { public void end(ExecuteContext ctx) { if (ctx.query() instanceof Insert) { // Is insert } else if (ctx.query() instanceof Update) { // Is update } } } > Is it possible to have a function that returns the type of last executed > operation in db. > > E.g. > Author a = ... > a.store() > Operation op = a.getLastOpetion(); > if ( op == Operation.INSERT ) > ... This is indeed an option. I have registered feature request #1865 for this. https://github.com/jOOQ/jOOQ/issues/1865 I'll think about other options too as I feel that a "getLastOperation()" method is a bit of a quirk, similar to JDBC's ResultSet.wasNull(). But it is an option. > Author a = ... > a.store() > Operation op = factory.getLastOpetion(); > if ( op == Operation.INSERT ) That's the wrong spot to implement this. This wouldn't suit batch operations, or store() operations that use an ExecuteListener-injected Connection, in case of which no factory reference might be available: http://www.jooq.org/javadoc/latest/org/jooq/ExecuteListener.html#start(org.jooq.ExecuteContext) Besides, the Factory can also execute plain SQL queries, where such an information would have to map to Operation.UNKNOWN > or even better > > factory.getNumberOfInsertedRows() > factory.getNumberOfUpdatedRows() This would suit batch operations, but the "Factory problems" mentioned before would remain the same. I really think that this information has to stay close to the store() methods, as they're the only ones causing this "problem" of not knowing whether an INSERT or an UPDATE was performed. >> That API suggestion feels like internals are allowed to leak to the >> public API. Why would you need this? > > [...] > > My simple result parser creates Author, Book and Language records from > Result<Record>. This involves copying record fields and without setting > isChanged=false afterwards these newly created Author, Book and Language > records have all fields dirty although they are just fetched from db. I made > a temporary resetting solution using reflection, but I would like to replace > it with better / faster solution. I see. Yes that topic is already adressed in some ticket. In the mean time, you might want to consider explicitly executing INSERT / UPDATE operations: INSERT: http://www.jooq.org/javadoc/latest/org/jooq/impl/Factory.html#executeInsert(R) UPDATE: http://www.jooq.org/javadoc/latest/org/jooq/impl/Factory.html#executeUpdate(R) This might also resolve your first issue... Cheers Lukas
