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.
|
2 answers
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.
|
Ralph Schoon (63.5k●3●36●46)
| answered Dec 14 '12, 3:36 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
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. Comments
Martin Dam Pedersen
commented Dec 14 '12, 4:56 a.m.
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,
|
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.