james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r952111 - in /james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail: JCRMailboxMapper.java JCRMessageMapper.java
Date Mon, 07 Jun 2010 06:08:44 GMT
Author: norman
Date: Mon Jun  7 06:08:44 2010
New Revision: 952111

URL: http://svn.apache.org/viewvc?rev=952111&view=rev
Log:
Use the NodeLocker to lock Nodes (IMAP-148). 

Modified:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java?rev=952111&r1=952110&r2=952111&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
(original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
Mon Jun  7 06:08:44 2010
@@ -32,11 +32,11 @@ import javax.jcr.query.QueryResult;
 import org.apache.commons.logging.Log;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.JcrUtils;
-import org.apache.jackrabbit.util.Locked;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.jcr.AbstractJCRMapper;
 import org.apache.james.imap.jcr.MailboxSessionJCRRepository;
 import org.apache.james.imap.jcr.NodeLocker;
+import org.apache.james.imap.jcr.NodeLocker.NodeLockedExecution;
 import org.apache.james.imap.jcr.mail.model.JCRMailbox;
 import org.apache.james.imap.mailbox.MailboxNotFoundException;
 import org.apache.james.imap.mailbox.MailboxSession;
@@ -136,11 +136,15 @@ public class JCRMailboxMapper extends Ab
      */
     public boolean existsMailboxStartingWith(String mailboxName) throws StorageException
{
         try {
-        	QueryManager manager = getSession().getWorkspace().getQueryManager();
-        	String queryString =  "//"+ MAILBOXES_PATH + "//element(*,jamesMailbox:mailbox)[jcr:like(@"
+ JCRMailbox.NAME_PROPERTY + ",'" +mailboxName+"%')]";
-        	QueryResult result = manager.createQuery(queryString, Query.XPATH).execute();
-        	NodeIterator it = result.getNodes();
-        	return it.hasNext();
+            QueryManager manager = getSession().getWorkspace()
+                    .getQueryManager();
+            String queryString = "//" + MAILBOXES_PATH
+                    + "//element(*,jamesMailbox:mailbox)[jcr:like(@"
+                    + JCRMailbox.NAME_PROPERTY + ",'" + mailboxName + "%')]";
+            QueryResult result = manager.createQuery(queryString, Query.XPATH)
+                    .execute();
+            NodeIterator it = result.getNodes();
+            return it.hasNext();
         } catch (RepositoryException e) {
             throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
         }
@@ -235,10 +239,10 @@ public class JCRMailboxMapper extends Ab
                 } else {
                     mailboxNode = rootNode.getNode(MAILBOXES_PATH);
                 }
-                new Locked() {
+                NodeLocker locker = getNodeLocker();
+                locker.execute(new NodeLockedExecution<Void>() {
 
-                    @Override
-                    protected Object run(Node node) throws RepositoryException {
+                    public Void execute(Node node) throws RepositoryException {
                         final String name = jcrMailbox.getName();
                         
                         //split the name so we can construct a nice node tree
@@ -262,8 +266,12 @@ public class JCRMailboxMapper extends Ab
                         getSession().save();
                         return null;
                     }
+
+                    public boolean isDeepLocked() {
+                        return true;
+                    }
                     
-                }.with(mailboxNode, true);
+                }, mailboxNode, Void.class);
                 
            } else {
                jcrMailbox.merge(node);

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java?rev=952111&r1=952110&r2=952111&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
(original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
Mon Jun  7 06:08:44 2010
@@ -34,11 +34,11 @@ import javax.jcr.query.QueryResult;
 import org.apache.commons.logging.Log;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.commons.JcrUtils;
-import org.apache.jackrabbit.util.Locked;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.jcr.AbstractJCRMapper;
 import org.apache.james.imap.jcr.MailboxSessionJCRRepository;
 import org.apache.james.imap.jcr.NodeLocker;
+import org.apache.james.imap.jcr.NodeLocker.NodeLockedExecution;
 import org.apache.james.imap.jcr.mail.model.JCRMessage;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.MessageRange;
@@ -410,17 +410,19 @@ public class JCRMessageMapper extends Ab
                 String dayNodePath = year + NODE_DELIMITER + month + NODE_DELIMITER + day;
                 boolean found = mailboxNode.hasNode(dayNodePath);
                 
+                NodeLocker locker = getNodeLocker();
+                
                 // check if the node for the day already exists. if not we need to create
the structure
                 if (found == false) {
+                    
                     // we lock the whole mailbox with all its childs while
                     // adding the folder structure for the date
                     // TODO: Maybe we should just lock the last child folder
-                    dayNode = (Node) new Locked() {
+                    dayNode = locker.execute(new NodeLocker.NodeLockedExecution<Node>()
{
 
-                        @Override
-                        protected Object run(Node mailboxNode) throws RepositoryException
{
+                        public Node execute(Node node) throws RepositoryException {
 
-                            Node yearNode = JcrUtils.getOrAddFolder(mailboxNode, year);
+                            Node yearNode = JcrUtils.getOrAddFolder(node, year);
                             yearNode.addMixin(JcrConstants.MIX_LOCKABLE);
 
                             Node monthNode = JcrUtils.getOrAddFolder(yearNode, month);
@@ -432,7 +434,12 @@ public class JCRMessageMapper extends Ab
                             getSession().save();
                             return dayNode;
                         }
-                    }.with(mailboxNode, true);
+
+                        public boolean isDeepLocked() {
+                            return true;
+                        }
+                    }, mailboxNode, Node.class);
+                   
                 } else {
                     
                     dayNode = mailboxNode.getNode(dayNodePath);
@@ -440,11 +447,10 @@ public class JCRMessageMapper extends Ab
                 
                 
                 // lock the day node and add the message
-                new Locked() {
+                locker.execute(new NodeLockedExecution<Void>() {
 
-                    @Override
-                    protected Object run(Node dayNode) throws RepositoryException {
-                        Node messageNode = dayNode.addNode(String.valueOf(membership.getUid()),"jamesMailbox:message");
+                    public Void execute(Node node) throws RepositoryException {
+                        Node messageNode = node.addNode(String.valueOf(membership.getUid()),"jamesMailbox:message");
                         try {
                             membership.merge(messageNode);
                         } catch (IOException e) {
@@ -455,10 +461,12 @@ public class JCRMessageMapper extends Ab
 
                         return null;
                     }
-                    
-                }.with(dayNode,false);
+
+                    public boolean isDeepLocked() {
+                        return true;
+                    }
+                }, dayNode, Void.class);
                 
-              
             } else {
                 membership.merge(messageNode);
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message