On 8/11/05, Walter Raboch <[EMAIL PROTECTED]> wrote: > Hi Stefan, > > >>Thanks for the discussion. Now I unterstand jackrabbits way of doing. > >>But in my opinion adding child nodes should not alter the parent node > >>itself. Just changing some properties is a state change. > > > > i don't agree. see 7.1.4 Adding Nodes in the jsr 170 spec: > > <quote> > > In order to save a newly added node, save must be called either on the > > Session, or on the new node's parent or higher-order ancestor > > (grandparent, etc.). > > </quote> > >>Furthermore there should be an error just in the case, that both updates > >>overwrite the changes of the other -> to prevent lost update problems. > >>In my example code it´s not the case, so I would prefer no error at all. > >>What do you think? > > > > AFAIK lost updates did never happen. your testcase failed in the right > > situations > > but threw the wrong exceptions. i committed a fix for that problem > > yesterday. > > IMO it now works as it should according to the jsr 170 spec. > > You are right according to the spec. Let me try to explain my thoughts: > > s0: read root node > s1: read root node > s0: add or remove child "c1" > s1: add or remove child "c2" > s0: rn.save() > s1: rn.save() > > All this without error. Because the changes of both sessions dont > interfere.
i can see what you mean. unfortunately there's no trivial solution. child node additions & removals per se are not guaranteed to be non-interfering. there's even a great chance that they actually *are* interfering. just think of same-name siblings. the same applies for child re-ordering. an application should lock the parent node to stay clear of such concurrency issues (pessimistic locking approach). > If both sessions change the same child or attribute, there should be > thrown an InvalidItemStateException. > > s0: read root node > s1: read root node > s0: set property p="hello" > s1: set property p="world" > s0: save > s1: save -> InvalidItemStateException > > What do you think? > > To our first problem with my testcase. I rerun the code but it still > fails with ItemNotFoundExceptions. But I dont know why. the first InvalidItemStateException is correct. i'll investigate the ItemNotFoundException. i guess there's a 'synchronized' missing somewhere... cheers stefan > > cheers, Walter > -- > Output of rerun (revision 231423): > ================================== > s0: started. > s1: started. > s2: started. > s3: started. > s4: started. > s3: Exception: removing testnode > javax.jcr.InvalidItemStateException: /: the item cannot be saved because > it has been modified externally. > at > org.apache.jackrabbit.core.ItemImpl.getTransientStates(ItemImpl.java:347) > at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1205) > at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:747) > at TestSession.run(TestSession.java:62) > at java.lang.Thread.run(Unknown Source) > s3: ended. > javax.jcr.ItemNotFoundException: 545ab69b-0297-427c-a05a-217e3c8f7d88 > at > org.apache.jackrabbit.core.ItemManager.createItemInstance(ItemManager.java:498) > at > org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:349) > at > org.apache.jackrabbit.core.NodeImpl.internalAddChildNode(NodeImpl.java:781) > at > org.apache.jackrabbit.core.NodeImpl.internalAddNode(NodeImpl.java:725) > at > org.apache.jackrabbit.core.NodeImpl.internalAddNode(NodeImpl.java:672) > at org.apache.jackrabbit.core.NodeImpl.addNode(NodeImpl.java:1721) > at TestSession.run(TestSession.java:70) > at java.lang.Thread.run(Unknown Source) > s0: Exception: adding testnode > s0: ended. > s4: Exception: removing testnode > javax.jcr.InvalidItemStateException: /: the item cannot be saved because > it has been modified externally. > at > org.apache.jackrabbit.core.ItemImpl.getTransientStates(ItemImpl.java:347) > at org.apache.jackrabbit.core.ItemImpl.save(ItemImpl.java:1205) > at org.apache.jackrabbit.core.SessionImpl.save(SessionImpl.java:747) > at TestSession.run(TestSession.java:62) > at java.lang.Thread.run(Unknown Source) > s4: ended. > s1: Exception: adding testnode > javax.jcr.ItemNotFoundException: e170d490-b7c1-4dfa-be14-f8932162b9f7 > at > org.apache.jackrabbit.core.ItemManager.createItemInstance(ItemManager.java:498) > at > org.apache.jackrabbit.core.ItemManager.getItem(ItemManager.java:349) > at > org.apache.jackrabbit.core.NodeImpl.internalAddChildNode(NodeImpl.java:781) > at > org.apache.jackrabbit.core.NodeImpl.internalAddNode(NodeImpl.java:725) > at > org.apache.jackrabbit.core.NodeImpl.internalAddNode(NodeImpl.java:672) > at org.apache.jackrabbit.core.NodeImpl.addNode(NodeImpl.java:1721) > at TestSession.run(TestSession.java:70) > at java.lang.Thread.run(Unknown Source) > s1: ended. > ..........s2: ended. > > >
