Hi,

I wonder if you can help me.

I would like to write some code that adds a folder to a parent, but I want
to do this in such a way that it will work during concurrent modifications.

The code I currently have is as follows ...

  // Start the session
  Session session = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()));
  try
  {
      // Get the root node for now
      Node rootNode = session.getRootNode();

     // Wait untill a lock is available on the parent folder
     boolean hasLock = false;
     while (hasLock == false)
     {
        if (folder.isLocked() == false)
        {
           try
           {
              // Take the lock out on the parent
              folder.lock(false, true);
              hasLock = true;
           }
           catch (Exception exception)
           {
              // Ignore and retry
           }
        }

         Thread.yield();
      }

      // Add the new folder
      rootNode.addNode ("testFolder_" + System.currentTimeMillis(),
"nt:folder");

      // Save the session
      session.save();
  }
  finally
  {
      // Log out, lock is revoked
      session.logout();
  }

I have a couple of questions:

1)  Is this pattern ok or is there a better way to do things?
2)  I have assumed that the parent node (the root node in this example) is
lockable.  If it isn't what is the best way to apply the lockable aspect in
a concurrent safe way?

I'm new to JackRabbit and trying to evaluate its capabilities.  Any help or
feedback will be gratefully received.

Thanks in advance,
Bob

Reply via email to