Hi Lukas,Just a follow on from this discussion.Is there a way to set the records "original" values after a store()?. We can set the changed flag, and reset the value to match the original value, but I couldn't see a way to set the original value itself? I might just be missing some obvious.
The reason being that the original values are used for the optimistic locking check. After a store, then subsequent fail and transaction rollback, I need to manually roll back the original values, or the optimistic lock check will fail next attempt. I hope that makes sense.
Hi Lukas,That did the trick! Thanks! :)In the very simplistic form:Load in any record objects as required, these are usually bound to forms, tables, etc. This can happen in multiple transactions, in several stages as the user needs, etcUser does any changes as needed to the records (inclusing adding records and deleting records)On savetry {open connection & transactionstoreRecordOriginalStaterecord.store() on each changed record (Or delete if deleting)commit transaction} catch (Optimistic Lock Exception) {Special handling involving the user to resolve issues} catch (Any other Exception) {rollback transactionrestore records back to their original state} finally () {
close connection}
So it is important to be able to roll back database changes and not lose information in the records or the optimistic locking will not work afterwards.It's working well now :)UI <-> JOOQ Records <-> Database.It would be fantastic if it could all happen automatically just by calling .store(). That would be "magic". I don't think that should be integrated into JOOQ and the architecture is very application dependent, but it would be great if JOOQ could provide some hooks so I could hook into .store() to do all the additional stuff.
Thinking about it... it is sounding a lot like hibernates flush(). Load a bunch of records, do whatever changes, on calling flush() it persists it to database, with any checks... But I never really liked how hibernate did that :). It would be better to accumulate all the records that you want only in a set, then just attach that set to a connection and .store(). I guess a set <-> transaction auto populating could happen too. We also do a few things like linking related records before storing them (because they don't have primary keys yet), then it stores them in the correct order and populates the foreign keys.
Anyway, I'm happy with how it is working at the moment, it isn't worth the extra effort for me to try and support this flexibility unless I start another project and want to get it in from the start. JOOQ does a great job of what it does. It seems like it would be expanding the scope of jooq to start getting into this other stuff, could almost be a separate project.
Ryan - You have discovered a nice problem to be resolved. I cache Record object at web layer to re-use them across multiple http request, if my transaction is rolled back then my cache object at web layer becomes incorrect also its too hard to track and rollback every record updated in the failed transaction.Lukas - from a framework perspective it would be nice to add rollback() method in UpdatableRecord to bring it back to original state then its upto the transaction layer to call the rollback() method.
--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 jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hello,
2013/8/6 Venkat Sadasivam <venka...@gmail.com>
Ryan - You have discovered a nice problem to be resolved. I cache Record object at web layer to re-use them across multiple http request, if my transaction is rolled back then my cache object at web layer becomes incorrect also its too hard to track and rollback every record updated in the failed transaction.
Lukas - from a framework perspective it would be nice to add rollback() method in UpdatableRecord to bring it back to original state then its upto the transaction layer to call the rollback() method.
The problem here is to know what the "original" state really is.
jOOQ already maintains an "original" state through Record.original(). This state corresponds to what was originally loaded from the database. Upon successful store, this "original" state is set to the Record's value.While I agree that this behaviour is cumbersome when rolling back a transaction, I'm not sure if there's an easy solution to this, which suits all use-cases and transaction models.
The silliest solution to this problem might be to add an UpdatableRecord.refreshOriginal() method, to re-read original values from the database, without affecting the other values. Would that make sense?
CheersLukas
You received this message because you are subscribed to a topic in the Google Groups "jOOQ User Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jooq-user/0bwAOu2LVjo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jooq-user+...@googlegroups.com.
For that to work wouldn't it need to know the original original values?, or at least the original original primary key value, otherwise after it is stored, the original state will be updated, so refreshing it may not be accurate.On 7/08/2013 3:24 PM, Lukas Eder wrote:
Hello,
2013/8/6 Venkat Sadasivam <venka...@gmail.com>
Ryan - You have discovered a nice problem to be resolved. I cache Record object at web layer to re-use them across multiple http request, if my transaction is rolled back then my cache object at web layer becomes incorrect also its too hard to track and rollback every record updated in the failed transaction.
Lukas - from a framework perspective it would be nice to add rollback() method in UpdatableRecord to bring it back to original state then its upto the transaction layer to call the rollback() method.
The problem here is to know what the "original" state really is.
jOOQ already maintains an "original" state through Record.original(). This state corresponds to what was originally loaded from the database. Upon successful store, this "original" state is set to the Record's value.While I agree that this behaviour is cumbersome when rolling back a transaction, I'm not sure if there's an easy solution to this, which suits all use-cases and transaction models.
The silliest solution to this problem might be to add an UpdatableRecord.refreshOriginal() method, to re-read original values from the database, without affecting the other values. Would that make sense?
CheersLukas
It would almost seem to work with all cases it would need record "versioning". Then it could handle savepoints too and roll back to an arbitrary point. Then it is just up to the end implementation to hook in the records with the transaction layer to keep it all in sync.
I think with "versioning", those listeners you are working on, and record "sets" to "track" all your records, you could implement just about any use case you needed to. It is just up to the end implementation to hook it all together in a way that makes sense for them (eg. hooking up a "set" to a transaction so they can be committed and rolled back as a single unit).