cancel
Showing results for 
Search instead for 
Did you mean: 

Programmatic ItemRevision and Database Locks

I am trying to simply revise an existing ItemRevision through SOA calls using the DataManagementService.revise2() method. While this appears to be working, I notice that doing anything else programmatically with the revised item revision results in an error stating

 

com.transcendata.cadpdm.soa.SOAException: [Locked by administrator on node tc-server in a session started at 09-Jan-2015 14:23
, The instance is in use., 
, Unable to load/refresh object.]

 

Thanks to a query fromt he site http://teamcenterone.wordpress.com/2014/02/05/database-locks-in-tc-unified/ I was able to see that my programmatic call was indeed leaving a lock on the item revision. I am revising the existing item like so:

 

public void reviseItem(ItemRevision itemRev, String newRevId) 
		throws ServiceException
{
	DataManagementService dmService = 
			DataManagementService.getService(
			TeamCenterSessionManager.getConnection());
	ReviseInfo[] reviseInfo = new ReviseInfo[1];
	   
	String irev_name = getStringProperty(itemRev, "object_name");
	
	reviseInfo[0] = new ReviseInfo();
	reviseInfo[0].baseItemRevision = itemRev;
	reviseInfo[0].clientId = itemRev.getUid();
	reviseInfo[0].newRevId = newRevId;
	reviseInfo[0].name = irev_name;
	reviseInfo[0].description = "test desc";

	ReviseResponse2 revised = dmService.revise2(reviseInfo);
	
	if (revised.serviceData.sizeOfPartialErrors() > 0)
	{
	    throw new ServiceException("Revise error.");
	}
}

 

When I run this on an existing ItemRevision at verion A, it does create a new ItemRevision B, however running a query from the site mentioned above does indeed show

 

locked_item_rev.png

 

Note that if I manually revise ItemRevision A through the UI this does not show up. I also notice some property differences between the programmatic revision and the manual revision. Manually, ItemRevision B shows "fnd0IsCheckoutable" and "isModifiable" as 'true'. However the programmatic revision shows both of these as false.

 

I figure I could try forcefully changing those properties after programmatically revising it, but that doesn't seem like the right approach.

 

What am I missing??

 

Any help would be much appreciated. Thanks!

1 REPLY

Re: Programmatic ItemRevision and Database Locks

So I was able to find a workaround for this, although it's definitely a little funky. In the process of trying different things manually, I noticed that checking out the ItemRevision with the database lock, then cancelling the checkout, caused the db lock to go away. So now, my revise method is as follows:

 

public void reviseItem(ItemRevision itemRev, String newRevId) throws ServiceException
{
	DataManagementService dmService = DataManagementService.getService(
			TeamCenterSessionManager.getConnection());
	ReviseInfo[] reviseInfo = new ReviseInfo[1];
	   
	String irev_name = getStringProperty(itemRev, "object_name");
    
    reviseInfo[0] = new ReviseInfo();
    reviseInfo[0].baseItemRevision = itemRev;
    reviseInfo[0].clientId = itemRev.getUid();
    reviseInfo[0].newRevId = newRevId;
    reviseInfo[0].name = irev_name;
    reviseInfo[0].description = "test desc";

    ReviseResponse2 revised = dmService.revise2(reviseInfo);
    
    ReviseOutput revOp = (ReviseOutput)revised.reviseOutputMap.get(itemRev.getUid());
    ItemRevision newRev = revOp.newItemRev;
    ModelObject[] fresh_rev = new ModelObject[1];
    fresh_rev[0] = newRev;

    _log.logDebug("Revised");
    if (revised.serviceData.sizeOfPartialErrors() > 0)
    {
        throw new ServiceException("DataManagementService.revise returned a partial error.");
    }
    
    // now this part makes no sense, but lets checkout then cancel the checkout
    // to get rid of the database lock
    ReservationService resService = ReservationService.getService(
    		TeamCenterSessionManager.getConnection());
    ServiceData sd = resService.checkout(fresh_rev, "", "");
    _log.logDebug("Temp check-out");
    if (sd.sizeOfPartialErrors() > 0)
    {
        throw new ServiceException("Checkout returned a partial error.");
    }
    
    sd = resService.cancelCheckout(fresh_rev);
    
    _log.logDebug("Temp cancel-check-out");
    if (sd.sizeOfPartialErrors() > 0)
    {
        throw new ServiceException("Cancel Checkout returned a partial error.");
    }
}

 I don't love this solution - primarily because I don't fully understand why it works - but it does get around the issues I was having.

 

If anyone else knows what the problem was in the first place (or why this seems to fix it), feel free to post.

 

Thanks!