Allow a closure to handle locking stale objects

Instead of throwing an exception, allow the user to decide what
happens when locking an object that has changed in the DB, by
passing a closure to DomainObject::lock().