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
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:
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:
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);