Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

1

0 votes


Accepted answer

Permanent link
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

1 vote

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


3 other answers

Permanent link
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

0 votes


Permanent link
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

0 votes


Permanent link
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.

 

0 votes

Your answer

Register or log in to post 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 12,019
× 1,202
× 233
× 66

Question asked: Jul 27 '12, 12:57 p.m.

Question was seen: 8,100 times

Last updated: Sep 07 '12, 4:30 a.m.

Confirmation Cancel Confirm