It's all about the answers!

Ask a question

SCM APIs - use auto lock to imitate reserved check-out


0
1
Weiping Lu (451810) | asked Jul 27 '12, 12:57 p.m.
JAZZ DEVELOPER
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


permanent link
Andrew Niefer (6385) | answered Jul 30 '12, 5:06 p.m.
JAZZ DEVELOPER
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
Weiping Lu commented Aug 16 '12, 11:57 p.m.
JAZZ DEVELOPER

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



permanent link
John Camelon (1.7k14) | answered Jul 30 '12, 5:04 p.m.
JAZZ DEVELOPER
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

permanent link
Weiping Lu (451810) | answered Jul 30 '12, 6:32 p.m.
JAZZ DEVELOPER
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

permanent link
praveen patidar (8612543) | answered Aug 24 '12, 2:24 a.m.
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


Register or to post your answer.