03-23-2012 09:00 AM
import org.alfresco.service.cmr.lock.LockService;
import org.alfresco.service.cmr.lock.LockType;
//…
private LockService lockService;
//…
if (counterRef != null)
{
// lock counter
boolean locked = false;
while (!locked)
{
try
{
lockService.lock(counterRef, LockType.WRITE_LOCK);
locked = true;
}
catch (Exception e)
{
try
{
wait(500);
}
catch (Exception ex)
{
}
}
}
// get the value
Integer count = (Integer)nodeService.getProperty(counterRef, CustomContentModel.PROP_OUTPUTNUMBER);
// add one
count++;
// save the value
nodeService.setProperty(counterRef, CustomContentModel.PROP_OUTPUTNUMBER, count);
// unlock counter
lockService.unlock(counterRef);
return count;
}
//…
… so far users have created about 3,000 documents… FIVE of them with duplicated number… … I can't understand why!?!03-23-2012 09:16 AM
03-23-2012 02:56 PM
03-29-2012 11:25 AM
if (counterRef != null)
{
// lock counter
lockService.lock(counterRef, LockType.WRITE_LOCK);
// get the value
Integer count = (Integer)nodeService.getProperty(counterRef, CustomContentModel.PROP_INPUTNUMBER);
count++;
// saves the value
nodeService.setProperty(counterRef, CustomContentModel.PROP_INPUTNUMBER, count);
// unlock counter
lockService.unlock(counterRef);
return count;
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.