You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2009/01/07 19:33:40 UTC

svn commit: r732419 - in /james/protocols/imap/trunk: deployment/src/test/java/org/apache/james/imap/functional/jpa/ jpa/src/main/java/org/apache/james/imap/jpa/ jpa/src/main/java/org/apache/james/imap/store/

Author: rdonkin
Date: Wed Jan  7 10:33:39 2009
New Revision: 732419

URL: http://svn.apache.org/viewvc?rev=732419&view=rev
Log:
Factor out JPA code into subclasses

Added:
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java
Modified:
    james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailbox.java
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java

Modified: james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java?rev=732419&r1=732418&r2=732419&view=diff
==============================================================================
--- james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java (original)
+++ james/protocols/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java Wed Jan  7 10:33:39 2009
@@ -29,10 +29,11 @@
 import org.apache.james.imap.functional.ImapHostSystem;
 import org.apache.james.imap.functional.SimpleMailboxManagerProvider;
 import org.apache.james.imap.functional.jpa.user.InMemoryUserManager;
+import org.apache.james.imap.jpa.JPAMailboxManager;
+import org.apache.james.imap.jpa.JPASubscriptionManager;
 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.imap.store.StoreSubscriptionManager;
 import org.apache.james.test.functional.HostSystem;
 import org.apache.openjpa.persistence.OpenJPAPersistence;
 
@@ -61,7 +62,7 @@
         
         userManager = new InMemoryUserManager();
         final EntityManagerFactory entityManagerFactory = OpenJPAPersistence.getEntityManagerFactory(properties);
-        mailboxManager = new StoreMailboxManager(userManager, new StoreSubscriptionManager(entityManagerFactory), entityManagerFactory);
+        mailboxManager = new JPAMailboxManager(userManager, new JPASubscriptionManager(entityManagerFactory), entityManagerFactory);
         
         SimpleMailboxManagerProvider provider = new SimpleMailboxManagerProvider();
         final DefaultImapProcessorFactory defaultImapProcessorFactory = new DefaultImapProcessorFactory();

Added: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java?rev=732419&view=auto
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java (added)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java Wed Jan  7 10:33:39 2009
@@ -0,0 +1,90 @@
+/****************************************************************
+ * 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 java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.persistence.EntityManagerFactory;
+
+import org.apache.commons.logging.Log;
+import org.apache.james.imap.jpa.mail.JPAMailboxMapper;
+import org.apache.james.imap.jpa.mail.JPAMessageMapper;
+import org.apache.james.imap.jpa.mail.map.openjpa.OpenJPAMailboxMapper;
+import org.apache.james.imap.jpa.mail.model.JPAHeader;
+import org.apache.james.imap.jpa.mail.model.JPAMessage;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.store.StoreMailbox;
+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.Message;
+
+public class JPAMailbox extends StoreMailbox {
+
+    private final EntityManagerFactory entityManagerFactory;
+
+    public JPAMailbox(final Mailbox mailbox, final Log log, final EntityManagerFactory entityManagerfactory) {
+        super(mailbox, log);
+        this.entityManagerFactory = entityManagerfactory;
+    }    
+
+    @Override
+    protected Mailbox getMailboxRow() throws MailboxException {
+        final MailboxMapper mapper = createMailboxMapper();
+        return mapper.findMailboxById(mailboxId);
+    }
+
+    @Override
+    protected MailboxMapper createMailboxMapper() {
+        final JPAMailboxMapper mapper = new OpenJPAMailboxMapper(entityManagerFactory.createEntityManager());
+        return mapper;
+    }
+    
+    @Override
+    protected MessageMapper createMessageMapper() {
+        final MessageMapper mapper = new JPAMessageMapper(entityManagerFactory.createEntityManager());
+        return mapper;
+    }
+    
+    @Override
+    protected Message createMessage(Date internalDate, final long uid, final int size, final byte[] body, final Flags flags, final List<Header> headers) {
+        final List<JPAHeader> jpaHeaders = new ArrayList<JPAHeader>(headers.size());
+        for (Header header: headers) {
+            jpaHeaders.add((JPAHeader) header);
+        }
+        final Message message = new JPAMessage(mailboxId, uid, internalDate, size, flags, body, jpaHeaders);
+        return message;
+    }
+    
+    @Override
+    protected Message copyMessage(StoreMailbox toMailbox, Message originalMessage, long uid) {
+        Message newRow = new JPAMessage(toMailbox.getMailboxId(), uid, (JPAMessage) originalMessage);
+        return newRow;
+    }
+    
+    @Override
+    protected Header createHeader(int lineNumber, String name, String value) {
+        final Header header = new JPAHeader(lineNumber, name, value);
+        return header;
+    }    
+}

Added: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java?rev=732419&view=auto
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java (added)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java Wed Jan  7 10:33:39 2009
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.EntityManagerFactory;
+
+import org.apache.james.imap.jpa.mail.JPAMailboxMapper;
+import org.apache.james.imap.jpa.mail.map.openjpa.OpenJPAMailboxMapper;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.store.Authenticator;
+import org.apache.james.imap.store.StoreMailbox;
+import org.apache.james.imap.store.StoreMailboxManager;
+import org.apache.james.imap.store.Subscriber;
+import org.apache.james.imap.store.mail.MailboxMapper;
+import org.apache.james.imap.store.mail.model.Mailbox;
+
+public class JPAMailboxManager extends StoreMailboxManager {
+
+    private final EntityManagerFactory entityManagerFactory;
+
+    public JPAMailboxManager(final Authenticator authenticator, final Subscriber subscriber, 
+            final EntityManagerFactory entityManagerFactory) {
+        super(authenticator, subscriber);
+        this.entityManagerFactory = entityManagerFactory;
+    }
+    
+    @Override
+    protected MailboxMapper createMailboxMapper() {
+        final JPAMailboxMapper mapper = new OpenJPAMailboxMapper(entityManagerFactory.createEntityManager());
+        return mapper;
+    }
+
+    @Override
+    protected StoreMailbox createMailbox(Mailbox mailboxRow) {
+        StoreMailbox result;
+        result = new JPAMailbox(mailboxRow, getLog(), entityManagerFactory);
+        return result;
+    }
+    
+    @Override
+    protected void doCreate(String namespaceName) throws MailboxException {
+        Mailbox mailbox = new org.apache.james.imap.jpa.mail.model.JPAMailbox(namespaceName, Math.abs(random.nextInt()));
+        final MailboxMapper mapper = createMailboxMapper();
+        mapper.begin();
+        mapper.save(mailbox);
+        mapper.commit();
+    }
+}

Added: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java?rev=732419&view=auto
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java (added)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPASubscriptionManager.java Wed Jan  7 10:33:39 2009
@@ -0,0 +1,46 @@
+/****************************************************************
+ * 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.EntityManagerFactory;
+
+import org.apache.james.imap.jpa.user.JPASubscriptionMapper;
+import org.apache.james.imap.jpa.user.model.JPASubscription;
+import org.apache.james.imap.store.StoreSubscriptionManager;
+import org.apache.james.imap.store.user.SubscriptionMapper;
+import org.apache.james.imap.store.user.model.Subscription;
+
+public class JPASubscriptionManager extends StoreSubscriptionManager {
+    private final EntityManagerFactory factory;
+    
+    public JPASubscriptionManager(final EntityManagerFactory factory) {
+        super();
+        this.factory = factory;
+    }
+
+    protected SubscriptionMapper createMapper() {
+        final JPASubscriptionMapper mapper = new JPASubscriptionMapper(factory.createEntityManager());
+        return mapper;
+    }
+    
+    protected Subscription createSubscription(final String user, final String mailbox) {
+        final Subscription newSubscription = new JPASubscription(user, mailbox);
+        return newSubscription;
+    }
+}

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailbox.java?rev=732419&r1=732418&r2=732419&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailbox.java (original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailbox.java Wed Jan  7 10:33:39 2009
@@ -32,15 +32,9 @@
 import javax.mail.Flags;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
-import javax.persistence.EntityManagerFactory;
 
 import org.apache.commons.logging.Log;
 import org.apache.james.api.imap.AbstractLogEnabled;
-import org.apache.james.imap.jpa.mail.JPAMailboxMapper;
-import org.apache.james.imap.jpa.mail.JPAMessageMapper;
-import org.apache.james.imap.jpa.mail.map.openjpa.OpenJPAMailboxMapper;
-import org.apache.james.imap.jpa.mail.model.JPAHeader;
-import org.apache.james.imap.jpa.mail.model.JPAMessage;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxListener;
 import org.apache.james.imap.mailbox.MailboxNotFoundException;
@@ -54,27 +48,37 @@
 import org.apache.james.imap.mailbox.util.UidRange;
 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.Message;
 
-public class StoreMailbox extends AbstractLogEnabled implements org.apache.james.imap.mailbox.Mailbox {
+public abstract class StoreMailbox extends AbstractLogEnabled implements org.apache.james.imap.mailbox.Mailbox {
 
     private static final int INITIAL_SIZE_HEADERS = 32;
 
-    private long mailboxId;
+    protected final long mailboxId;
 
     private final UidChangeTracker tracker;
 
     private final MessageSearches searches;
 
-    private final EntityManagerFactory entityManagerFactory;
-
-    StoreMailbox(final Mailbox mailbox, final Log log, final EntityManagerFactory entityManagerfactory) {
+    public StoreMailbox(final Mailbox mailbox, final Log log) {
         this.searches = new MessageSearches();
         setLog(log);
         this.mailboxId = mailbox.getMailboxId();
         this.tracker = new UidChangeTracker(mailbox.getLastUid());
-        this.entityManagerFactory = entityManagerfactory;
+    }
+
+    protected abstract Message copyMessage(StoreMailbox toMailbox, Message originalMessage, long uid);
+    
+    protected abstract MessageMapper createMessageMapper();
+    
+    protected abstract Mailbox getMailboxRow() throws MailboxException;
+
+    protected abstract MailboxMapper createMailboxMapper();
+    
+    public long getMailboxId() {
+        return mailboxId;
     }
 
     public int getMessageCount(MailboxSession mailboxSession) throws MailboxException {
@@ -103,8 +107,8 @@
                 final int size = size(mimeMessage);
                 final byte[] body = body(mimeMessage);
                 final Flags flags = mimeMessage.getFlags();
-                final List<JPAHeader> headers = headers(mailboxId, uid, mimeMessage);
-                final JPAMessage message = new JPAMessage(mailboxId, uid, internalDate, size, flags, body, headers);
+                final List<Header> headers = headers(mailboxId, uid, mimeMessage);
+                final Message message = createMessage(internalDate, uid, size, body, flags, headers);
                 final MessageMapper mapper = createMessageMapper();
 
                 mapper.begin();
@@ -123,10 +127,8 @@
         }
     }
 
-    private MessageMapper createMessageMapper() {
-        final MessageMapper mapper = new JPAMessageMapper(entityManagerFactory.createEntityManager());
-        return mapper;
-    }
+    protected abstract Message createMessage(Date internalDate, final long uid, final int size, final byte[] body, 
+            final Flags flags, final List<Header> headers);
 
     private byte[] body(MimeMessage message) throws IOException, MessagingException {
         InputStream is = message.getInputStream();
@@ -134,19 +136,21 @@
         return bytes;
     }
 
-    private List<JPAHeader> headers(long mailboxId, long uid, MimeMessage message) throws MessagingException {
-        final List<JPAHeader> results = new ArrayList<JPAHeader>(INITIAL_SIZE_HEADERS);
+    private List<Header> headers(long mailboxId, long uid, MimeMessage message) throws MessagingException {
+        final List<Header> results = new ArrayList<Header>(INITIAL_SIZE_HEADERS);
         int lineNumber = 0;
         for (Enumeration lines = message.getAllHeaderLines(); lines.hasMoreElements();) {
             String line = (String) lines.nextElement();
             int colon = line.indexOf(": ");
             if (colon > 0) {
-                final JPAHeader header = new JPAHeader(++lineNumber, line.substring(0, colon), line.substring(colon + 2));
+                final Header header = createHeader(++lineNumber, line.substring(0, colon), line.substring(colon + 2));
                 results.add(header);
             }
         }
         return results;
     }
+    
+    protected abstract Header createHeader(int lineNumber, String name, String value);
 
     private int size(MimeMessage message) throws IOException, MessagingException {
         // TODO very ugly size mesurement
@@ -354,16 +358,6 @@
         return tracker;
     }
 
-    private Mailbox getMailboxRow() throws MailboxException {
-        final MailboxMapper mapper = createMailboxMapper();
-        return mapper.findMailboxById(mailboxId);
-    }
-
-    private MailboxMapper createMailboxMapper() {
-        final JPAMailboxMapper mapper = new OpenJPAMailboxMapper(entityManagerFactory.createEntityManager());
-        return mapper;
-    }
-
     public Iterator search(SearchQuery query, FetchGroup fetchGroup,
             MailboxSession mailboxSession) throws MailboxException {
         final MessageMapper messageMapper = createMessageMapper();
@@ -416,7 +410,7 @@
                     // mail 4 is big and comes over a slow connection.
                     long uid = mailbox.getLastUid();
 
-                    Message newRow = new JPAMessage(toMailbox.mailboxId, uid, (JPAMessage) originalMessage);
+                    Message newRow = copyMessage(toMailbox, originalMessage, uid);
 
 
                     mapper.save(newRow);
@@ -434,7 +428,7 @@
             throw new MailboxException(e);
         }
     }
-
+    
     public void deleted(MailboxSession session) {
         tracker.mailboxDeleted(session.getSessionId());
     }

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java?rev=732419&r1=732418&r2=732419&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java (original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java Wed Jan  7 10:33:39 2009
@@ -27,13 +27,8 @@
 import java.util.Map;
 import java.util.Random;
 
-import javax.persistence.EntityManagerFactory;
-
 import org.apache.commons.logging.Log;
 import org.apache.james.api.imap.AbstractLogEnabled;
-import org.apache.james.imap.jpa.mail.JPAMailboxMapper;
-import org.apache.james.imap.jpa.mail.map.openjpa.OpenJPAMailboxMapper;
-import org.apache.james.imap.jpa.mail.model.JPAMailbox;
 import org.apache.james.imap.mailbox.ListResult;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxExistsException;
@@ -48,25 +43,29 @@
 import org.apache.james.imap.store.mail.MailboxMapper;
 import org.apache.james.imap.store.mail.model.Mailbox;
 
-public class StoreMailboxManager extends AbstractLogEnabled implements MailboxManager {
+public abstract class StoreMailboxManager extends AbstractLogEnabled implements MailboxManager {
 
     private static final char SQL_WILDCARD_CHAR = '%';
 
-    private final static Random random = new Random();
+    protected final static Random random = new Random();
 
     private final Map<String, StoreMailbox> mailboxes;
 
     private final Authenticator authenticator;    
-    private final Subscriber subscriber;
-    private final EntityManagerFactory entityManagerFactory;
+    private final Subscriber subscriber;    
 
-    public StoreMailboxManager(final Authenticator authenticator, final Subscriber subscriber, final EntityManagerFactory entityManagerFactory) {
+    public StoreMailboxManager(final Authenticator authenticator, final Subscriber subscriber) {
         mailboxes = new HashMap<String, StoreMailbox>();
         this.authenticator = authenticator;
         this.subscriber = subscriber;
-        this.entityManagerFactory = entityManagerFactory;
     }
 
+    protected abstract StoreMailbox createMailbox(Mailbox mailboxRow);
+    
+    protected abstract MailboxMapper createMailboxMapper();
+    
+    protected abstract void doCreate(String namespaceName) throws MailboxException;
+    
     public org.apache.james.imap.mailbox.Mailbox getMailbox(String mailboxName)
     throws MailboxException {
         return doGetMailbox(mailboxName);
@@ -86,7 +85,7 @@
 
                 StoreMailbox result = (StoreMailbox) mailboxes.get(mailboxName);
                 if (result == null) {
-                    result = new StoreMailbox(mailboxRow, getLog(), entityManagerFactory);
+                    result = createMailbox(mailboxRow);
                     mailboxes.put(mailboxName, result);
                 }
                 return result;
@@ -132,14 +131,6 @@
         }
     }
 
-    private void doCreate(String namespaceName) throws MailboxException {
-        JPAMailbox mailbox = new JPAMailbox(namespaceName, Math.abs(random.nextInt()));
-        final MailboxMapper mapper = createMailboxMapper();
-        mapper.begin();
-        mapper.save(mailbox);
-        mapper.commit();
-    }
-
     public void deleteMailbox(String mailboxName, MailboxSession session)
     throws MailboxException {
         getLog().info("deleteMailbox " + mailboxName);
@@ -280,11 +271,6 @@
         mailboxes.clear();
     }
 
-    private MailboxMapper createMailboxMapper() {
-        final JPAMailboxMapper mapper = new OpenJPAMailboxMapper(entityManagerFactory.createEntityManager());
-        return mapper;
-    }
-
     public MailboxSession createSession() {
         return new SimpleMailboxSession(random.nextLong());
     }

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java?rev=732419&r1=732418&r2=732419&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java (original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/store/StoreSubscriptionManager.java Wed Jan  7 10:33:39 2009
@@ -22,10 +22,6 @@
 import java.util.HashSet;
 import java.util.List;
 
-import javax.persistence.EntityManagerFactory;
-
-import org.apache.james.imap.jpa.user.JPASubscriptionMapper;
-import org.apache.james.imap.jpa.user.model.JPASubscription;
 import org.apache.james.imap.mailbox.SubscriptionException;
 import org.apache.james.imap.store.user.SubscriptionMapper;
 import org.apache.james.imap.store.user.model.Subscription;
@@ -33,16 +29,16 @@
 /**
  * Manages subscriptions.
  */
-public class StoreSubscriptionManager implements Subscriber {
+public abstract class StoreSubscriptionManager implements Subscriber {
 
     private static final int INITIAL_SIZE = 32;
-    private final EntityManagerFactory factory;
-
-    public StoreSubscriptionManager(final EntityManagerFactory factory) {
+    
+    public StoreSubscriptionManager() {
         super();
-        this.factory = factory;
     }
 
+    protected abstract SubscriptionMapper createMapper();
+    
     public void subscribe(final String user, final String mailbox) throws SubscriptionException {
         final SubscriptionMapper mapper = createMapper();
         mapper.begin();
@@ -55,15 +51,7 @@
         }
     }
 
-    private Subscription createSubscription(final String user, final String mailbox) {
-        final Subscription newSubscription = new JPASubscription(user, mailbox);
-        return newSubscription;
-    }
-
-    private SubscriptionMapper createMapper() {
-        final JPASubscriptionMapper mapper = new JPASubscriptionMapper(factory.createEntityManager());
-        return mapper;
-    }
+    protected abstract Subscription createSubscription(final String user, final String mailbox);
 
     public Collection<String> subscriptions(final String user) throws SubscriptionException {
         final SubscriptionMapper mapper = createMapper();



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