james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r951398 [1/4] - in /james/imap/trunk: deployment/src/test/java/org/apache/james/imap/functional/inmemory/ deployment/src/test/java/org/apache/james/imap/functional/jcr/ deployment/src/test/java/org/apache/james/imap/functional/jpa/ jcr/src/...
Date Fri, 04 Jun 2010 13:07:08 GMT
Author: norman
Date: Fri Jun  4 13:07:05 2010
New Revision: 951398

URL: http://svn.apache.org/viewvc?rev=951398&view=rev
Log:
Refactor store to re-use Mappers for the whole session. Most of the work was contributed by Tim-Christion Mundt. See IMAP-148

Added:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/InMemoryMailbox.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleHeader.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/user/
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/user/InMemorySubscriptionMapper.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/user/model/
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/user/model/InMemorySubscription.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/MailboxSessionMapperFactory.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/AbstractFullContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/AbstractRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/ByteContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/CRLFOutputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/ConfigurableMimeTokenStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/CountingInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/DelegatingRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/FileRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/FullByteContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/InMemoryRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/InputStreamContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/InputStreamFullContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/LazySkippingInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/PartContentBuilder.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/RewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/streaming/StreamUtils.java
Removed:
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/MailboxSessionEntityManagerFactory.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailbox.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleHeader.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/AbstractFullContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/AbstractRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ByteContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/CRLFOutputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ConfigurableMimeTokenStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/CountingInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FullByteContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InMemoryRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InputStreamFullContent.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/LazySkippingInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/PartContentBuilder.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StreamUtils.java
Modified:
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java
    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/JCRMailboxManager.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/MailboxSessionJCRRepository.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java
    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
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPATransactionalMapper.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAUidConsumer.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMessageManager.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/user/JPASubscriptionMapper.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMessageManager.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemorySubscriptionManager.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/MimeDescriptorImpl.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/PasswordAwareMailboxSession.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/PasswordAwareUser.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MailboxMapper.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/model/AbstractDocument.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/model/Document.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/transaction/AbstractTransactionalMapper.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/transaction/TransactionalMapper.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/FileRewindableInputStreamTest.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/InMemoryRewindableInputStreamTest.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/PartContentBuilderComplexMultipartTest.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/PartContentBuilderMultipartAlternativeTest.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/RewindableInputStreamTest.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java
    james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/MessageRowUtils.java
    james/imap/trunk/torque/src/main/java/org/apache/james/mailboxmanager/torque/TorqueMailbox.java
    james/imap/trunk/torque/src/test/java/org/apache/james/mailboxmanager/torque/PartContentBuilderComplexMultipartTest.java
    james/imap/trunk/torque/src/test/java/org/apache/james/mailboxmanager/torque/PartContentBuilderMultipartAlternativeTest.java

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java (original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/inmemory/InMemoryHostSystem.java Fri Jun  4 13:07:05 2010
@@ -23,17 +23,17 @@ import org.apache.james.imap.encode.main
 import org.apache.james.imap.functional.ImapHostSystem;
 import org.apache.james.imap.functional.InMemoryUserManager;
 import org.apache.james.imap.inmemory.InMemoryMailboxManager;
+import org.apache.james.imap.inmemory.InMemoryMailboxSessionMapperFactory;
 import org.apache.james.imap.inmemory.InMemorySubscriptionManager;
 import org.apache.james.imap.main.DefaultImapDecoderFactory;
 import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
-import org.apache.james.imap.store.StoreMailboxManager;
 import org.apache.james.test.functional.HostSystem;
 
 public class InMemoryHostSystem extends ImapHostSystem {
 
     private final InMemoryMailboxManager mailboxManager;
     private final InMemoryUserManager userManager; 
-    
+    private final InMemoryMailboxSessionMapperFactory factory;
     static HostSystem build() throws Exception {        
         InMemoryHostSystem host =  new InMemoryHostSystem();
         return host;
@@ -41,7 +41,8 @@ public class InMemoryHostSystem extends 
     
     private InMemoryHostSystem() {
         userManager = new InMemoryUserManager();
-        mailboxManager = new InMemoryMailboxManager(userManager, new InMemorySubscriptionManager());
+        factory = new InMemoryMailboxSessionMapperFactory();
+        mailboxManager = new InMemoryMailboxManager(factory, userManager, new InMemorySubscriptionManager(factory));
         final DefaultImapProcessorFactory defaultImapProcessorFactory = new DefaultImapProcessorFactory();
         defaultImapProcessorFactory.configure(mailboxManager);
         configure(new DefaultImapDecoderFactory().buildImapDecoder(),

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java (original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRHostSystem.java Fri Jun  4 13:07:05 2010
@@ -29,11 +29,14 @@ import org.apache.james.imap.functional.
 import org.apache.james.imap.functional.InMemoryUserManager;
 import org.apache.james.imap.jcr.GlobalMailboxSessionJCRRepository;
 import org.apache.james.imap.jcr.JCRMailboxManager;
+import org.apache.james.imap.jcr.JCRMailboxSessionMapperFactory;
 import org.apache.james.imap.jcr.JCRSubscriptionManager;
 import org.apache.james.imap.jcr.JCRUtils;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.main.DefaultImapDecoderFactory;
 import org.apache.james.imap.processor.main.DefaultImapProcessorFactory;
+import org.apache.james.imap.store.Authenticator;
+import org.apache.james.imap.store.Subscriber;
 import org.apache.james.test.functional.HostSystem;
 import org.xml.sax.InputSource;
 
@@ -67,10 +70,10 @@ public class JCRHostSystem extends ImapH
             JCRUtils.registerCnd(repository, workspace, user, pass);
             
             userManager = new InMemoryUserManager();
+            JCRMailboxSessionMapperFactory mf = new JCRMailboxSessionMapperFactory(sessionRepos);
 
             //TODO: Fix the scaling stuff so the tests will pass with max scaling too
-            mailboxManager = new JCRMailboxManager(userManager, new JCRSubscriptionManager(sessionRepos), sessionRepos);
-
+            mailboxManager = new JCRMailboxManager(mf, userManager, new JCRSubscriptionManager(mf));
             final DefaultImapProcessorFactory defaultImapProcessorFactory = new DefaultImapProcessorFactory();
             resetUserMetaData();
             MailboxSession session = mailboxManager.createSystemSession("test", new SimpleLog("TestLog"));

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java (original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jcr/JCRStressTest.java Fri Jun  4 13:07:05 2010
@@ -28,6 +28,7 @@ import org.apache.jackrabbit.core.config
 import org.apache.james.imap.functional.AbstractStressTest;
 import org.apache.james.imap.jcr.GlobalMailboxSessionJCRRepository;
 import org.apache.james.imap.jcr.JCRMailboxManager;
+import org.apache.james.imap.jcr.JCRMailboxSessionMapperFactory;
 import org.apache.james.imap.jcr.JCRSubscriptionManager;
 import org.apache.james.imap.jcr.JCRUtils;
 import org.apache.james.imap.jcr.MailboxSessionJCRRepository;
@@ -38,18 +39,13 @@ import org.junit.Before;
 import org.xml.sax.InputSource;
 
 public class JCRStressTest extends AbstractStressTest{
-
     
     private JCRMailboxManager mailboxManager;
 
-
-
     private static final String JACKRABBIT_HOME = "deployment/target/jackrabbit";
     public static final String META_DATA_DIRECTORY = "target/user-meta-data";
     private RepositoryImpl repository;
-
-
-    
+   
     
     @Before
     public void setUp() throws RepositoryException {
@@ -66,9 +62,8 @@ public class JCRStressTest extends Abstr
         JCRUtils.registerCnd(repository, workspace, user, pass);
 
         MailboxSessionJCRRepository sessionRepos = new GlobalMailboxSessionJCRRepository(repository, workspace, user, pass);
-        // TODO: Fix the scaling stuff so the tests will pass with max scaling
-        // too
-        mailboxManager = new JCRMailboxManager(null, new JCRSubscriptionManager(sessionRepos), sessionRepos);
+        JCRMailboxSessionMapperFactory mf = new JCRMailboxSessionMapperFactory(sessionRepos);
+        mailboxManager = new JCRMailboxManager(mf, null, new JCRSubscriptionManager(mf));
 
     }
     
@@ -77,14 +72,8 @@ public class JCRStressTest extends Abstr
     
     public void tearDown() {
         MailboxSession session = mailboxManager.createSystemSession("test", new SimpleLog("Test"));
-        /*
-        try {
-            //mailboxManager.deleteEverything(session);
-        } catch (MailboxException e) {
-            e.printStackTrace();
-        }
-        */
         session.close();
+        repository.shutdown();
         new File(JACKRABBIT_HOME).delete();
 
     }

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java (original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java Fri Jun  4 13:07:05 2010
@@ -29,8 +29,8 @@ import org.apache.commons.logging.impl.S
 import org.apache.james.imap.encode.main.DefaultImapEncoderFactory;
 import org.apache.james.imap.functional.ImapHostSystem;
 import org.apache.james.imap.functional.InMemoryUserManager;
+import org.apache.james.imap.jpa.JPAMailboxSessionMapperFactory;
 import org.apache.james.imap.jpa.JPASubscriptionManager;
-import org.apache.james.imap.jpa.MailboxSessionEntityManagerFactory;
 import org.apache.james.imap.jpa.openjpa.OpenJPAMailboxManager;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.main.DefaultImapDecoderFactory;
@@ -68,8 +68,8 @@ public class JPAHostSystem extends ImapH
                 "org.apache.james.imap.jpa.user.model.JPASubscription)");
         userManager = new InMemoryUserManager();
         entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties);
-        MailboxSessionEntityManagerFactory factory = new MailboxSessionEntityManagerFactory(entityManagerFactory);
-        mailboxManager = new OpenJPAMailboxManager(userManager, new JPASubscriptionManager(factory), factory);
+        JPAMailboxSessionMapperFactory mf = new JPAMailboxSessionMapperFactory(entityManagerFactory);
+        mailboxManager = new OpenJPAMailboxManager(mf, userManager, new JPASubscriptionManager(mf));
         
         final DefaultImapProcessorFactory defaultImapProcessorFactory = new DefaultImapProcessorFactory();
         resetUserMetaData();

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java (original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAStressTest.java Fri Jun  4 13:07:05 2010
@@ -25,8 +25,8 @@ import javax.persistence.EntityManagerFa
 
 import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.james.imap.functional.AbstractStressTest;
+import org.apache.james.imap.jpa.JPAMailboxSessionMapperFactory;
 import org.apache.james.imap.jpa.JPASubscriptionManager;
-import org.apache.james.imap.jpa.MailboxSessionEntityManagerFactory;
 import org.apache.james.imap.jpa.openjpa.OpenJPAMailboxManager;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
@@ -64,8 +64,8 @@ public class JPAStressTest extends Abstr
         properties.put("openjpa.LockTimeout", locktimeout + "");
        
         entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties);
-        MailboxSessionEntityManagerFactory emf = new MailboxSessionEntityManagerFactory(entityManagerFactory);
-        mailboxManager = new OpenJPAMailboxManager(null, new JPASubscriptionManager(emf), emf);
+        JPAMailboxSessionMapperFactory mf = new JPAMailboxSessionMapperFactory(entityManagerFactory);
+        mailboxManager = new OpenJPAMailboxManager(mf, null, new JPASubscriptionManager(mf));
         
         // Set the lock timeout via SQL because of a bug in openJPA
         // https://issues.apache.org/jira/browse/OPENJPA-1656
@@ -97,5 +97,5 @@ public class JPAStressTest extends Abstr
     protected StoreMailboxManager<?> getMailboxManager() {
         return mailboxManager;
     }
-   
+
 }

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=951398&r1=951397&r2=951398&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 Fri Jun  4 13:07:05 2010
@@ -24,28 +24,29 @@ import javax.jcr.Session;
 import org.apache.commons.logging.Log;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.store.transaction.AbstractTransactionalMapper;
 
-
-
 /**
  * Abstract Mapper base class for Level 1 Implementations of JCR. So no real transaction management is used. 
  * 
  * The Session.save() will get called on commit() method,  session.refresh(false) on rollback, and session.refresh(true) on begin()
  *
  */
-public abstract class AbstractJCRMapper extends AbstractTransactionalMapper implements JCRImapConstants{
+public abstract class AbstractJCRMapper extends AbstractTransactionalMapper implements JCRImapConstants {
     public final static String MAILBOXES_PATH =  "mailboxes";
     public final static String SUBSCRIPTIONS_PATH =  "subscriptions";
 
-    private final Session session;
+    private Session session;
     private final Log logger;
+	private final MailboxSessionJCRRepository repository;
+	private final MailboxSession mSession;
 
-    public AbstractJCRMapper(final Session session, Log logger) {
-        this.session = session;
+    public AbstractJCRMapper(final MailboxSessionJCRRepository repository, MailboxSession mSession, Log logger) {
+        this.repository = repository;
+        this.mSession = mSession;
         this.logger = logger;
     }
-    
 
     /**
      * Return the logger
@@ -61,22 +62,23 @@ public abstract class AbstractJCRMapper 
      * 
      * @return session
      */
-    protected Session getSession() {
+    protected Session getSession() throws RepositoryException{
+    	if (session == null) {
+    		session = repository.login(mSession);
+    	}
         return session;
     }
 
-
     /**
      * Begin is not supported by level 1 JCR implementations, however we refresh the session
      */
     protected void begin() throws MailboxException {  
         try {
-            session.refresh(true);
+            getSession().refresh(true);
         } catch (RepositoryException e) {
             // do nothin on refresh
         }
         // Do nothing
-        
     }
 
     /**
@@ -84,13 +86,12 @@ public abstract class AbstractJCRMapper 
      */
     protected void commit() throws MailboxException {
         try {
-            if (session.hasPendingChanges()) {
-                session.save();
+            if (getSession().hasPendingChanges()) {
+                getSession().save();
             }
         } catch (RepositoryException e) {
             throw new MailboxException(HumanReadableText.COMMIT_TRANSACTION_FAILED, e);
         }
-
     }
 
     /**
@@ -99,10 +100,23 @@ public abstract class AbstractJCRMapper 
     protected void rollback() throws MailboxException {
         try {
             // just refresh session and discard all pending changes
-            session.refresh(false);
+            getSession().refresh(false);
         } catch (RepositoryException e) {
             // just catch on rollback by now
         }
     }
+
+    /**
+     * Logout from open JCR Session
+     */
+    public void endRequest() {
+        if (session != null) {
+            if (session.isLive())
+                session.logout();
+            session = null;
+        }
+    }
         
+    
+
 }

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=951398&r1=951397&r2=951398&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 Fri Jun  4 13:07:05 2010
@@ -28,8 +28,7 @@ import org.apache.james.imap.mailbox.Mai
 
 /**
  * 
- * Manager one JCR {@link Session} per {@link MailboxSession}. It will use one user and password 
- * for all 
+ * Manage JCR {@link Session}. It will use one user and password for all 
  *
  */
 public class GlobalMailboxSessionJCRRepository extends MailboxSessionJCRRepository{
@@ -52,12 +51,7 @@ public class GlobalMailboxSessionJCRRepo
      */
     @Override
     public Session login(MailboxSession session) throws RepositoryException {
-        Session jcrSession = (Session) session.getAttributes().get(JCR_SESSION);
-        if (jcrSession == null) {
-            
-            jcrSession = getRepository().login(new SimpleCredentials(username, pass), getWorkspace());
-            session.getAttributes().put(JCR_SESSION, jcrSession);
-        }
+        Session jcrSession = getRepository().login(new SimpleCredentials(username, pass), getWorkspace());
         return jcrSession;
     }
 

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxManager.java Fri Jun  4 13:07:05 2010
@@ -21,24 +21,20 @@ package org.apache.james.imap.jcr;
 import java.util.ArrayList;
 import java.util.Locale;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.jcr.mail.JCRMailboxMapper;
+import org.apache.james.imap.jcr.mail.model.JCRMailbox;
 import org.apache.james.imap.mailbox.BadCredentialsException;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.Authenticator;
 import org.apache.james.imap.store.PasswordAwareMailboxSession;
-import org.apache.james.imap.store.StoreMessageManager;
 import org.apache.james.imap.store.StoreMailboxManager;
+import org.apache.james.imap.store.StoreMessageManager;
 import org.apache.james.imap.store.Subscriber;
 import org.apache.james.imap.store.UidConsumer;
-import org.apache.james.imap.store.mail.MailboxMapper;
 import org.apache.james.imap.store.mail.model.Mailbox;
 import org.apache.james.imap.store.transaction.TransactionalMapper;
 
@@ -49,37 +45,24 @@ import org.apache.james.imap.store.trans
  */
 public class JCRMailboxManager extends StoreMailboxManager<String> implements JCRImapConstants{
 
-    private final MailboxSessionJCRRepository repository;
-    private final Log logger = LogFactory.getLog(JCRMailboxManager.class);
+	private final JCRMailboxSessionMapperFactory mapperFactory;    
+	private final Log logger = LogFactory.getLog(JCRMailboxManager.class);
     
-    public JCRMailboxManager(final Authenticator authenticator, final Subscriber subscriber, final MailboxSessionJCRRepository repository) {
-        super(authenticator, subscriber, new JCRUidConsumer(repository));
-        this.repository = repository;
+    public JCRMailboxManager(JCRMailboxSessionMapperFactory mapperFactory, final Authenticator authenticator, final Subscriber subscriber) {
+	    super(mapperFactory, authenticator, subscriber, new JCRUidConsumer(mapperFactory.getRepository()));
+		this.mapperFactory = mapperFactory;
     }
 
 
     @Override
-    protected StoreMessageManager<String> createMailbox(MailboxEventDispatcher dispatcher, UidConsumer<String> consumer,Mailbox<String> mailboxRow, MailboxSession session) throws MailboxException{
-        return new JCRMessageManager(dispatcher, consumer, (org.apache.james.imap.jcr.mail.model.JCRMailbox) mailboxRow, repository, getLog(), getDelimiter());    
-    }
-
-    @Override
-    protected MailboxMapper<String> createMailboxMapper(MailboxSession session) throws MailboxException {
-
-        try {
-            Session jcrSession = repository.login(session);
-            JCRMailboxMapper mapper = new JCRMailboxMapper(jcrSession, getLog(), getDelimiter());
-            return mapper;
-        } catch (RepositoryException e) {
-            throw new MailboxException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
-        }
-        
+    protected StoreMessageManager<String> createMessageManager(MailboxEventDispatcher dispatcher, UidConsumer<String> consumer, Mailbox<String> mailboxEntity, MailboxSession session) throws MailboxException{
+        return new JCRMessageManager(mapperFactory, dispatcher, consumer, (JCRMailbox) mailboxEntity, logger, getDelimiter(), session);
     }
 
     @Override
-    protected void doCreate(String namespaceName, MailboxSession session) throws MailboxException {
+    protected void doCreateMailbox(String namespaceName, MailboxSession session) throws MailboxException {
         final Mailbox<String> mailbox = new org.apache.james.imap.jcr.mail.model.JCRMailbox(namespaceName, randomUidValidity(), logger);
-        final JCRMailboxMapper mapper = (JCRMailboxMapper)createMailboxMapper(session);
+        final JCRMailboxMapper mapper = (JCRMailboxMapper) mapperFactory.getMailboxMapper(session);
         mapper.execute(new TransactionalMapper.Transaction() {
 
             public void run() throws MailboxException {
@@ -110,7 +93,6 @@ public class JCRMailboxManager extends S
      */
     @Override
     public void endProcessingRequest(MailboxSession session) {
-        repository.logout(session);
         super.endProcessingRequest(session);
     }
     

Added: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java?rev=951398&view=auto
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java (added)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java Fri Jun  4 13:07:05 2010
@@ -0,0 +1,74 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jcr;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.james.imap.jcr.mail.JCRMailboxMapper;
+import org.apache.james.imap.jcr.mail.JCRMessageMapper;
+import org.apache.james.imap.jcr.user.JCRSubscriptionMapper;
+
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.mailbox.SubscriptionException;
+import org.apache.james.imap.store.MailboxSessionMapperFactory;
+import org.apache.james.imap.store.mail.MailboxMapper;
+import org.apache.james.imap.store.mail.MessageMapper;
+import org.apache.james.imap.store.user.SubscriptionMapper;
+
+/**
+ * JCR implementation of a {@link MailboxSessionMapperFactory}
+ * 
+ *
+ */
+public class JCRMailboxSessionMapperFactory extends MailboxSessionMapperFactory<String> {
+
+    private MailboxSessionJCRRepository repository;
+    private Log logger;
+    private char delimiter;
+
+    public JCRMailboxSessionMapperFactory(final MailboxSessionJCRRepository repository) {
+        this.repository = repository;
+        this.logger = LogFactory.getLog(JCRSubscriptionManager.class);
+        this.delimiter = '.';
+    }
+
+    @Override
+    public MailboxMapper<String> createMailboxMapper(MailboxSession session) throws MailboxException {
+        JCRMailboxMapper mapper = new JCRMailboxMapper(repository, session, logger, delimiter);
+        return mapper;
+    }
+
+    @Override
+    public MessageMapper<String> createMessageMapper(MailboxSession session) throws MailboxException {
+        JCRMessageMapper messageMapper = new JCRMessageMapper(repository, session, logger);
+        return messageMapper;
+    }
+
+    @Override
+    public SubscriptionMapper createSubscriptionMapper(MailboxSession session) throws SubscriptionException {
+        JCRSubscriptionMapper mapper = new JCRSubscriptionMapper(repository, session, logger);
+        return mapper;
+    }
+    
+    public MailboxSessionJCRRepository getRepository() {
+        return repository;
+    }
+
+}

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java Fri Jun  4 13:07:05 2010
@@ -23,21 +23,17 @@ import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 
-import javax.jcr.RepositoryException;
 import javax.mail.Flags;
 
 import org.apache.commons.logging.Log;
-import org.apache.james.imap.api.display.HumanReadableText;
-import org.apache.james.imap.jcr.mail.JCRMailboxMapper;
-import org.apache.james.imap.jcr.mail.JCRMessageMapper;
 import org.apache.james.imap.jcr.mail.model.JCRHeader;
+import org.apache.james.imap.jcr.mail.model.JCRMailbox;
 import org.apache.james.imap.jcr.mail.model.JCRMessage;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.StoreMessageManager;
 import org.apache.james.imap.store.UidConsumer;
-import org.apache.james.imap.store.mail.MessageMapper;
 import org.apache.james.imap.store.mail.model.Header;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
@@ -46,21 +42,17 @@ import org.apache.james.imap.store.mail.
  * JCR implementation of a {@link StoreMessageManager}
  *
  */
-public class JCRMessageManager extends StoreMessageManager<String>{
+public class JCRMessageManager extends StoreMessageManager<String> {
 
-    private final MailboxSessionJCRRepository repos;
     private final Log log;
-    private char delimiter;
 
-    public JCRMessageManager(final MailboxEventDispatcher dispatcher, UidConsumer<String> consumer, final org.apache.james.imap.jcr.mail.model.JCRMailbox mailbox, final MailboxSessionJCRRepository repos, final Log log, final char delimiter) {
-        super(dispatcher, consumer, mailbox);
+    public JCRMessageManager(JCRMailboxSessionMapperFactory mapperFactory,
+            final MailboxEventDispatcher dispatcher, UidConsumer<String> consumer,
+            final JCRMailbox mailbox, final Log log, final char delimiter, MailboxSession session) throws MailboxException {
+        super(mapperFactory, dispatcher, consumer, mailbox, session);
         this.log = log;
-        this.repos = repos;
-        this.delimiter = delimiter;
-        
     }
 
-
     @Override
     protected MailboxMembership<String> copyMessage(MailboxMembership<String> originalMessage, long uid, MailboxSession session) throws MailboxException {
         MailboxMembership<String> newRow = new JCRMessage(getMailboxId(), uid, (JCRMessage) originalMessage, log);
@@ -80,38 +72,6 @@ public class JCRMessageManager extends S
         }
         final MailboxMembership<String> message = new JCRMessage(getMailboxId(), uid, internalDate, 
                 size, flags, document, bodyStartOctet, jcrHeaders, propertyBuilder, log);
-        return message;       
-        
-    }
-
-    @Override
-    protected MessageMapper<String> createMessageMapper(MailboxSession session) throws MailboxException {
-        try {
-            JCRMessageMapper messageMapper = new JCRMessageMapper(repos.login(session), getMailboxId(), log);
-            return messageMapper;
-        } catch (RepositoryException e) {
-            throw new MailboxException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
-        }
-        
-    }
-
-    /**
-     * Ceate a MailboxMapper for the given {@link MailboxSession} 
-     * 
-     * @param session
-     * @return mailboxMapper
-     * @throws MailboxException 
-     * @throws MailboxException
-     */
-    protected JCRMailboxMapper createMailboxMapper(MailboxSession session) throws MailboxException {
-        try {
-            JCRMailboxMapper mapper = new JCRMailboxMapper(repos.login(session), log, delimiter);
-            return mapper;
-
-        } catch (RepositoryException e) {
-            throw new MailboxException(HumanReadableText.GENERIC_FAILURE_DURING_PROCESSING, e);
-        }
-        
-
+        return message;
     }
-}
+}
\ No newline at end of file

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRSubscriptionManager.java Fri Jun  4 13:07:05 2010
@@ -18,48 +18,22 @@
  ****************************************************************/
 package org.apache.james.imap.jcr;
 
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.james.imap.api.display.HumanReadableText;
-import org.apache.james.imap.jcr.user.JCRSubscriptionMapper;
 import org.apache.james.imap.jcr.user.model.JCRSubscription;
 import org.apache.james.imap.mailbox.MailboxSession;
-import org.apache.james.imap.mailbox.SubscriptionException;
 import org.apache.james.imap.store.StoreSubscriptionManager;
-import org.apache.james.imap.store.user.SubscriptionMapper;
 import org.apache.james.imap.store.user.model.Subscription;
 
 /**
  * JCR implementation of a SubscriptionManager
- * 
- * 
  */
-public class JCRSubscriptionManager extends StoreSubscriptionManager implements JCRImapConstants{
-    private final Log logger = LogFactory.getLog(JCRSubscriptionManager.class);
-    private final MailboxSessionJCRRepository repository;
-
-    public JCRSubscriptionManager(final MailboxSessionJCRRepository repository ) {
-        super();
-        this.repository = repository;
-    }
-
-
+public class JCRSubscriptionManager extends StoreSubscriptionManager<String> implements JCRImapConstants {
     
-    @Override
-    protected SubscriptionMapper createMapper(MailboxSession session) throws SubscriptionException {
-        try {
-            Session jcrSession = repository.login(session);
-            JCRSubscriptionMapper mapper = new JCRSubscriptionMapper(jcrSession, logger);
+    private final Log logger = LogFactory.getLog(JCRSubscriptionManager.class);
 
-            return mapper;
-        } catch (RepositoryException e) {
-            throw new SubscriptionException(HumanReadableText.GENERIC_SUBSCRIPTION_FAILURE, e);
-        }        
-        
-      
+    public JCRSubscriptionManager(JCRMailboxSessionMapperFactory mapperFactory) {
+        super(mapperFactory);
     }
 
     @Override

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=951398&r1=951397&r2=951398&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 Fri Jun  4 13:07:05 2010
@@ -27,7 +27,7 @@ import org.apache.james.imap.mailbox.Mai
 import org.apache.james.imap.store.PasswordAwareUser;
 
 /**
- * Manage JCR {@link Session} per {@link MailboxSession}. It use the username and the password of 
+ * Manage JCR {@link Session}. It use the username and the password of 
  * the logged in IMAP user to access the {@link Repository}
  *
  */
@@ -35,14 +35,12 @@ public class MailboxSessionJCRRepository
     
     private Repository repository;
     private String workspace;
-    protected final static String JCR_SESSION = "JCR_SESSION";
     
     public MailboxSessionJCRRepository(Repository repository ,String workspace) {
         this.repository = repository;
         this.workspace = workspace;
     }
 
-
     /**
      * If no {@link Session} exists for the {@link MailboxSession} one will get created.
      * If one exists it just return the existing.
@@ -52,35 +50,17 @@ public class MailboxSessionJCRRepository
      * @throws RepositoryException
      */
     public Session login(MailboxSession session) throws RepositoryException {
-        Session jcrSession = (Session) session.getAttributes().get(JCR_SESSION);
-        if (jcrSession == null) {
-            PasswordAwareUser user = (PasswordAwareUser) session.getUser();
-            String username = user.getUserName();
-            String password = user.getPassword();
-            char[] pass = null;
-            if (password != null) {
-                pass = password.toCharArray();
-            }
-            jcrSession = repository.login(new SimpleCredentials(username, pass), workspace);
-            session.getAttributes().put(JCR_SESSION, jcrSession);
+        PasswordAwareUser user = (PasswordAwareUser) session.getUser();
+        String username = user.getUserName();
+        String password = user.getPassword();
+        char[] pass = null;
+        if (password != null) {
+            pass = password.toCharArray();
         }
-        return jcrSession;
+        return repository.login(new SimpleCredentials(username, pass),
+                workspace);
     }
-    
-    /**
-     * Logout the {@link Session} which exists for the {@link MailboxSession}
-     * 
-     * @param session
-     */
-    public void logout(MailboxSession session) {
-        if (session != null) {
-            Session jcrSession = (Session) session.getAttributes().remove(JCR_SESSION);
-            if (jcrSession != null && jcrSession.isLive()) {
-                jcrSession.logout();
-            }
-        }
-    }
-    
+
     /**
      * Return the {@link Repository} 
      * 
@@ -90,7 +70,6 @@ public class MailboxSessionJCRRepository
         return repository;
     }
     
-    
     /**
      * Return the workspace
      * 

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/Persistent.java Fri Jun  4 13:07:05 2010
@@ -26,25 +26,25 @@ import javax.jcr.RepositoryException;
 
 public interface Persistent {
 
-	/**
-	 * Merge the object with the node
-	 * 
-	 * @param node
-	 */
-	public void merge(Node node) throws RepositoryException,IOException;
+    /**
+     * Merge the object with the node
+     * 
+     * @param node
+     */
+    public void merge(Node node) throws RepositoryException, IOException;
 
-	/**
-	 * Return underlying Node
-	 * 
-	 * @return node
-	 */
-	public Node getNode();
+    /**
+     * Return underlying Node
+     * 
+     * @return node
+     */
+    public Node getNode();
 
-	/**
-	 * Return if the object is persistent
-	 * 
-	 * @return
-	 */
-	public boolean isPersistent();
+    /**
+     * Return if the object is persistent
+     * 
+     * @return
+     */
+    public boolean isPersistent();
 
 }

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=951398&r1=951397&r2=951398&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 Fri Jun  4 13:07:05 2010
@@ -25,7 +25,6 @@ import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
@@ -36,8 +35,10 @@ import org.apache.jackrabbit.commons.Jcr
 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.mail.model.JCRMailbox;
 import org.apache.james.imap.mailbox.MailboxNotFoundException;
+import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.StorageException;
 import org.apache.james.imap.store.mail.MailboxMapper;
 import org.apache.james.imap.store.mail.model.Mailbox;
@@ -51,8 +52,8 @@ public class JCRMailboxMapper extends Ab
 
     private char delimiter;
 
-    public JCRMailboxMapper(final Session session, final Log logger, char delimiter) {
-        super(session, logger);
+    public JCRMailboxMapper(final MailboxSessionJCRRepository repos, MailboxSession session, final Log logger, char delimiter) {
+        super(repos, session, logger);
         this.delimiter = delimiter;
     }
 
@@ -144,7 +145,6 @@ public class JCRMailboxMapper extends Ab
         }
     }
 
-
     /*
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MailboxMapper#findMailboxById(java.lang.Object)
@@ -241,7 +241,7 @@ public class JCRMailboxMapper extends Ab
                         final String name = jcrMailbox.getName();
                         
                         //split the name so we can construct a nice node tree
-                        final String nameParts[] = name.split("\\" +String.valueOf(delimiter),3);
+                        final String nameParts[] = name.split("\\" + String.valueOf(delimiter), 3);
                         
                         // this loop will create a structure like:
                         // /mailboxes/u/user/INBOX

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=951398&r1=951397&r2=951398&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 Fri Jun  4 13:07:05 2010
@@ -27,7 +27,6 @@ import java.util.List;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
@@ -38,7 +37,9 @@ import org.apache.jackrabbit.commons.Jcr
 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.mail.model.JCRMessage;
+import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.MessageRange;
 import org.apache.james.imap.mailbox.SearchQuery;
 import org.apache.james.imap.mailbox.StorageException;
@@ -54,11 +55,8 @@ import org.apache.james.imap.store.mail.
  */
 public class JCRMessageMapper extends AbstractJCRMapper implements MessageMapper<String> {
 
-    private final String uuid;
-
-    public JCRMessageMapper(final Session session, final String uuid, final Log logger) {
-        super(session, logger);
-        this.uuid = uuid;
+    public JCRMessageMapper(final MailboxSessionJCRRepository repos, MailboxSession session, final Log logger) {
+        super(repos, session, logger);
     }
 
     /*
@@ -67,7 +65,7 @@ public class JCRMessageMapper extends Ab
      * @see
      * org.apache.james.imap.store.mail.MessageMapper#countMessagesInMailbox()
      */
-    public long countMessagesInMailbox() throws StorageException {
+    public long countMessagesInMailbox(String uuid) throws StorageException {
         try {
             // we use order by because without it count will always be 0 in jackrabbit
             String queryString = "//" + MAILBOXES_PATH + "//element(*,jamesMailbox:message)[@" + JCRMessage.MAILBOX_UUID_PROPERTY +"='" + uuid +"'] order by @" + JCRMessage.UID_PROPERTY;
@@ -97,7 +95,7 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#countUnseenMessagesInMailbox
      * ()
      */
-    public long countUnseenMessagesInMailbox() throws StorageException {
+    public long countUnseenMessagesInMailbox(String uuid) throws StorageException {
         
         try {
             // we use order by because without it count will always be 0 in jackrabbit
@@ -124,12 +122,9 @@ public class JCRMessageMapper extends Ab
 
     /*
      * (non-Javadoc)
-     * 
-     * @see
-     * org.apache.james.imap.store.mail.MessageMapper#delete(org.apache.james
-     * .imap.store.mail.model.MailboxMembership)
+     * @see org.apache.james.imap.store.mail.MessageMapper#delete(java.lang.Object, org.apache.james.imap.store.mail.model.MailboxMembership)
      */
-    public void delete(MailboxMembership<String> message) throws StorageException {
+    public void delete(String uuid, MailboxMembership<String> message) throws StorageException {
         JCRMessage membership = (JCRMessage) message;
         if (membership.isPersistent()) {
             try {
@@ -149,7 +144,7 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#findInMailbox(org.apache
      * .james.imap.mailbox.MessageRange)
      */
-    public List<MailboxMembership<String>> findInMailbox(MessageRange set) throws StorageException {
+    public List<MailboxMembership<String>> findInMailbox(String uuid, MessageRange set) throws StorageException {
         try {
             final List<MailboxMembership<String>> results;
             final long from = set.getUidFrom();
@@ -300,7 +295,7 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#findMarkedForDeletionInMailbox
      * (org.apache.james.imap.mailbox.MessageRange)
      */
-    public List<MailboxMembership<String>> findMarkedForDeletionInMailbox(MessageRange set) throws StorageException {
+    public List<MailboxMembership<String>> findMarkedForDeletionInMailbox(String uuid, MessageRange set) throws StorageException {
         try {
             final List<MailboxMembership<String>> results;
             final long from = set.getUidFrom();
@@ -335,7 +330,7 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#findRecentMessagesInMailbox
      * ()
      */
-    public List<MailboxMembership<String>> findRecentMessagesInMailbox() throws StorageException {
+    public List<MailboxMembership<String>> findRecentMessagesInMailbox(String uuid) throws StorageException {
         
         try {
             List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
@@ -360,7 +355,7 @@ public class JCRMessageMapper extends Ab
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
      */
-    public List<MailboxMembership<String>> findUnseenMessagesInMailbox() throws StorageException {
+    public List<MailboxMembership<String>> findUnseenMessagesInMailbox(String uuid) throws StorageException {
         try {
             List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
             String queryString = "//" + MAILBOXES_PATH + "//element(*,jamesMailbox:message)[@" + JCRMessage.MAILBOX_UUID_PROPERTY +"='" + uuid +"'] AND [@" + JCRMessage.SEEN_PROPERTY +"='false'] order by @" + JCRMessage.UID_PROPERTY;
@@ -386,7 +381,7 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#save(org.apache.james.
      * imap.store.mail.model.MailboxMembership)
      */
-    public void save(MailboxMembership<String> message) throws StorageException {
+    public void save(String uuid, MailboxMembership<String> message) throws StorageException {
         final JCRMessage membership = (JCRMessage) message;
         try {
             //JCRUtils.createNodeRecursive(getSession().getRootNode(), mailboxN);
@@ -483,7 +478,7 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#searchMailbox(org.apache
      * .james.imap.mailbox.SearchQuery)
      */
-    public List<MailboxMembership<String>> searchMailbox(SearchQuery query) throws StorageException {
+    public List<MailboxMembership<String>> searchMailbox(String uuid, SearchQuery query) throws StorageException {
         try {
             List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
             final String xpathQuery = formulateXPath(uuid, query);

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java Fri Jun  4 13:07:05 2010
@@ -38,13 +38,13 @@ import org.apache.james.imap.api.display
 import org.apache.james.imap.jcr.JCRImapConstants;
 import org.apache.james.imap.jcr.Persistent;
 import org.apache.james.imap.mailbox.MailboxException;
-import org.apache.james.imap.store.StreamUtils;
 import org.apache.james.imap.store.mail.model.AbstractDocument;
 import org.apache.james.imap.store.mail.model.Document;
 import org.apache.james.imap.store.mail.model.Header;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
 import org.apache.james.imap.store.mail.model.Property;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
+import org.apache.james.imap.store.streaming.StreamUtils;
 
 /**
  * JCR implementation of {@link Document}
@@ -485,6 +485,7 @@ public class JCRMessage extends Abstract
      */
     public Document getDocument() {
         if (isPersistent()) {
+        	//TODO: Why not "this"?
             return new JCRMessage(node, logger);
            
         }

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/user/JCRSubscriptionMapper.java Fri Jun  4 13:07:05 2010
@@ -25,7 +25,6 @@ import javax.jcr.Node;
 import javax.jcr.NodeIterator;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.jcr.query.Query;
 import javax.jcr.query.QueryManager;
 import javax.jcr.query.QueryResult;
@@ -34,7 +33,9 @@ import org.apache.commons.logging.Log;
 import org.apache.jackrabbit.commons.JcrUtils;
 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.user.model.JCRSubscription;
+import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.SubscriptionException;
 import org.apache.james.imap.store.user.SubscriptionMapper;
 import org.apache.james.imap.store.user.model.Subscription;
@@ -45,8 +46,8 @@ import org.apache.james.imap.store.user.
  */
 public class JCRSubscriptionMapper extends AbstractJCRMapper implements SubscriptionMapper {
 
-    public JCRSubscriptionMapper(final Session session, final Log log) {
-        super(session, log);
+    public JCRSubscriptionMapper(final MailboxSessionJCRRepository repos, MailboxSession session, final Log log) {
+        super(repos,session, log);
     }
 
     /*

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java Fri Jun  4 13:07:05 2010
@@ -18,8 +18,7 @@
  ****************************************************************/
 package org.apache.james.imap.jpa;
 
-
-import org.apache.james.imap.jpa.mail.JPAMailboxMapper;
+import org.apache.james.imap.jpa.mail.model.JPAMailbox;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.store.Authenticator;
@@ -29,26 +28,20 @@ import org.apache.james.imap.store.mail.
 import org.apache.james.imap.store.mail.model.Mailbox;
 import org.apache.james.imap.store.transaction.TransactionalMapper;
 
-
 /**
  * JPA implementation of {@link StoreMailboxManager}
- * 
- *
  */
 public abstract class JPAMailboxManager extends StoreMailboxManager<Long> {
-
-    protected final MailboxSessionEntityManagerFactory entityManagerFactory;
-    public JPAMailboxManager(final Authenticator authenticator, final Subscriber subscriber, 
-            final MailboxSessionEntityManagerFactory entityManagerFactory) {
-        super(authenticator, subscriber,new JPAUidConsumer(entityManagerFactory));
-        this.entityManagerFactory = entityManagerFactory;
-    }
     
+    public JPAMailboxManager(JPAMailboxSessionMapperFactory mailboxSessionMapperFactory,
+            final Authenticator authenticator, final Subscriber subscriber) {
+        super(mailboxSessionMapperFactory, authenticator, subscriber, new JPAUidConsumer(mailboxSessionMapperFactory));
+    }
     
     @Override
-    protected void doCreate(String namespaceName, MailboxSession session) throws MailboxException {
-        final Mailbox<Long> mailbox = new org.apache.james.imap.jpa.mail.model.JPAMailbox(namespaceName, randomUidValidity());
-        final MailboxMapper<Long> mapper = createMailboxMapper(session);
+    protected void doCreateMailbox(String namespaceName, MailboxSession session) throws MailboxException {
+        final Mailbox<Long> mailbox = new JPAMailbox(namespaceName, randomUidValidity());
+        final MailboxMapper<Long> mapper = mailboxSessionMapperFactory.getMailboxMapper(session);
         mapper.execute(new TransactionalMapper.Transaction(){
 
             public void run() throws MailboxException {
@@ -65,7 +58,7 @@ public abstract class JPAMailboxManager 
      * @throws MailboxException
      */
     public void deleteEverything(MailboxSession mailboxSession) throws MailboxException {
-        final MailboxMapper<Long> mapper = createMailboxMapper(mailboxSession);
+        final MailboxMapper<Long> mapper = mailboxSessionMapperFactory.getMailboxMapper(mailboxSession);
         mapper.execute(new TransactionalMapper.Transaction() {
 
             public void run() throws MailboxException {
@@ -74,18 +67,5 @@ public abstract class JPAMailboxManager 
             
         });
     }
-
-    
-    @Override
-    public void endProcessingRequest(MailboxSession session) {
-        entityManagerFactory.closeEntityManager(session);
-    }
-
-
-    @Override
-    protected MailboxMapper<Long> createMailboxMapper(MailboxSession session) {
-        return new JPAMailboxMapper(entityManagerFactory.createEntityManager(session));
-    }
-
     
 }

Added: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java?rev=951398&view=auto
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java (added)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java Fri Jun  4 13:07:05 2010
@@ -0,0 +1,69 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jpa;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.james.imap.jpa.mail.JPAMailboxMapper;
+import org.apache.james.imap.jpa.mail.JPAMessageMapper;
+import org.apache.james.imap.jpa.user.JPASubscriptionMapper;
+import org.apache.james.imap.mailbox.MailboxSession;
+import org.apache.james.imap.store.MailboxSessionMapperFactory;
+import org.apache.james.imap.store.mail.MailboxMapper;
+import org.apache.james.imap.store.mail.MessageMapper;
+import org.apache.james.imap.store.user.SubscriptionMapper;
+
+/**
+ * JPA implementation of {@link MailboxSessionMapperFactory}
+ *
+ */
+public class JPAMailboxSessionMapperFactory extends MailboxSessionMapperFactory<Long> {
+
+    private final EntityManagerFactory entityManagerFactory;
+
+    public JPAMailboxSessionMapperFactory(EntityManagerFactory entityManagerFactory) {
+        this.entityManagerFactory = entityManagerFactory;
+    }
+
+    @Override
+    public MailboxMapper<Long> createMailboxMapper(MailboxSession session) {
+        return new JPAMailboxMapper(entityManagerFactory);
+    }
+
+    @Override
+    public MessageMapper<Long> createMessageMapper(MailboxSession session) {
+        return new JPAMessageMapper(entityManagerFactory);
+    }
+
+    @Override
+    public SubscriptionMapper createSubscriptionMapper(MailboxSession session) {
+        return new JPASubscriptionMapper(entityManagerFactory);
+    }
+
+    /**
+     * Return a new {@link EntityManager} instance
+     * 
+     * @return manager
+     */
+    public EntityManager createEntityManager() {
+        return entityManagerFactory.createEntityManager();
+    }
+
+}

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java Fri Jun  4 13:07:05 2010
@@ -25,8 +25,6 @@ import java.util.List;
 
 import javax.mail.Flags;
 
-import org.apache.james.imap.jpa.mail.JPAMailboxMapper;
-import org.apache.james.imap.jpa.mail.JPAMessageMapper;
 import org.apache.james.imap.jpa.mail.model.AbstractJPAMailboxMembership;
 import org.apache.james.imap.jpa.mail.model.JPAHeader;
 import org.apache.james.imap.jpa.mail.model.JPAMailboxMembership;
@@ -35,8 +33,6 @@ import org.apache.james.imap.mailbox.Mai
 import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.StoreMessageManager;
 import org.apache.james.imap.store.UidConsumer;
-import org.apache.james.imap.store.mail.MailboxMapper;
-import org.apache.james.imap.store.mail.MessageMapper;
 import org.apache.james.imap.store.mail.model.Header;
 import org.apache.james.imap.store.mail.model.Mailbox;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
@@ -44,27 +40,13 @@ import org.apache.james.imap.store.mail.
 
 /**
  * Abstract base class which should be used from JPA 2.0 implementations
- * 
- * 
- *
  */
 public class JPAMessageManager extends StoreMessageManager<Long> {
-
-    protected final MailboxSessionEntityManagerFactory entityManagerFactory;
-    
-    public JPAMessageManager(final MailboxEventDispatcher dispatcher, final UidConsumer<Long> consumer,final Mailbox<Long> mailbox, final MailboxSessionEntityManagerFactory entityManagerFactory) {
-        super(dispatcher, consumer, mailbox);
-        this.entityManagerFactory = entityManagerFactory;        
-    }  
-
-
-
     
-    @Override
-    protected MessageMapper<Long> createMessageMapper(MailboxSession session) {                
-        JPAMessageMapper mapper = new JPAMessageMapper(entityManagerFactory.createEntityManager(session), getMailboxId());
-       
-        return mapper;
+    public JPAMessageManager(JPAMailboxSessionMapperFactory mapperFactory,
+            final MailboxEventDispatcher dispatcher, final UidConsumer<Long> consumer,
+            final Mailbox<Long> mailbox, MailboxSession session) throws MailboxException {
+        super(mapperFactory, dispatcher, consumer, mailbox, session);     
     }
     
     @Override
@@ -76,8 +58,6 @@ public class JPAMessageManager extends S
         }
         final MailboxMembership<Long> message = new JPAMailboxMembership(getMailboxId(), uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
         return message;
-
-       
     }
     
     @Override
@@ -86,20 +66,10 @@ public class JPAMessageManager extends S
         return newRow;
     }
     
-    
     @Override
     protected Header createHeader(int lineNumber, String name, String value) {
         final Header header = new JPAHeader(lineNumber, name, value);
         return header;
     }
-
-
-
-
-    @Override
-    protected MailboxMapper<Long> createMailboxMapper(MailboxSession session) {
-        return new JPAMailboxMapper(entityManagerFactory.createEntityManager(session));
-    }
-    
     
 }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java Fri Jun  4 13:07:05 2010
@@ -18,34 +18,19 @@
  ****************************************************************/
 package org.apache.james.imap.jpa;
 
-import org.apache.james.imap.jpa.user.JPASubscriptionMapper;
 import org.apache.james.imap.jpa.user.model.JPASubscription;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.store.StoreSubscriptionManager;
-import org.apache.james.imap.store.user.SubscriptionMapper;
 import org.apache.james.imap.store.user.model.Subscription;
 
 /**
  * JPA implementation of {@link StoreSubscriptionManager}
- * 
  *
  */
-public class JPASubscriptionManager extends StoreSubscriptionManager {
-    private final MailboxSessionEntityManagerFactory factory;
+public class JPASubscriptionManager extends StoreSubscriptionManager<Long> {
     
-    public JPASubscriptionManager(final MailboxSessionEntityManagerFactory factory) {
-        super();
-        this.factory = factory;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.StoreSubscriptionManager#createMapper(org.apache.james.imap.mailbox.MailboxSession)
-     */
-    protected SubscriptionMapper createMapper(MailboxSession session) {                
-        JPASubscriptionMapper  mapper = new JPASubscriptionMapper(factory.createEntityManager(session));
-        
-        return mapper;
+    public JPASubscriptionManager(final JPAMailboxSessionMapperFactory mapperFactory) {
+        super(mapperFactory);
     }
     
     /*

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPATransactionalMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPATransactionalMapper.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPATransactionalMapper.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPATransactionalMapper.java Fri Jun  4 13:07:05 2010
@@ -18,7 +18,6 @@
  ****************************************************************/
 package org.apache.james.imap.jpa;
 
-
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 import javax.persistence.EntityTransaction;
@@ -35,17 +34,22 @@ import org.apache.james.imap.store.trans
  */
 public abstract class JPATransactionalMapper extends AbstractTransactionalMapper {
 
-    private EntityManager entityManager;
-    public JPATransactionalMapper(final EntityManager entityManager) {
-        this.entityManager = entityManager;
+    protected EntityManagerFactory entityManagerFactory;
+    protected EntityManager entityManager;
+    
+    public JPATransactionalMapper(final EntityManagerFactory entityManagerFactory) {
+        this.entityManagerFactory = entityManagerFactory;
     }
 
     /**
-     * Return the currently used {@link EntityManager}. If the currently used {@link EntityManager} is null or is closed a new will get obtained from the {@link EntityManagerFactory}
+     * Return the currently used {@link EntityManager} or a new one if none exists.
      * 
      * @return entitymanger
      */
-    protected EntityManager getManager() {
+    public EntityManager getEntityManager() {
+        if (entityManager != null)
+            return entityManager;
+        entityManager = entityManagerFactory.createEntityManager();
         return entityManager;
     }
 
@@ -55,19 +59,18 @@ public abstract class JPATransactionalMa
      */
     protected void begin() throws MailboxException {
         try {
-            getManager().getTransaction().begin();
+            getEntityManager().getTransaction().begin();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.START_TRANSACTION_FAILED, e);
         }
     }
-    
 
     /**
      * Commit the Transaction and close the EntityManager
      */
     protected void commit() throws MailboxException {
         try {
-            getManager().getTransaction().commit();
+            getEntityManager().getTransaction().commit();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.COMMIT_TRANSACTION_FAILED, e);
         }
@@ -81,9 +84,20 @@ public abstract class JPATransactionalMa
         EntityTransaction transaction = entityManager.getTransaction();
         // check if we have a transaction to rollback
         if (transaction.isActive()) {
-            getManager().getTransaction().rollback();
+            getEntityManager().getTransaction().rollback();
+        }
+    }
+
+    /**
+     * Close open {@link EntityManager}
+     */
+    public void endRequest() {
+        if (entityManager != null) {
+            if (entityManager.isOpen())
+                entityManager.close();
+            entityManager = null;
         }
     }
-    
 
+    
 }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAUidConsumer.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAUidConsumer.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAUidConsumer.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAUidConsumer.java Fri Jun  4 13:07:05 2010
@@ -22,42 +22,41 @@ import javax.persistence.EntityManager;
 import javax.persistence.EntityTransaction;
 import javax.persistence.LockModeType;
 
+import org.apache.james.imap.jpa.mail.model.JPAMailbox;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.store.UidConsumer;
 import org.apache.james.imap.store.mail.model.Mailbox;
 
 /**
  * Take care of consume/reserve the next uid for a {@link Mailbox}. This is done by using database locks
- * 
  *
  */
 public class JPAUidConsumer implements UidConsumer<Long>{
 
-    private final MailboxSessionEntityManagerFactory factory;
+    private final JPAMailboxSessionMapperFactory factory;
 
-    public JPAUidConsumer(final MailboxSessionEntityManagerFactory factory) {
+    public JPAUidConsumer(final JPAMailboxSessionMapperFactory factory) {
         this.factory = factory;
     }
     
     /**
-     * 
      * Reserve next Uid in mailbox and return the mailbox. We use a PESSIMISTIC_WRITE lock here to be sure we don't see any duplicates here when
      * accessing the database with many different threads / connections
      * 
      * @see org.apache.james.imap.store.UidConsumer#reserveNextUid(org.apache.james.imap.store.mail.model.Mailbox, org.apache.james.imap.mailbox.MailboxSession)
      */
     public long reserveNextUid(Mailbox<Long> mailbox, MailboxSession session) {
-        EntityManager manager = factory.createEntityManager(session);
+        EntityManager manager = factory.createEntityManager();
         EntityTransaction transaction = manager.getTransaction();
         transaction.begin();
-
-        // we need to set a persimistic write lock to be sure we don't get any problems with dirty reads etc
-        org.apache.james.imap.jpa.mail.model.JPAMailbox m = manager.find(org.apache.james.imap.jpa.mail.model.JPAMailbox.class, mailbox.getMailboxId(), LockModeType.PESSIMISTIC_WRITE);
+        // we need to set a pessimistic write lock to be sure we don't get any problems with dirty reads etc.
+        JPAMailbox m = manager.find(JPAMailbox.class, mailbox.getMailboxId(), LockModeType.PESSIMISTIC_WRITE);
         manager.refresh(m);
         m.consumeUid();
         manager.persist(m);
         manager.flush();
         transaction.commit();
+        manager.close();
         return m.getLastUid();
     }
 

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java Fri Jun  4 13:07:05 2010
@@ -21,7 +21,7 @@ package org.apache.james.imap.jpa.mail;
 
 import java.util.List;
 
-import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
 import javax.persistence.NoResultException;
 import javax.persistence.PersistenceException;
 
@@ -40,8 +40,8 @@ public class JPAMailboxMapper extends JP
 
     private static final char SQL_WILDCARD_CHAR = '%';
     
-    public JPAMailboxMapper(EntityManager factory) {
-        super(factory);
+    public JPAMailboxMapper(EntityManagerFactory entityManagerFactory) {
+        super(entityManagerFactory);
     }
 
     /**
@@ -50,18 +50,16 @@ public class JPAMailboxMapper extends JP
     public boolean existsMailboxStartingWith(String mailboxName) throws StorageException {
         
         final String name = mailboxName + SQL_WILDCARD_CHAR; 
-        final Long numberOfChildMailboxes = (Long) getManager().createNamedQuery("countMailboxesWithNameLike").setParameter("nameParam", name).getSingleResult();
+        final Long numberOfChildMailboxes = (Long) getEntityManager().createNamedQuery("countMailboxesWithNameLike").setParameter("nameParam", name).getSingleResult();
         return numberOfChildMailboxes != null && numberOfChildMailboxes > 0;
     }
 
-
-
     /**
      * @see org.apache.james.imap.store.mail.MailboxMapper#save(Mailbox)
      */
     public void save(Mailbox<Long> mailbox) throws StorageException {
         try {
-            getManager().persist(mailbox);
+            getEntityManager().persist(mailbox);
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.SAVE_FAILED, e);
         } 
@@ -72,7 +70,7 @@ public class JPAMailboxMapper extends JP
      */
     public Mailbox<Long> findMailboxByName(String name) throws StorageException, MailboxNotFoundException {
         try {
-            return (JPAMailbox) getManager().createNamedQuery("findMailboxByName").setParameter("nameParam", name).getSingleResult();
+            return (JPAMailbox) getEntityManager().createNamedQuery("findMailboxByName").setParameter("nameParam", name).getSingleResult();
         } catch (NoResultException e) {
             throw new MailboxNotFoundException(name);
             
@@ -86,7 +84,7 @@ public class JPAMailboxMapper extends JP
      */
     public void delete(Mailbox<Long> mailbox) throws StorageException {
         try {  
-            getManager().remove(mailbox);
+            getEntityManager().remove(mailbox);
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.DELETED_FAILED, e);
         } 
@@ -98,7 +96,7 @@ public class JPAMailboxMapper extends JP
     @SuppressWarnings("unchecked")
     public List<Mailbox<Long>> findMailboxWithNameLike(String name) throws StorageException {
         try {
-            return getManager().createNamedQuery("findMailboxWithNameLike").setParameter("nameParam", SQL_WILDCARD_CHAR + name + SQL_WILDCARD_CHAR).getResultList();
+            return getEntityManager().createNamedQuery("findMailboxWithNameLike").setParameter("nameParam", SQL_WILDCARD_CHAR + name + SQL_WILDCARD_CHAR).getResultList();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
         } 
@@ -109,7 +107,7 @@ public class JPAMailboxMapper extends JP
      */
     public void deleteAll() throws StorageException {
         try {
-            getManager().createNamedQuery("deleteAll").executeUpdate();
+            getEntityManager().createNamedQuery("deleteAll").executeUpdate();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.DELETED_FAILED, e);
         } 
@@ -120,7 +118,7 @@ public class JPAMailboxMapper extends JP
      */
     public long countMailboxesWithName(String name) throws StorageException {
         try {
-            return (Long) getManager().createNamedQuery("countMailboxesWithName").setParameter("nameParam", name).getSingleResult();
+            return (Long) getEntityManager().createNamedQuery("countMailboxesWithName").setParameter("nameParam", name).getSingleResult();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.COUNT_FAILED, e);
         } 
@@ -131,7 +129,7 @@ public class JPAMailboxMapper extends JP
      */
     public Mailbox<Long> findMailboxById(Long mailboxId) throws StorageException, MailboxNotFoundException  {
         try {
-            return (JPAMailbox) getManager().createNamedQuery("findMailboxById").setParameter("idParam", mailboxId).getSingleResult();
+            return (JPAMailbox) getEntityManager().createNamedQuery("findMailboxById").setParameter("idParam", mailboxId).getSingleResult();
         } catch (NoResultException e) {
             throw new MailboxNotFoundException(mailboxId);   
         } catch (PersistenceException e) {



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