From: Gavin K. <ga...@ap...> - 2002-10-01 04:50:47
|
Hi, I've been thinking about improving Hibernate's locking API recently. Currently your object could be in 3 different states: * No lock, for example if you just called session.update(foo) or if the session was disconnected * Shared lock, for example if you just called session.load(id) or session.find(query) * Exclusive lock, if you called session.loadWithLock(id) or session.lock(foo), or if changes to the object have been flush()ed There is currently no mechanism for upgrading a lock from No lock to Shared lock, ie. to do a version check for an object. So I'm wondering about deprecating Session.lock() and Session.loadWithLock() and replacing them with Session.load(clazz, id, lockMode) Session.load(object, id, lockMode) Session.lock(object, lockMode) I would introduce a new class, public class LockMode { public static final LockMode NONE; public static final LockMode SHARED; public static final LockMode EXCLUSIVE; } Then Session.loadWithLock(clazz, id) == Session.load(clazz, id, LockMode.EXCLUSIVE) Session.lock(foo) == Session.lock(foo, LockMode.EXCLUSIVE) There is also a certain argument for allowing Session.update(foo, lockMode), but thats a bit more difficult to implement, so lets leave it for later.... Ideas + criticisms are very welcome! Gavin |