SCM APIs - use auto lock to imitate reserved check-out
I am trying to implement an auto lock or unlock mechanism to imitate a reserved check-out when certain UI action is performed by the user.
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
The methods you will be interested in are IWorkspaceManager#findLocks and IWorkspaceManager.applyLockOperations. You can get the workspace manager from SCMPlatfom.getWorkspaceManager(ITeamRepository); You will need the stream and component that the files are in.
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); Weiping Lu selected this answer as the correct answer
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
erling jorgensen
commented Sep 07 '12, 4:30 a.m.
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 |
3 other answers
Using client API:
IWorkspaceManager#applyLockOperations() - to lock/unlock
IWorkspaceManager#getLocks() - to see the locks the user currently holds
IWorkspaceManager#findLocks() to query locks by user or component or stream
Hope this helps,
JohnC
Jazz SCM Lead
|
Hi John/Andrew,
Thank you very much ! I have also learn some more from debugging into RTC's LockAction, UnlockAction and some of APIs used by change view label provider decoration class. Weiping |
Hello
the API seems helpful but weather the lock API can be called via Operation advisor? if yes than from which event in the Operation Behavior this can be configured? Like for Save work item the "Save Work Item(Server)" event is there present. |
Your answer
Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.