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

Atomic link manipulation on workItem

I want to delete and create links on a workItem as an atomic operation. So how can I ensure that it's all or nothing ?
I don't want to be in a position where I have deleted some links and then for some reason I couldn't create the new ones. Or the other way around.

I really don't care if the operation takes place on the server or in a client as long as it is atomic.

Any help is appreciated. 

0 votes



2 answers

Permanent link
 Hi 

I actually found a solution to this problem.  

First I created a service on the server which extends AbstractService. Instructions and example can be found here : Hello Jazz -- How to write a simple Jazz component

Second i used the TransactionService inside my service to run my critical code. By getting a instance of the TransactionService it is possible to call the runInTransaction method. It looks like this:
public String myAtomicOperation() throws TeamRepositoryException {
	ITransactionService transactionService = getService(ITransactionService.class);

	String runInTransactionResult = transactionService.runInTransaction(false, new ITransactionRunnable<String>() {
		
		@Override
		public String run() throws TeamRepositoryException {
			
		    // CRITICAL CODE GOES HERE
		    // Example: createLinks, deleteLinks.	
		    
                    return "The result";
		}
	});

	return runInTransactionResult;
}
So when I want to atomic modify links on a WorkItem I call myAtomicOperation on my service, and it encapsulates all the removal and creation of links inside the transaction.
If anything goes wrong half the way through my operations and a TeamRepositoryException is thrown, then everything is rolled back automatically.  

I hope this could be useful for others to.

If anyone knows of any drawbacks to this implementation, please let me know. 
 

1 vote

Comments

Thanks for sharing Martin!


Permanent link
The API is as the API is. You could check that the new links could be created before deleting the old ones. However if for some reason e.g. you don't have tested if you have permission to modify one of the elements, or the server goes down, or some other weird scenario throws an exception, there is noting you can do.

See https://rsjazz.wordpress.com/ for examples about the link API.

0 votes

Comments

 Hi Ralph


I have made an example where I create some links between a workItem and a changeSet within a deliver operation contributor. When working in that scope I can create links and if I add an exceptionInfo to the collector the links are gone when returning from the deliver operation. 

This tells me that the deliver operation runs within an atomic transaction  and therefore everything gets rolled back if something went wrong. Is this correct ?

Now my question of course is. Can we do the same thing within a service of our own ?   

 

Hi Martin,

that is above my level of knowledge. My experience is that in an advisor, if you prevent a save, the element is rolled back to the prior state on cancel.

I had a discussion with some developers two day ago where we found that you should not do manipulations in an advisor. See this post. I was not really aware of that also - I did not read the API documentation good enough I guess.

For work items, I think if you do your modifications e.g. in a workitem operation and exit with an exception or you and don't do the save of the workingcopy, you should end up with the previous state of the work item. However, I am not really sure if this is guarded by a transaction and is really atomic. I will pass this on to someone who could probably tell.

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
× 10,934
× 411
× 233

Question asked: Dec 14 '12, 3:15 a.m.

Question was seen: 6,460 times

Last updated: Mar 12 '13, 6:06 a.m.

Confirmation Cancel Confirm