SCM APIs - use auto lock to imitate reserved check-out
Specifically, what are the APIs for the following operations:
(1) Given one file or multiple files in my workspace, how to know if each file is locked or unlocked, and if it is by whom?
(2) What is the recommended (reliable) approach for locking and unlocking a file or multiple files?
Any help will be greatly appreciated.
Thanks,
Weiping
Accepted answer
To find locks, create a ILockSearchCriteria for the file/folder IVersionableHandles that you are interested in:
ILockSearchCriteria criteria = ILockSearchCriteria.FACTORY.newInstance(); criteria.getVersionables().add(interestingFileHandles); criteria.getComponents().add(componentHandle); criteria.getStreams().add(streamHandle); ILockSearchResult result = workspaceManager.findLocks(criteria, IWorkspaceManager.MAX_QUERY_SIZE, progressMonitor);
If you go through the ILockSearchResult, you'll find IVersionableLock#getContributor() which gives you the contributor who locked that IVersionableLock#getVersionable() item.
For locking and unlocking, it is something like:
IVersionableLockOperationFactory factory = workspaceManager.lockOperationFactory(); collection.add(factory.acquire(file, stream, component); collection.release(file, stream, component); workspaceManager.applyLockOperations(collection, progressMonitor);
Comments
Hi Andrew,
This API works fine if the number of versionable handles in the criteria is not too large, say, a few hundreds: ILockSearchResult result = workspaceManager.findLocks(criteria, IWorkspaceManager.MAX_QUERY_SIZE, progressMonitor);
But, if the number of versionable handles is large, e.g 19000, then it takes forever until time out. In my case here, the numbers of stream and component are both one. Actually, I would simple need to get all the locks under the stream/component
Is there any faster way to find the locks under this condition? I noticed UserLockCache class contains some cache info I need, but this class is not accessible as an public API class.
Thanks,
Weiping
HI
As far as I can see, the accepted answer is inteded for client-side locking only. I need to lock items associated to a changeset on a Stream on delivery. All in a Contributor e.g. server-side. Does anybody have a snippet that shows this?
From the Contributor-interface I have access to Changeset, Component and the Stream I deliver to.
Regards
Erling