james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r952214 - in /james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr: AbstractJCRMapper.java GlobalMailboxSessionJCRRepository.java MailboxSessionJCRRepository.java
Date Mon, 07 Jun 2010 13:22:20 GMT
Author: norman
Date: Mon Jun  7 13:22:19 2010
New Revision: 952214

URL: http://svn.apache.org/viewvc?rev=952214&view=rev
Log:
Move the JCR handling to MailboxSessionJCRRepository, so we are sure only one Session is bound
per Request

Modified:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/AbstractJCRMapper.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/GlobalMailboxSessionJCRRepository.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/AbstractJCRMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/AbstractJCRMapper.java?rev=952214&r1=952213&r2=952214&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/AbstractJCRMapper.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/AbstractJCRMapper.java Mon
Jun  7 13:22:19 2010
@@ -36,7 +36,6 @@ import org.apache.james.imap.store.trans
 public abstract class AbstractJCRMapper extends AbstractTransactionalMapper implements JCRImapConstants
{
     public final static String MAILBOXES_PATH =  "mailboxes";
     public final static String SUBSCRIPTIONS_PATH =  "subscriptions";
-    private final static String JCR_SESSION = "JCR_SESSION";
 
     private final Log logger;
     private final MailboxSessionJCRRepository repository;
@@ -69,12 +68,7 @@ public abstract class AbstractJCRMapper 
      * @return session
      */
     protected Session getSession() throws RepositoryException{
-        Session session = (Session) mSession.getAttributes().get(JCR_SESSION);
-    	if (session == null) {
-    		session = repository.login(mSession);
-    		mSession.getAttributes().put(JCR_SESSION, session);
-    	}
-        return session;
+        return repository.login(mSession);
     }
 
     /**
@@ -118,13 +112,7 @@ public abstract class AbstractJCRMapper 
      * Logout from open JCR Session
      */
     public void endRequest() {
-        Session session = (Session) mSession.getAttributes().remove(JCR_SESSION);
-
-        if (session != null) {
-            if (session.isLive())
-                session.logout();
-            session = null;
-        }
+       repository.logout(mSession);
     }
         
     

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/GlobalMailboxSessionJCRRepository.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/GlobalMailboxSessionJCRRepository.java?rev=952214&r1=952213&r2=952214&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/GlobalMailboxSessionJCRRepository.java
(original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/GlobalMailboxSessionJCRRepository.java
Mon Jun  7 13:22:19 2010
@@ -21,7 +21,6 @@ package org.apache.james.imap.jcr;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.SimpleCredentials;
 
 import org.apache.james.imap.mailbox.MailboxSession;
 
@@ -51,8 +50,7 @@ public class GlobalMailboxSessionJCRRepo
      */
     @Override
     public Session login(MailboxSession session) throws RepositoryException {
-        Session jcrSession = getRepository().login(new SimpleCredentials(username, pass),
getWorkspace());
-        return jcrSession;
+        return login(session, username, pass);
     }
 
 }

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java?rev=952214&r1=952213&r2=952214&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java
(original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java
Mon Jun  7 13:22:19 2010
@@ -32,7 +32,7 @@ import org.apache.james.imap.mailbox.Mai
  *
  */
 public class MailboxSessionJCRRepository {
-    
+    private final static String JCR_SESSION = "JCR_SESSION";
     private Repository repository;
     private String workspace;
     
@@ -57,10 +57,40 @@ public class MailboxSessionJCRRepository
         if (password != null) {
             pass = password.toCharArray();
         }
-        return repository.login(new SimpleCredentials(username, pass),
-                workspace);
+        return login(session, username, pass);
     }
 
+
+
+    protected Session login(MailboxSession mSession, String username,
+            char[] pass) throws RepositoryException {
+        Session session = (Session) mSession.getAttributes().get(JCR_SESSION);
+        if (session == null) {
+            session = repository.login(new SimpleCredentials(username, pass),
+                    workspace);
+            mSession.getAttributes().put(JCR_SESSION, session);
+        }
+        return session;
+    }
+    
+    /**
+     * Logout the JCR {@link Session} if one exists
+     * 
+     * @param mSession
+     */
+    public void logout(MailboxSession mSession) {
+        if (mSession == null) return;
+        
+        Session session = (Session) mSession.getAttributes().remove(JCR_SESSION);
+
+        if (session != null) {
+            if (session.isLive())
+                session.logout();
+            session = null;
+        }
+    }
+    
+    
     /**
      * Return the {@link Repository} 
      * 



---------------------------------------------------------------------
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