Unable to save the same ProjectAreaWorkingCopy twice in a row. Stale Exception.
I've been trying to programatically change the process configuration XML. I've done it successfully, however I run into a problem when my application gets multiple requests to save in the same Project Area.
The problem that I have is that the save method returns successfully. Another request starts and then I get a:
com.ibm.team.repository.common.StaleDataException: UpdateItemCurrentRow failure: Params=[_WHQxglx_EeWFo6onmSus9Q,_uakdUNQmEeK9uYPg6dqTSg,_UqClklx_EeWFo6onmSus9Q]
Whats even stranger is that even tho the exception is thrown, the item gets saved correctly to the file. Is there a way to manually synchronize the save? Make sure its really really saved? Can I test if there is a save in progress?
I've already tried all sorts of tricks like checking if isDirty() before I try saving but nothing works. Help?
2 answers
you have to reload the process object and get a new working copy.. once you 'save' thru the working copy, it becomes invalid.
Comments
Hello!
So every time there is a new request, a new connection is made, I fetch the process object, get a new working copy and then save.
can u describe a little more where the request comes in.. is this is a server plugin?
Its a stand alone Java application using the Java API, requests come in from Spring Integration. The request instantiates a new RTC connection, and a new class that handles PAInformation related stuff:
RtcConnection con = new RtcConnection(url, user, pass);
ProjectAreaInformationServiceImpl paInfoService = new ProjectAreaInformationServiceImpl(con);
String response = paInfoService.doSomething(paName, someObject);
con.close();
return response;
The problem occurs when a request to edit a IProcessAreaWorkingCopy happens. The problem is that even if the projectAreaWorkingCopy.save(null); has finished doing its thing, and the connection is closed, it leaves the PA in an awkward state. The next request comes in and BOOM! Stale Data exception.
as these are private classes, its hard to help without much more detail.
I have a plain java utility that updates the process area multiple times in the same run, so it can be done.
Can you share how are you retrieving the IProcessAreaWorkingCopy? Can you tell me if you do something other then projectAreaWorkingCopy.save(null); at the end of your changes?
I don't use the processarea directly..
I use the ProcessItem Client
private static IProcessItemService destprocessItemClient = null;
destprocessItemClient = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
// allocate arraylist to hold list of modified objects.. all have to be saved at one time.
ArrayList<IProcessItem> newitemlist = new ArrayList<IProcessItem>();
// add the project to the list
newitemlist.add((new IProcessItem[] { iprja_dest })[0]);
do work, add modified items (working copies) to the arraylist as you go
// allocate space for the array
IProcessItem[] ilist = new IProcessItem[newitemlist.size()];
// build the arrary
ilist = newitemlist.toArray(ilist);
try
{
// save all the new/modified objects to the repository
destprocessItemClient.save(ilist, null);
}
catch (Exception ex)
{
if (!ex.getMessage().contains("Duplicate"))
System.out.println("exception=" + ex.getMessage());
}
I use the ProcessItem Client
private static IProcessItemService destprocessItemClient = null;
destprocessItemClient = (IProcessItemService) repo.getClientLibrary(IProcessItemService.class);
// allocate arraylist to hold list of modified objects.. all have to be saved at one time.
ArrayList<IProcessItem> newitemlist = new ArrayList<IProcessItem>();
// add the project to the list
newitemlist.add((new IProcessItem[] { iprja_dest })[0]);
do work, add modified items (working copies) to the arraylist as you go
// allocate space for the array
IProcessItem[] ilist = new IProcessItem[newitemlist.size()];
// build the arrary
ilist = newitemlist.toArray(ilist);
try
{
// save all the new/modified objects to the repository
destprocessItemClient.save(ilist, null);
}
catch (Exception ex)
{
if (!ex.getMessage().contains("Duplicate"))
System.out.println("exception=" + ex.getMessage());
}