Hi Colin,
Colin Kilburn wrote:
Hello,
I am using optimistic locking for a few classes/tables in my
application. However, in certain circumstances when my application
starts up, I want to disable optimistic locking for the lifetime of the
application. I have tried to modify the repository metadata at
runtime, but I still get an OptimisticLockException when trying to
update an object whose locking field is not consistent with the
database.
The locking fields will be cached (for better performance) in
ClassDescriptor first time method cld.getLockingFields() was called. In
#disableOptimisticLocking() you set the locking state after calling this
method (and the locking state change is currently not reflected in
ClassDescriptor, e.g. via a state change listener).
A workaround could be to remove and re-add the locking fields. In this
case the cached locking fields array will be nullified. See below
I've included my disabling method below. Is there anything
I can add to it to completely disable this mechanism?
private void disableOptimisticLocking() {
DescriptorRepository r =
MetadataManager.getInstance().getGlobalRepository();
Map dt = r.getDescriptorTable();
Iterator i = dt.entrySet().iterator();
while (i.hasNext()) {
Map.Entry entry = (Map.Entry) i.next();
ClassDescriptor cd = (ClassDescriptor) entry.getValue();
if (!cd.isInterface() && cd.isLocking()) {
FieldDescriptor[] lockingFields = cd.getLockingFields();
for (int j = 0; j < lockingFields.length; j++) {
FieldDescriptor descriptor = lockingFields[j];
descriptor.setLocking(false);
descriptor.setUpdateLock(false);
// workaround: re-add field-descriptor
cd.removeFieldDescriptor(descriptor);
cd.addFieldDescriptor(descriptor);
}
}
}
}
Never tried this, but if it's done at application start up there
shouldn't be any side-effects.
regards,
Armin
Thanks in advance,
Colin
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]