0

How do you lock a record in ActiveJDBC? I've seen the documentation about optimistic locking, but I would like to use pessimistic locking instead. Is there a way to do this, or does locking happen automatically when you use ActiveJDBC transactions?

Thanks!

Hongyi Li
  • 1,059
  • 2
  • 11
  • 19

1 Answers1

1

Locking does not occur in ActiveJDBC. ActiveJDBC models are completely disconnected from the database, as AJ does not even has a notion of a session.

Optimistic locking is supported: http://javalite.io/optimistic_locking

Pessimistic locking is a way to lock a set of rows for some time so that one user only can update them. Please, see CONCUR_UPDATABLE for more information. Generally speaking, pessimistic locking is more trouble than it is worth. ActiveJDBC does not support it. You will have to use plain JDBC for that.

tx

ipolevoy
  • 5,432
  • 2
  • 31
  • 46
  • is there a way to invoke plain JDBC through ActiveJDBC? Or do I have to set up JDBC from scratch to use in parallel with Activejdbc? Also, is there sample code or anything that can help me start on this kind of pessimistic locking? Thanks igor! – Hongyi Li Aug 06 '14 at 18:42
  • You can have a direct access to a connection on current thread: [Base#connection](http://javalite.github.io/activejdbc/org/javalite/activejdbc/Base.html#connection--), at which point you can drop to JDBC level – ipolevoy Aug 08 '14 at 01:28