AnsweredAssumed Answered

Counter action giving duplicate numbers

Question asked by ovirtanen on Apr 20, 2010
Latest reply on Apr 22, 2010 by derek
I have a piece of code that uses a central space as the location of a counter aspect, then injects the next value to a given object as a sequence number, like so:

synchronized public void injectIdentifier(NodeRef nodeRef) {
   NodeRef rootSpace = locateRootSpace();
   Action countAction = serviceRegistry.getActionService().createAction("counter");
   serviceRegistry.getActionService().executeAction(countAction, rootSpace);
   Integer count = (Integer) nodeService.getProperty(arubaHome, ContentModel.PROP_COUNTER);
   count += 9999;
   nodeService.setProperty(nodeRef, MyModel.PROP_IDENTIFIER, count.toString());

Now, this seemed to be working perfectly, until it started returning duplicate numbers or possibly even jumped backwards a couple of times – not exactly sure which. The locateRootSpace method looks for the company home using lucene, then resolves by name a space directly under it. This code has since been replaced with a direct MySQL sequence query, which solved the manifested problem.

But I'm left wondering what could have caused this. Any ideas?