4 Replies Latest reply on Feb 9, 2007 5:23 AM by manik

    How to add without overwriting

    vincent.marquez

      I'm interested in learning the correct way to add data to a node only if the node is empty. My concern is that between checking if an FQN exists, and adding a new object under that specific FQN, data could have been added to the cache.

      I understand there is explicit locking on Node objects, but if the FQN does not exist in the cache, it will return null. Is there a basic pattern or strategy I should be taking to avoid this potential problem? Thanks in advance for any suggestions.

        • 1. Re: How to add without overwriting
          manik

          Transactions.

          1) Start a tx
          2) Check if node is empty
          3) If so, write to node
          4) End tx

          • 2. Re: How to add without overwriting
            vincent.marquez

            Would it be appropriate to use the DummyTransactionManager here? I thought I had read somewhere that it wasn't recommended for production use... Thank you for your reply.

            • 3. Re: How to add without overwriting
              vincent.marquez

              Also, I wrote a simple test case, and got some unexpected behaviour.

              I started a tx in the first vm, then checked if a node 'existed'. Then, from another VM, I added data to that node. Back in the original VM, I added data to a node and called commit.

              I was expecting some sort of rollback exception, but instead it overwrote the value that the 2nd VM had placed in the node.

              To me, this appreas incorrect. Any ideas on something i'm doing wrong? Thanks again for the help.

              • 4. Re: How to add without overwriting
                manik

                1) Wouldn't recommend the dummy TM in production.

                2) Did the 2nd node use a tx as well? If it didn't then there is no guarantee that it's data will be safe. If both nodes used txs, then the 2nd node would not have been able to commit (it would have rolled back)