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 [2/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
Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java Fri Jun  4 13:07:05 2010
@@ -20,7 +20,7 @@ package org.apache.james.imap.jpa.mail;
 
 import java.util.List;
 
-import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
 import javax.persistence.PersistenceException;
 
 import org.apache.james.imap.api.display.HumanReadableText;
@@ -40,18 +40,15 @@ import org.apache.james.imap.store.mail.
  *
  */
 public class JPAMessageMapper extends JPATransactionalMapper implements MessageMapper<Long> {
-
-    private final long mailboxId;
     
-    public JPAMessageMapper(final EntityManager factory, final long mailboxId) {
-        super(factory);
-        this.mailboxId = mailboxId;
+    public JPAMessageMapper(final EntityManagerFactory entityManagerFactory) {
+        super(entityManagerFactory);
     }
 
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#findInMailbox(org.apache.james.imap.mailbox.MessageRange)
      */
-    public List<MailboxMembership<Long>> findInMailbox(MessageRange set) throws StorageException {
+    public List<MailboxMembership<Long>> findInMailbox(Long mailboxId, MessageRange set) throws StorageException {
         try {
             final List<MailboxMembership<Long>> results;
             final long from = set.getUidFrom();
@@ -79,36 +76,36 @@ public class JPAMessageMapper extends JP
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findMessagesInMailboxAfterUID(long mailboxId, long uid) {
-        return getManager().createNamedQuery("findMessagesInMailboxAfterUID")
+    private List<MailboxMembership<Long>> findMessagesInMailboxAfterUID(Long mailboxId, long uid) {
+        return getEntityManager().createNamedQuery("findMessagesInMailboxAfterUID")
         .setParameter("idParam", mailboxId)
         .setParameter("uidParam", uid).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findMessagesInMailboxWithUID(long mailboxId, long uid) {
-        return getManager().createNamedQuery("findMessagesInMailboxWithUID")
+    private List<MailboxMembership<Long>> findMessagesInMailboxWithUID(Long mailboxId, long uid) {
+        return getEntityManager().createNamedQuery("findMessagesInMailboxWithUID")
         .setParameter("idParam", mailboxId)
         .setParameter("uidParam", uid).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findMessagesInMailboxBetweenUIDs(long mailboxId, long from, long to) {
-        return getManager().createNamedQuery("findMessagesInMailboxBetweenUIDs")
+    private List<MailboxMembership<Long>> findMessagesInMailboxBetweenUIDs(Long mailboxId, long from, long to) {
+        return getEntityManager().createNamedQuery("findMessagesInMailboxBetweenUIDs")
         .setParameter("idParam", mailboxId)
         .setParameter("fromParam", from)
         .setParameter("toParam", to).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findMessagesInMailbox(long mailboxId) {
-        return getManager().createNamedQuery("findMessagesInMailbox").setParameter("idParam", mailboxId).getResultList();
+    private List<MailboxMembership<Long>> findMessagesInMailbox(Long mailboxId) {
+        return getEntityManager().createNamedQuery("findMessagesInMailbox").setParameter("idParam", mailboxId).getResultList();
     }
 
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#findMarkedForDeletionInMailbox(org.apache.james.imap.mailbox.MessageRange)
      */
-    public List<MailboxMembership<Long>> findMarkedForDeletionInMailbox(final MessageRange set) throws StorageException {
+    public List<MailboxMembership<Long>> findMarkedForDeletionInMailbox(Long mailboxId, final MessageRange set) throws StorageException {
         try {
             final List<MailboxMembership<Long>> results;
             final long from = set.getUidFrom();
@@ -135,27 +132,27 @@ public class JPAMessageMapper extends JP
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findDeletedMessagesInMailbox(long mailboxId) {
-        return getManager().createNamedQuery("findDeletedMessagesInMailbox").setParameter("idParam", mailboxId).getResultList();
+    private List<MailboxMembership<Long>> findDeletedMessagesInMailbox(Long mailboxId) {
+        return getEntityManager().createNamedQuery("findDeletedMessagesInMailbox").setParameter("idParam", mailboxId).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxAfterUID(long mailboxId, long uid) {
-        return getManager().createNamedQuery("findDeletedMessagesInMailboxAfterUID")
+    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxAfterUID(Long mailboxId, long uid) {
+        return getEntityManager().createNamedQuery("findDeletedMessagesInMailboxAfterUID")
         .setParameter("idParam", mailboxId)
         .setParameter("uidParam", uid).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxWithUID(long mailboxId, long uid) {
-        return getManager().createNamedQuery("findDeletedMessagesInMailboxWithUID")
+    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxWithUID(Long mailboxId, long uid) {
+        return getEntityManager().createNamedQuery("findDeletedMessagesInMailboxWithUID")
         .setParameter("idParam", mailboxId)
         .setParameter("uidParam", uid).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxBetweenUIDs(long mailboxId, long from, long to) {
-        return getManager().createNamedQuery("findDeletedMessagesInMailboxBetweenUIDs")
+    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxBetweenUIDs(Long mailboxId, long from, long to) {
+        return getEntityManager().createNamedQuery("findDeletedMessagesInMailboxBetweenUIDs")
         .setParameter("idParam", mailboxId)
         .setParameter("fromParam", from)
         .setParameter("toParam", to).getResultList();
@@ -164,9 +161,9 @@ public class JPAMessageMapper extends JP
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#countMessagesInMailbox()
      */
-    public long countMessagesInMailbox() throws StorageException {
+    public long countMessagesInMailbox(Long mailboxId) throws StorageException {
         try {
-            return (Long) getManager().createNamedQuery("countMessagesInMailbox").setParameter("idParam", mailboxId).getSingleResult();
+            return (Long) getEntityManager().createNamedQuery("countMessagesInMailbox").setParameter("idParam", mailboxId).getSingleResult();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.COUNT_FAILED, e);
         }
@@ -175,9 +172,9 @@ public class JPAMessageMapper extends JP
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#countUnseenMessagesInMailbox()
      */
-    public long countUnseenMessagesInMailbox() throws StorageException {
+    public long countUnseenMessagesInMailbox(Long mailboxId) throws StorageException {
         try {
-            return (Long) getManager().createNamedQuery("countUnseenMessagesInMailbox").setParameter("idParam", mailboxId).getSingleResult();
+            return (Long) getEntityManager().createNamedQuery("countUnseenMessagesInMailbox").setParameter("idParam", mailboxId).getSingleResult();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.COUNT_FAILED, e);
         }
@@ -187,16 +184,16 @@ public class JPAMessageMapper extends JP
      * @see org.apache.james.imap.store.mail.MessageMapper#searchMailbox(org.apache.james.imap.mailbox.SearchQuery)
      */
     @SuppressWarnings("unchecked")
-    public List<MailboxMembership<Long>> searchMailbox(SearchQuery query) throws StorageException {
+    public List<MailboxMembership<Long>> searchMailbox(Long mailboxId, SearchQuery query) throws StorageException {
         try {
             final String jql = formulateJQL(mailboxId, query);
-            return getManager().createQuery(jql).getResultList();
+            return getEntityManager().createQuery(jql).getResultList();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
         }
     }
 
-    private String formulateJQL(long mailboxId, SearchQuery query) {
+    private String formulateJQL(Long mailboxId, SearchQuery query) {
         final StringBuilder queryBuilder = new StringBuilder(50);
         queryBuilder.append("SELECT membership FROM Membership membership WHERE membership.mailboxId = ").append(mailboxId);
         final List<Criterion> criteria = query.getCriterias();
@@ -223,12 +220,13 @@ public class JPAMessageMapper extends JP
         return jql;
     }
 
-    /**
-     * @see org.apache.james.imap.store.mail.MessageMapper#delete(MailboxMembership)
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#delete(java.lang.Object, org.apache.james.imap.store.mail.model.MailboxMembership)
      */
-    public void delete(MailboxMembership<Long> message) throws StorageException {
+    public void delete(Long uid, MailboxMembership<Long> message) throws StorageException {
         try {
-            getManager().remove(message);
+            getEntityManager().remove(message);
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.DELETED_FAILED, e);
         }
@@ -239,9 +237,9 @@ public class JPAMessageMapper extends JP
      * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
      */
     @SuppressWarnings("unchecked")
-    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox()  throws StorageException {
+    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox(Long mailboxId)  throws StorageException {
         try {
-            return getManager().createNamedQuery("findUnseenMessagesInMailboxOrderByUid").setParameter("idParam", mailboxId).getResultList();
+            return getEntityManager().createNamedQuery("findUnseenMessagesInMailboxOrderByUid").setParameter("idParam", mailboxId).getResultList();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
         }
@@ -251,9 +249,9 @@ public class JPAMessageMapper extends JP
      * @see org.apache.james.imap.store.mail.MessageMapper#findRecentMessagesInMailbox()
      */
     @SuppressWarnings("unchecked")
-    public List<MailboxMembership<Long>> findRecentMessagesInMailbox() throws StorageException {
+    public List<MailboxMembership<Long>> findRecentMessagesInMailbox(Long mailboxId) throws StorageException {
         try {
-            return getManager().createNamedQuery("findRecentMessagesInMailbox").setParameter("idParam", mailboxId).getResultList();
+            return getEntityManager().createNamedQuery("findRecentMessagesInMailbox").setParameter("idParam", mailboxId).getResultList();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
         }
@@ -262,9 +260,9 @@ public class JPAMessageMapper extends JP
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#save(MailboxMembership)
      */
-    public void save(MailboxMembership<Long> message) throws StorageException {
+    public void save(Long mailboxId, MailboxMembership<Long> message) throws StorageException {
         try {
-            getManager().persist(message);
+            getEntityManager().persist(message);
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.SAVE_FAILED, e);
         }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java Fri Jun  4 13:07:05 2010
@@ -29,9 +29,9 @@ import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Lob;
 
-import org.apache.james.imap.store.StreamUtils;
 import org.apache.james.imap.store.mail.model.Document;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
+import org.apache.james.imap.store.streaming.StreamUtils;
 
 @Entity(name="Message")
 public class JPAMessage extends AbstractJPAMessage{

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java Fri Jun  4 13:07:05 2010
@@ -31,9 +31,9 @@ import javax.persistence.FetchType;
 import org.apache.james.imap.jpa.mail.model.AbstractJPAMessage;
 import org.apache.james.imap.jpa.mail.model.JPAHeader;
 import org.apache.james.imap.jpa.mail.model.JPAMessage;
-import org.apache.james.imap.store.StreamUtils;
 import org.apache.james.imap.store.mail.model.Document;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
+import org.apache.james.imap.store.streaming.StreamUtils;
 import org.apache.openjpa.persistence.Persistent;
 
 /**

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java Fri Jun  4 13:07:05 2010
@@ -21,7 +21,8 @@ package org.apache.james.imap.jpa.openjp
 
 
 import org.apache.james.imap.jpa.JPAMailboxManager;
-import org.apache.james.imap.jpa.MailboxSessionEntityManagerFactory;
+import org.apache.james.imap.jpa.JPAMailboxSessionMapperFactory;
+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;
@@ -38,17 +39,18 @@ public class OpenJPAMailboxManager exten
 
     private boolean useStreaming;
 
-    public OpenJPAMailboxManager(Authenticator authenticator, Subscriber subscriber, MailboxSessionEntityManagerFactory entityManagerFactory, boolean useStreaming) {
-        super(authenticator, subscriber, entityManagerFactory);
+    public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, Subscriber subscriber, boolean useStreaming) {
+        super(mapperFactory, authenticator, subscriber);
         this.useStreaming = useStreaming;
     }
 
-    public OpenJPAMailboxManager(Authenticator authenticator, Subscriber subscriber, MailboxSessionEntityManagerFactory entityManagerFactory) {
-        this(authenticator, subscriber, entityManagerFactory, false);
+    public OpenJPAMailboxManager(JPAMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, Subscriber subscriber) {
+        this(mapperFactory, authenticator, subscriber, false);
     }
 
-    protected StoreMessageManager<Long> createMailbox(MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer, Mailbox<Long> mailboxRow, MailboxSession session) {
-        StoreMessageManager<Long> result =  new OpenJPAMessageManager(dispatcher, consumer, mailboxRow,entityManagerFactory, useStreaming);
+    @Override
+    protected StoreMessageManager<Long> createMessageManager(MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer, Mailbox<Long> mailboxRow, MailboxSession session) throws MailboxException {
+        StoreMessageManager<Long> result =  new OpenJPAMessageManager((JPAMailboxSessionMapperFactory) mailboxSessionMapperFactory, dispatcher, consumer, mailboxRow, session, useStreaming);
         return result;
     }
 }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMessageManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMessageManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMessageManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMessageManager.java Fri Jun  4 13:07:05 2010
@@ -26,8 +26,8 @@ import java.util.List;
 
 import javax.mail.Flags;
 
+import org.apache.james.imap.jpa.JPAMailboxSessionMapperFactory;
 import org.apache.james.imap.jpa.JPAMessageManager;
-import org.apache.james.imap.jpa.MailboxSessionEntityManagerFactory;
 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.openjpa.JPAStreamingMailboxMembership;
@@ -44,16 +44,20 @@ import org.apache.james.imap.store.mail.
  * OpenJPA implementation of Mailbox
  *
  */
-public class OpenJPAMessageManager extends JPAMessageManager{
+public class OpenJPAMessageManager extends JPAMessageManager {
 
     private final boolean useStreaming;
 
-    public OpenJPAMessageManager(MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer, Mailbox<Long> mailbox, MailboxSessionEntityManagerFactory entityManagerFactory) {
-        this(dispatcher, consumer, mailbox, entityManagerFactory, false);
+    public OpenJPAMessageManager(JPAMailboxSessionMapperFactory mapperFactory,
+            MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer,
+            Mailbox<Long> mailbox, MailboxSession session) throws MailboxException {
+        this(mapperFactory, dispatcher, consumer, mailbox, session, false);
     }
 
-    public OpenJPAMessageManager(MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer, Mailbox<Long> mailbox, MailboxSessionEntityManagerFactory entityManagerFactory, final boolean useStreaming) {
-        super(dispatcher, consumer, mailbox, entityManagerFactory);
+    public OpenJPAMessageManager(JPAMailboxSessionMapperFactory mapperFactory,
+            MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer,
+            Mailbox<Long> mailbox, MailboxSession session, final boolean useStreaming) throws MailboxException {
+        super(mapperFactory, dispatcher, consumer, mailbox, session);
         this.useStreaming = useStreaming;
     }
 
@@ -78,6 +82,5 @@ public class OpenJPAMessageManager exten
             return super.createMessage(internalDate, uid, size, bodyStartOctet, document, flags, headers, propertyBuilder);
         }
     }
-    
 
-}
+}
\ No newline at end of file

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/user/JPASubscriptionMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/user/JPASubscriptionMapper.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/user/JPASubscriptionMapper.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/user/JPASubscriptionMapper.java Fri Jun  4 13:07:05 2010
@@ -20,7 +20,7 @@ package org.apache.james.imap.jpa.user;
 
 import java.util.List;
 
-import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
 import javax.persistence.NoResultException;
 import javax.persistence.PersistenceException;
 
@@ -35,18 +35,17 @@ import org.apache.james.imap.store.user.
  */
 public class JPASubscriptionMapper extends JPATransactionalMapper implements SubscriptionMapper {
 
-    public JPASubscriptionMapper(final EntityManager factory) {
-        super(factory);
+    public JPASubscriptionMapper(final EntityManagerFactory entityManagerFactory) {
+        super(entityManagerFactory);
     }
 
-
     /**
      * @throws SubscriptionException 
      * @see org.apache.james.imap.store.user.SubscriptionMapper#findFindMailboxSubscriptionForUser(java.lang.String, java.lang.String)
      */
     public Subscription findFindMailboxSubscriptionForUser(final String user, final String mailbox) throws SubscriptionException {
         try {
-            return (Subscription) getManager().createNamedQuery("findFindMailboxSubscriptionForUser")
+            return (Subscription) getEntityManager().createNamedQuery("findFindMailboxSubscriptionForUser")
             .setParameter("userParam", user).setParameter("mailboxParam", mailbox).getSingleResult();
         } catch (NoResultException e) {
             return null;
@@ -61,7 +60,7 @@ public class JPASubscriptionMapper exten
      */
     public void save(Subscription subscription) throws SubscriptionException {
         try {
-            getManager().persist(subscription);
+            getEntityManager().persist(subscription);
         } catch (PersistenceException e) {
             throw new SubscriptionException(HumanReadableText.SAVE_FAILED, e);
         }
@@ -74,7 +73,7 @@ public class JPASubscriptionMapper exten
     @SuppressWarnings("unchecked")
     public List<Subscription> findSubscriptionsForUser(String user) throws SubscriptionException {
         try {
-            return (List<Subscription>) getManager().createNamedQuery("findSubscriptionsForUser").setParameter("userParam", user).getResultList();
+            return (List<Subscription>) getEntityManager().createNamedQuery("findSubscriptionsForUser").setParameter("userParam", user).getResultList();
         } catch (PersistenceException e) {
             throw new SubscriptionException(HumanReadableText.SEARCH_FAILED, e);
         }
@@ -86,7 +85,7 @@ public class JPASubscriptionMapper exten
      */
     public void delete(Subscription subscription) throws SubscriptionException {
         try {
-            getManager().remove(subscription);
+            getEntityManager().remove(subscription);
         } catch (PersistenceException e) {
             throw new SubscriptionException(HumanReadableText.DELETED_FAILED, e);
         }

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxManager.java Fri Jun  4 13:07:05 2010
@@ -19,182 +19,45 @@
 
 package org.apache.james.imap.inmemory;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
+import org.apache.james.imap.inmemory.mail.model.InMemoryMailbox;
 import org.apache.james.imap.mailbox.MailboxException;
-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.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.Authenticator;
-import org.apache.james.imap.store.StoreMessageManager;
+import org.apache.james.imap.store.MailboxSessionMapperFactory;
 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;
 
-public class InMemoryMailboxManager extends StoreMailboxManager<Long> implements MailboxMapper<Long>{
-
-    private static final int INITIAL_SIZE = 128;
-    private Map<Long, InMemoryMailbox> mailboxesById;
-    private Map<String, InMemoryStoreMessageManager> storeMailboxByName;
-    private Map<Long, String> idNameMap;
-    private MailboxSession session;
+public class InMemoryMailboxManager extends StoreMailboxManager<Long> {
 
-    public InMemoryMailboxManager(Authenticator authenticator, Subscriber subscriber) {
-        super(authenticator, subscriber, new UidConsumer<Long>() {
+    public InMemoryMailboxManager(MailboxSessionMapperFactory<Long> mapperFactory, Authenticator authenticator, Subscriber subscriber) {
+        super(mapperFactory, authenticator, subscriber, new UidConsumer<Long>() {
 
             public long reserveNextUid(Mailbox<Long> mailbox, MailboxSession session) throws MailboxException {
                 mailbox.consumeUid();
                 return mailbox.getLastUid();
             }
         });
-        mailboxesById = new ConcurrentHashMap<Long, InMemoryMailbox>(INITIAL_SIZE);
-        storeMailboxByName = new ConcurrentHashMap<String, InMemoryStoreMessageManager>(INITIAL_SIZE);
-        idNameMap = new ConcurrentHashMap<Long, String>(INITIAL_SIZE);
     }
 
     @Override
-    protected StoreMessageManager<Long> createMailbox(MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer, Mailbox<Long> mailboxRow, MailboxSession session) {
-        InMemoryStoreMessageManager storeMailbox = storeMailboxByName.get(mailboxRow.getName());
-        if (storeMailbox == null) {
-            storeMailbox = new InMemoryStoreMessageManager(dispatcher, consumer, (InMemoryMailbox)mailboxRow);
-            storeMailboxByName.put(mailboxRow.getName(), storeMailbox);
-        }
-        
-        return storeMailbox;
+    protected StoreMessageManager<Long> createMessageManager(MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer, Mailbox<Long> mailboxRow, MailboxSession session) throws MailboxException {
+        return new InMemoryStoreMessageManager(mailboxSessionMapperFactory, dispatcher, consumer, (InMemoryMailbox)mailboxRow, session);
     }
 
     @Override
-    protected MailboxMapper<Long> createMailboxMapper(MailboxSession session) {
-        this.session = session;
-        return this;
-    }
-
-    @Override
-    protected void doCreate(String namespaceName, MailboxSession session) throws StorageException {
+    protected void doCreateMailbox(String namespaceName, MailboxSession session) throws StorageException {
         InMemoryMailbox mailbox = new InMemoryMailbox(randomId(), namespaceName, randomUidValidity());
-        idNameMap.put(mailbox.getMailboxId(), mailbox.getName());
-        save(mailbox);
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MailboxMapper#countMailboxesWithName(java.lang.String)
-     */
-    public long countMailboxesWithName(String name) throws StorageException {
-        int total = 0;
-        for (final InMemoryMailbox mailbox:mailboxesById.values()) {
-            if (mailbox.getName().equals(name)) {
-                total++;
-            }
+        try {
+            mailboxSessionMapperFactory.getMailboxMapper(session).save(mailbox);
+        } catch (MailboxException e) {
         }
-        return total;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MailboxMapper#delete(org.apache.james.imap.store.mail.model.Mailbox)
-     */
-    public void delete(Mailbox<Long> mailbox) throws StorageException {
-        mailboxesById.remove(mailbox.getMailboxId());
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MailboxMapper#deleteAll()
-     */
-    public void deleteAll() throws StorageException {
-        mailboxesById.clear();
-    }
-
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MailboxMapper#findMailboxById(java.lang.Object)
-     */
-    public Mailbox<Long> findMailboxById(Long mailboxId) throws StorageException, MailboxNotFoundException {
-        return mailboxesById.get(mailboxesById);
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MailboxMapper#findMailboxByName(java.lang.String)
-     */
-    public synchronized Mailbox<Long> findMailboxByName(String name) throws StorageException, MailboxNotFoundException {
-        Mailbox<Long> result = null;
-        for (final InMemoryMailbox mailbox:mailboxesById.values()) {
-            if (mailbox.getName().equals(name)) {
-                result = mailbox;
-                break;
-            }
-        }
-        return result;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MailboxMapper#findMailboxWithNameLike(java.lang.String)
-     */
-    public List<Mailbox<Long>> findMailboxWithNameLike(String name) throws StorageException {
-        final String regex = name.replace("%", ".*");
-        List<Mailbox<Long>> results = new ArrayList<Mailbox<Long>>();
-        for (final InMemoryMailbox mailbox:mailboxesById.values()) {
-            if (mailbox.getName().matches(regex)) {
-                results.add(mailbox);
-            }
-        }
-        return results;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MailboxMapper#existsMailboxStartingWith(java.lang.String)
-     */
-    public boolean existsMailboxStartingWith(String mailboxName) throws StorageException {
-        boolean result = false;
-        for (final InMemoryMailbox mailbox:mailboxesById.values()) {
-            if (mailbox.getName().startsWith(mailboxName)) {
-                result = true;
-                break;
-            }
-        }
-        return result;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MailboxMapper#save(org.apache.james.imap.store.mail.model.Mailbox)
-     */
-    public void save(Mailbox<Long> mailbox) throws StorageException {
-        mailboxesById.put(mailbox.getMailboxId(), (InMemoryMailbox) mailbox);
-        String name = idNameMap.remove(mailbox.getMailboxId());
-        if (name != null) {
-            InMemoryStoreMessageManager m = storeMailboxByName.remove(name);
-            if (m!= null) {
-                try {
-                    m.getMailboxEntity(session).setName(mailbox.getName());
-                    storeMailboxByName.put(mailbox.getName(), m);
-                } catch (MailboxException e) {
-                    throw new StorageException(e.getKey(), e);
-                } 
-            }
-        }
-        idNameMap.put(mailbox.getMailboxId(), mailbox.getName());
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.transaction.TransactionalMapper#execute(org.apache.james.imap.store.transaction.TransactionalMapper.Transaction)
-     */
-    public void execute(Transaction transaction) throws MailboxException {
-        transaction.run();
     }
 
     /**
@@ -204,16 +67,7 @@ public class InMemoryMailboxManager exte
      */
 
     public synchronized void deleteEverything() throws MailboxException {
-        final MailboxMapper<Long> mapper = createMailboxMapper(null);
-        mapper.execute(new TransactionalMapper.Transaction() {
-
-            public void run() throws MailboxException {
-                mapper.deleteAll(); 
-            }
-            
-        });
-        storeMailboxByName.clear();
-        idNameMap.clear();
+        ((InMemoryMailboxSessionMapperFactory) mailboxSessionMapperFactory).deleteAll();
     }
 
     public long reserveNextUid(Mailbox<Long> mailbox, MailboxSession session) throws MailboxException {

Added: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java?rev=951398&view=auto
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java (added)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java Fri Jun  4 13:07:05 2010
@@ -0,0 +1,87 @@
+/****************************************************************
+ * 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.inmemory;
+
+import org.apache.james.imap.inmemory.mail.InMemoryMailboxMapper;
+import org.apache.james.imap.inmemory.mail.InMemoryMessageMapper;
+import org.apache.james.imap.inmemory.user.InMemorySubscriptionMapper;
+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.transaction.TransactionalMapper;
+import org.apache.james.imap.store.user.SubscriptionMapper;
+
+public class InMemoryMailboxSessionMapperFactory extends MailboxSessionMapperFactory<Long> {
+
+    private MailboxMapper<Long> mailboxMapper;
+    private MessageMapper<Long> messageMapper;
+    private SubscriptionMapper subscriptionMapper;
+    
+    public InMemoryMailboxSessionMapperFactory() {
+        mailboxMapper = new InMemoryMailboxMapper();
+        messageMapper = new InMemoryMessageMapper();
+        subscriptionMapper = new InMemorySubscriptionMapper();
+    }
+    
+    public MailboxMapper<Long> getMailboxMapper(MailboxSession session) throws MailboxException {
+        return mailboxMapper;
+    }
+    
+    @Override
+    public MailboxMapper<Long> createMailboxMapper(MailboxSession session) throws MailboxException {
+        return null;
+    }
+
+    @Override
+    public MessageMapper<Long> getMessageMapper(MailboxSession session) throws MailboxException {
+        return messageMapper;
+    }
+
+    @Override
+    public MessageMapper<Long> createMessageMapper(MailboxSession session) throws MailboxException {
+        return null;
+    }
+
+    @Override
+    public SubscriptionMapper getSubscriptionMapper(MailboxSession session) throws SubscriptionException {
+        return subscriptionMapper;
+    }
+
+    @Override
+    public SubscriptionMapper createSubscriptionMapper(MailboxSession session) throws SubscriptionException {
+        return null;
+    }
+    
+    public void deleteAll() throws MailboxException {
+        final MailboxMapper<Long> mapper = mailboxMapper;
+        mapper.execute(new TransactionalMapper.Transaction() {
+
+            public void run() throws MailboxException {
+                mapper.deleteAll(); 
+            }
+            
+        });
+        ((InMemoryMessageMapper) messageMapper).deleteAll();
+        ((InMemorySubscriptionMapper) subscriptionMapper).deleteAll();
+    }
+
+}

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMessageManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMessageManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMessageManager.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMessageManager.java Fri Jun  4 13:07:05 2010
@@ -21,44 +21,31 @@ package org.apache.james.imap.inmemory;
 
 import java.io.ByteArrayOutputStream;
 import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Date;
-import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
 
 import javax.mail.Flags;
 
+import org.apache.james.imap.inmemory.mail.model.InMemoryMailbox;
+import org.apache.james.imap.inmemory.mail.model.SimpleHeader;
+import org.apache.james.imap.inmemory.mail.model.SimpleMailboxMembership;
 import org.apache.james.imap.mailbox.MailboxException;
 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;
 import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
-import org.apache.james.imap.store.MailboxMembershipComparator;
+import org.apache.james.imap.store.MailboxSessionMapperFactory;
 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;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
 
-public class InMemoryStoreMessageManager extends StoreMessageManager<Long> implements MessageMapper<Long> {
-    
-    private static final int INITIAL_SIZE = 256;
-    private Map<Long, MailboxMembership<Long>> membershipByUid;
-    private InMemoryMailbox mailbox;
-
-    public InMemoryStoreMessageManager(MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer, InMemoryMailbox mailbox) {
-        super(dispatcher, consumer, mailbox);
-        this.mailbox = mailbox;
-        this.membershipByUid = new ConcurrentHashMap<Long, MailboxMembership<Long>>(INITIAL_SIZE);
+public class InMemoryStoreMessageManager extends StoreMessageManager<Long> {
+
+    public InMemoryStoreMessageManager(MailboxSessionMapperFactory<Long> mapperFactory,
+            MailboxEventDispatcher dispatcher, UidConsumer<Long> consumer, InMemoryMailbox mailbox,
+            MailboxSession session) throws MailboxException {
+        super(mapperFactory, dispatcher, consumer, mailbox, session);
     }
-    
 
     @Override
     protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid, MailboxSession session) {
@@ -90,175 +77,6 @@ public class InMemoryStoreMessageManager
             byteContent = new byte[0];
         }
         return new SimpleMailboxMembership(internalDate, uid, size, bodyStartOctet, byteContent, flags, headers, propertyBuilder, getMailboxId());
-
-
-    }
-
-    @Override
-    protected MessageMapper<Long> createMessageMapper(MailboxSession session) {
-        return this;
-    }
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#countMessagesInMailbox()
-     */
-    public long countMessagesInMailbox() throws StorageException {
-        return membershipByUid.size();
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#countUnseenMessagesInMailbox()
-     */
-    public long countUnseenMessagesInMailbox() throws StorageException {
-        long count = 0;
-        for(MailboxMembership<Long> member:membershipByUid.values()) {
-            if (!member.isSeen()) {
-                count++;
-            }
-        }
-        return count;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#delete(org.apache.james.imap.store.mail.model.MailboxMembership)
-     */
-    public void delete(MailboxMembership<Long> message) throws StorageException {
-        membershipByUid.remove(message.getUid());
-    }
-
-    @SuppressWarnings("unchecked")
-    public List<MailboxMembership<Long>> findInMailbox(MessageRange set) throws StorageException {
-        final List<MailboxMembership<Long>> results;
-        final MessageRange.Type type = set.getType();
-        switch (type) {
-            case ALL:
-                results = new ArrayList<MailboxMembership<Long>>(membershipByUid.values());
-                break;
-            case FROM:
-                results = new ArrayList<MailboxMembership<Long>>(membershipByUid.values());
-                for (final Iterator<MailboxMembership<Long>> it=results.iterator();it.hasNext();) {
-                   if (it.next().getUid()< set.getUidFrom()) {
-                       it.remove(); 
-                   }
-                }
-                break;
-            case RANGE:
-                results = new ArrayList<MailboxMembership<Long>>(membershipByUid.values());
-                for (final Iterator<MailboxMembership<Long>> it=results.iterator();it.hasNext();) {
-                   final long uid = it.next().getUid();
-                if (uid<set.getUidFrom() || uid>set.getUidTo()) {
-                       it.remove(); 
-                   }
-                }
-                break;
-            case ONE:
-                results  = new ArrayList<MailboxMembership<Long>>(1);
-                final MailboxMembership member = membershipByUid.get(set.getUidFrom());
-                if (member != null) {
-                    results.add(member);
-                }
-                break;
-            default:
-                results = new ArrayList<MailboxMembership<Long>>();
-                break;
-        }
-        Collections.sort(results, MailboxMembershipComparator.INSTANCE);
-        return results;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#findMarkedForDeletionInMailbox(org.apache.james.imap.mailbox.MessageRange)
-     */
-    public List<MailboxMembership<Long>> findMarkedForDeletionInMailbox(MessageRange set) throws StorageException {
-        final List<MailboxMembership<Long>> results = findInMailbox(set);
-        for(final Iterator<MailboxMembership<Long>> it=results.iterator();it.hasNext();) {
-            if (!it.next().isDeleted()) {
-                it.remove();
-            }
-        }
-        return results;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#findRecentMessagesInMailbox()
-     */
-    public List<MailboxMembership<Long>> findRecentMessagesInMailbox() throws StorageException {
-        final List<MailboxMembership<Long>> results = new ArrayList<MailboxMembership<Long>>();
-        for(MailboxMembership<Long> member:membershipByUid.values()) {
-            if (member.isRecent()) {
-                results.add(member);
-            }
-        }
-        Collections.sort(results, MailboxMembershipComparator.INSTANCE);
-
-        return results;
     }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
-     */
-    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox() throws StorageException {
-        final List<MailboxMembership<Long>> results = new ArrayList<MailboxMembership<Long>>();
-        for(MailboxMembership<Long> member:membershipByUid.values()) {
-            if (!member.isSeen()) {
-                results.add(member);
-            }
-        }
-        Collections.sort(results, MailboxMembershipComparator.INSTANCE);
-        return results;
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#save(org.apache.james.imap.store.mail.model.MailboxMembership)
-     */
-    public void save(MailboxMembership<Long> message) throws StorageException {
-        membershipByUid.put(message.getUid(), message);
-    }
-
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#searchMailbox(org.apache.james.imap.mailbox.SearchQuery)
-     */
-    public List<MailboxMembership<Long>> searchMailbox(SearchQuery query) throws StorageException {
-        return new ArrayList<MailboxMembership<Long>>(membershipByUid.values());
-    }
-
-
-    /**
-     * There is no really Transaction handling here.. Just run it 
-     */
-    public void execute(Transaction transaction) throws MailboxException {
-        transaction.run();
-    }
-
-
-    public void dispose() {
-        // do nothing
-        
-    }
-    
-    
-    public MessageMapper<Long> getMessageMapperForRequest(MailboxSession session) throws MailboxException {
-        return createMessageMapper(session);
-    }
-
-
-    @Override
-    protected MailboxMapper<Long> createMailboxMapper(MailboxSession session) throws MailboxException {
-        return null;
-    }
-
-
-    @Override
-    protected Mailbox<Long> getMailboxEntity(MailboxSession session) throws MailboxException {
-        return mailbox;
-    }
-
     
 }

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemorySubscriptionManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemorySubscriptionManager.java?rev=951398&r1=951397&r2=951398&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemorySubscriptionManager.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemorySubscriptionManager.java Fri Jun  4 13:07:05 2010
@@ -16,38 +16,23 @@
  * specific language governing permissions and limitations      *
  * under the License.                                           *
  ****************************************************************/
-
 package org.apache.james.imap.inmemory;
 
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
+import org.apache.james.imap.inmemory.user.model.InMemorySubscription;
 import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
-import org.apache.james.imap.mailbox.MailboxSession.User;
+import org.apache.james.imap.store.MailboxSessionMapperFactory;
 import org.apache.james.imap.store.StoreSubscriptionManager;
-import org.apache.james.imap.store.user.SubscriptionMapper;
+import org.apache.james.imap.store.transaction.TransactionalMapper.Transaction;
 import org.apache.james.imap.store.user.model.Subscription;
 
 /**
  * Stores subscriptions in memory.
  */
-public class InMemorySubscriptionManager extends StoreSubscriptionManager implements SubscriptionMapper {
-    
-    private static final int INITIAL_SIZE = 64;
-    private final Map<String, List<Subscription>> subscriptionsByUser;
+public class InMemorySubscriptionManager extends StoreSubscriptionManager<Long> {
     
-    public InMemorySubscriptionManager() {
-        super();
-        subscriptionsByUser = new ConcurrentHashMap<String, List<Subscription>>(INITIAL_SIZE);
-    }
-
-    @Override
-    protected SubscriptionMapper createMapper(MailboxSession session) {
-        return this;
+    public InMemorySubscriptionManager(MailboxSessionMapperFactory<Long> mapperFactory) {
+        super(mapperFactory);
     }
 
     @Override
@@ -55,118 +40,6 @@ public class InMemorySubscriptionManager
         return new InMemorySubscription(mailbox, session.getUser());
     }
 
-    public synchronized void delete(Subscription subscription) {
-        final String user = subscription.getUser();
-        final List<Subscription> subscriptions = subscriptionsByUser.get(user);
-        if (subscriptions != null) {
-            subscriptions.remove(subscription);
-        }
-    }
-
-    public Subscription findFindMailboxSubscriptionForUser(String user, String mailbox) {
-        final List<Subscription> subscriptions = subscriptionsByUser.get(user);
-        Subscription result = null;
-        if (subscriptions != null) {
-            for(Subscription subscription:subscriptions) {
-                if (subscription.getMailbox().equals(mailbox)) {
-                    result = subscription;
-                    break;
-                }
-            }
-        }
-        return result;
-    }
-
-    @SuppressWarnings("unchecked")
-    public List<Subscription> findSubscriptionsForUser(String user) {
-        final List<Subscription> subcriptions = subscriptionsByUser.get(user);
-        final List<Subscription> results;
-        if (subcriptions == null) {
-            results = Collections.EMPTY_LIST;
-        } else {
-            // Make a copy to prevent concurrent modifications
-            results = new ArrayList<Subscription>(subcriptions);
-        }
-        return results;
-    }
-
-    public synchronized void save(Subscription subscription) {
-        final String user = subscription.getUser();
-        final List<Subscription> subscriptions = subscriptionsByUser.get(user);
-        if (subscriptions == null) {
-            final List<Subscription> newSubscriptions  = new ArrayList<Subscription>();
-            newSubscriptions.add(subscription);
-            subscriptionsByUser.put(user, newSubscriptions);
-        } else {
-            subscriptions.add(subscription);
-        }
-    }
-
-    private final static class InMemorySubscription implements Subscription {
-
-        private final String mailbox;
-        private final String user;
-        
-        public InMemorySubscription(final String mailbox, final User user) {
-            super();
-            this.mailbox = mailbox;
-            this.user = user.getUserName();
-        }
-
-        public String getMailbox() {
-            return mailbox;
-        }
-
-        public String getUser() {
-            return user;
-        }
-
-        @Override
-        public int hashCode() {
-            final int PRIME = 31;
-            int result = 1;
-            result = PRIME * result + ((mailbox == null) ? 0 : mailbox.hashCode());
-            result = PRIME * result + ((user == null) ? 0 : user.hashCode());
-            return result;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (this == obj)
-                return true;
-            if (obj == null)
-                return false;
-            if (getClass() != obj.getClass())
-                return false;
-            final InMemorySubscription other = (InMemorySubscription) obj;
-            if (mailbox == null) {
-                if (other.mailbox != null)
-                    return false;
-            } else if (!mailbox.equals(other.mailbox))
-                return false;
-            if (user == null) {
-                if (other.user != null)
-                    return false;
-            } else if (!user.equals(other.user))
-                return false;
-            return true;
-        }
-
-        /**
-         * Representation suitable for logging and debugging.
-         * @return a <code>String</code> representation 
-         * of this object.
-         */
-        public String toString()
-        {
-            return "InMemorySubscription[ "
-                + "mailbox = " + this.mailbox + " "
-                + "user = " + this.user + " "
-                + " ]";
-        }
-        
-    }
-
     /*
      * (non-Javadoc)
      * @see org.apache.james.imap.store.transaction.TransactionalMapper#execute(org.apache.james.imap.store.transaction.TransactionalMapper.Transaction)
@@ -181,6 +54,5 @@ public class InMemorySubscriptionManager
      */
     public void dispose() {
         // do nothing
-        
     }
 }

Added: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java?rev=951398&view=auto
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java (added)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java Fri Jun  4 13:07:05 2010
@@ -0,0 +1,147 @@
+/****************************************************************
+ * 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.inmemory.mail;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.james.imap.inmemory.mail.model.InMemoryMailbox;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxNotFoundException;
+import org.apache.james.imap.mailbox.StorageException;
+import org.apache.james.imap.store.mail.MailboxMapper;
+import org.apache.james.imap.store.mail.model.Mailbox;
+
+public class InMemoryMailboxMapper implements MailboxMapper<Long> {
+    
+    private static final int INITIAL_SIZE = 128;
+    private Map<Long, InMemoryMailbox> mailboxesById;
+
+    public InMemoryMailboxMapper() {
+        mailboxesById = new ConcurrentHashMap<Long, InMemoryMailbox>(INITIAL_SIZE);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MailboxMapper#countMailboxesWithName(java.lang.String)
+     */
+    public long countMailboxesWithName(String name) throws StorageException {
+        int total = 0;
+        for (final InMemoryMailbox mailbox:mailboxesById.values()) {
+            if (mailbox.getName().equals(name)) {
+                total++;
+            }
+        }
+        return total;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MailboxMapper#delete(org.apache.james.imap.store.mail.model.Mailbox)
+     */
+    public void delete(Mailbox<Long> mailbox) throws StorageException {
+        mailboxesById.remove(mailbox.getMailboxId());
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MailboxMapper#deleteAll()
+     */
+    public void deleteAll() throws StorageException {
+        mailboxesById.clear();
+    }
+
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MailboxMapper#findMailboxById(java.lang.Object)
+     */
+    public Mailbox<Long> findMailboxById(Long mailboxId) throws StorageException, MailboxNotFoundException {
+        return mailboxesById.get(mailboxesById);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MailboxMapper#findMailboxByName(java.lang.String)
+     */
+    public synchronized Mailbox<Long> findMailboxByName(String name) throws StorageException, MailboxNotFoundException {
+        Mailbox<Long> result = null;
+        for (final InMemoryMailbox mailbox:mailboxesById.values()) {
+            if (mailbox.getName().equals(name)) {
+                result = mailbox;
+                break;
+            }
+        }
+        return result;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MailboxMapper#findMailboxWithNameLike(java.lang.String)
+     */
+    public List<Mailbox<Long>> findMailboxWithNameLike(String name) throws StorageException {
+        final String regex = name.replace("%", ".*");
+        List<Mailbox<Long>> results = new ArrayList<Mailbox<Long>>();
+        for (final InMemoryMailbox mailbox:mailboxesById.values()) {
+            if (mailbox.getName().matches(regex)) {
+                results.add(mailbox);
+            }
+        }
+        return results;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MailboxMapper#existsMailboxStartingWith(java.lang.String)
+     */
+    public boolean existsMailboxStartingWith(String mailboxName) throws StorageException {
+        boolean result = false;
+        for (final InMemoryMailbox mailbox:mailboxesById.values()) {
+            if (mailbox.getName().startsWith(mailboxName)) {
+                result = true;
+                break;
+            }
+        }
+        return result;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MailboxMapper#save(org.apache.james.imap.store.mail.model.Mailbox)
+     */
+    public void save(Mailbox<Long> mailbox) throws StorageException {
+        mailboxesById.put(mailbox.getMailboxId(), (InMemoryMailbox) mailbox);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.transaction.TransactionalMapper#execute(org.apache.james.imap.store.transaction.TransactionalMapper.Transaction)
+     */
+    public void execute(Transaction transaction) throws MailboxException {
+        transaction.run();
+    }
+
+    public void endRequest() {
+        // TODO Auto-generated method stub
+        
+    }
+    
+}

Added: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java?rev=951398&view=auto
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java (added)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java Fri Jun  4 13:07:05 2010
@@ -0,0 +1,182 @@
+package org.apache.james.imap.inmemory.mail;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MessageRange;
+import org.apache.james.imap.mailbox.SearchQuery;
+import org.apache.james.imap.mailbox.StorageException;
+import org.apache.james.imap.store.MailboxMembershipComparator;
+import org.apache.james.imap.store.mail.MessageMapper;
+import org.apache.james.imap.store.mail.model.MailboxMembership;
+
+public class InMemoryMessageMapper implements MessageMapper<Long> {
+
+    private Map<Long, Map<Long, MailboxMembership<Long>>> mailboxByUid;
+    private static final int INITIAL_SIZE = 256;
+    
+    public InMemoryMessageMapper() {
+        this.mailboxByUid = new ConcurrentHashMap<Long, Map<Long, MailboxMembership<Long>>>(INITIAL_SIZE);
+    }
+    
+    private Map<Long, MailboxMembership<Long>> getMembershipByUidForMailbox(Long mailboxId) {
+        Map<Long, MailboxMembership<Long>> membershipByUid = mailboxByUid.get(mailboxId);
+        if (membershipByUid == null) {
+            membershipByUid = new ConcurrentHashMap<Long, MailboxMembership<Long>>(INITIAL_SIZE);
+            mailboxByUid.put(mailboxId, membershipByUid);
+        }
+        return membershipByUid;
+    }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#countMessagesInMailbox()
+     */
+    public long countMessagesInMailbox(Long mailboxId) throws StorageException {
+        return getMembershipByUidForMailbox(mailboxId).size();
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#countUnseenMessagesInMailbox()
+     */
+    public long countUnseenMessagesInMailbox(Long mailboxId) throws StorageException {
+        long count = 0;
+        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailboxId).values()) {
+            if (!member.isSeen()) {
+                count++;
+            }
+        }
+        return count;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#delete(org.apache.james.imap.store.mail.model.MailboxMembership)
+     */
+    public void delete(Long mailboxId, MailboxMembership<Long> message) throws StorageException {
+        getMembershipByUidForMailbox(mailboxId).remove(message.getUid());
+    }
+
+    @SuppressWarnings("unchecked")
+    public List<MailboxMembership<Long>> findInMailbox(Long mailboxId, MessageRange set) throws StorageException {
+        final List<MailboxMembership<Long>> results;
+        final MessageRange.Type type = set.getType();
+        switch (type) {
+            case ALL:
+                results = new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailboxId).values());
+                break;
+            case FROM:
+                results = new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailboxId).values());
+                for (final Iterator<MailboxMembership<Long>> it=results.iterator();it.hasNext();) {
+                   if (it.next().getUid()< set.getUidFrom()) {
+                       it.remove(); 
+                   }
+                }
+                break;
+            case RANGE:
+                results = new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailboxId).values());
+                for (final Iterator<MailboxMembership<Long>> it=results.iterator();it.hasNext();) {
+                   final long uid = it.next().getUid();
+                if (uid<set.getUidFrom() || uid>set.getUidTo()) {
+                       it.remove(); 
+                   }
+                }
+                break;
+            case ONE:
+                results  = new ArrayList<MailboxMembership<Long>>(1);
+                final MailboxMembership member = getMembershipByUidForMailbox(mailboxId).get(set.getUidFrom());
+                if (member != null) {
+                    results.add(member);
+                }
+                break;
+            default:
+                results = new ArrayList<MailboxMembership<Long>>();
+                break;
+        }
+        Collections.sort(results, MailboxMembershipComparator.INSTANCE);
+        return results;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#findMarkedForDeletionInMailbox(org.apache.james.imap.mailbox.MessageRange)
+     */
+    public List<MailboxMembership<Long>> findMarkedForDeletionInMailbox(Long mailboxId, MessageRange set) throws StorageException {
+        final List<MailboxMembership<Long>> results = findInMailbox(mailboxId, set);
+        for(final Iterator<MailboxMembership<Long>> it=results.iterator();it.hasNext();) {
+            if (!it.next().isDeleted()) {
+                it.remove();
+            }
+        }
+        return results;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#findRecentMessagesInMailbox()
+     */
+    public List<MailboxMembership<Long>> findRecentMessagesInMailbox(Long mailboxId) throws StorageException {
+        final List<MailboxMembership<Long>> results = new ArrayList<MailboxMembership<Long>>();
+        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailboxId).values()) {
+            if (member.isRecent()) {
+                results.add(member);
+            }
+        }
+        Collections.sort(results, MailboxMembershipComparator.INSTANCE);
+        return results;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
+     */
+    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox(Long mailboxId) throws StorageException {
+        final List<MailboxMembership<Long>> results = new ArrayList<MailboxMembership<Long>>();
+        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailboxId).values()) {
+            if (!member.isSeen()) {
+                results.add(member);
+            }
+        }
+        Collections.sort(results, MailboxMembershipComparator.INSTANCE);
+        return results;
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#save(org.apache.james.imap.store.mail.model.MailboxMembership)
+     */
+    public void save(Long mailboxId, MailboxMembership<Long> message) throws StorageException {
+        getMembershipByUidForMailbox(mailboxId).put(message.getUid(), message);
+    }
+
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.imap.store.mail.MessageMapper#searchMailbox(org.apache.james.imap.mailbox.SearchQuery)
+     */
+    public List<MailboxMembership<Long>> searchMailbox(Long mailboxId, SearchQuery query) throws StorageException {
+        return new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailboxId).values());
+    }
+
+    /**
+     * There is no really Transaction handling here.. Just run it 
+     */
+    public void execute(Transaction transaction) throws MailboxException {
+        transaction.run();
+    }
+    
+    public void deleteAll() {
+        mailboxByUid.clear();
+    }
+
+    public void endRequest() {
+        // TODO Auto-generated method stub
+        
+    }
+    
+}

Added: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/InMemoryMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/InMemoryMailbox.java?rev=951398&view=auto
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/InMemoryMailbox.java (added)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/InMemoryMailbox.java Fri Jun  4 13:07:05 2010
@@ -0,0 +1,68 @@
+/****************************************************************
+ * 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.inmemory.mail.model;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.james.imap.store.mail.model.Mailbox;
+
+/**
+ * Mailbox data which is stored only in memory.
+ */
+public class InMemoryMailbox implements Mailbox<Long> {
+
+    private final long id;    
+    private final long uidValidity;
+    private final AtomicLong nextUid;
+    private String name;
+    
+    public InMemoryMailbox(final long id, final String name, final long uidValidity) {
+        super();
+        this.nextUid = new AtomicLong(0);
+        this.id = id;
+        this.name = name;
+        this.uidValidity = uidValidity;
+    }
+
+    public void consumeUid() {
+        nextUid.incrementAndGet();
+    }
+
+    public long getLastUid() {
+        return nextUid.get();
+    }
+
+    public Long getMailboxId() {
+        return id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+
+    public long getUidValidity() {
+        return uidValidity;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+}

Added: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleHeader.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleHeader.java?rev=951398&view=auto
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleHeader.java (added)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleHeader.java Fri Jun  4 13:07:05 2010
@@ -0,0 +1,56 @@
+/****************************************************************
+ * 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.inmemory.mail.model;
+
+import org.apache.james.imap.store.mail.model.AbstractComparableHeader;
+
+public class SimpleHeader extends AbstractComparableHeader {
+
+    public String field;
+    public int lineNumber;
+    public String value;
+    
+    public SimpleHeader() {}
+    
+    public SimpleHeader(SimpleHeader header) {
+        this.field = header.field;
+        this.lineNumber = header.lineNumber;
+        this.value = header.value;
+    }
+    
+    public SimpleHeader(String field, int lineNumber, String value) {
+        super();
+        this.field = field;
+        this.lineNumber = lineNumber;
+        this.value = value;
+    }
+
+    public String getFieldName() {
+        return field;
+    }
+
+    public int getLineNumber() {
+        return lineNumber;
+    }
+
+    public String getValue() {
+        return value;
+    }
+}
\ No newline at end of file

Added: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java?rev=951398&view=auto
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java (added)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/model/SimpleMailboxMembership.java Fri Jun  4 13:07:05 2010
@@ -0,0 +1,243 @@
+/****************************************************************
+ * 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.inmemory.mail.model;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.Flags;
+
+import org.apache.james.imap.store.mail.model.AbstractMailboxMembership;
+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.DelegatingRewindableInputStream;
+import org.apache.james.imap.store.streaming.LazySkippingInputStream;
+import org.apache.james.imap.store.streaming.RewindableInputStream;
+
+public class SimpleMailboxMembership extends AbstractMailboxMembership<Long> implements Document, Comparable<MailboxMembership<Long>> {
+
+    private final long uid;
+    private final long mailboxId;
+    private int size;
+    private boolean answered;
+    private boolean deleted;
+    private boolean draft;
+    private boolean flagged;
+    private boolean recent;
+    private boolean seen;
+    private Date internalDate;
+    private final String subType;
+    private List<Property> properties;
+    private final String mediaType;
+    private List<Header> headers;
+    private Long lineCount;
+    private byte[] document;
+    private int bodyStartOctet;
+    
+    public SimpleMailboxMembership(long mailboxId, long uid, final SimpleMailboxMembership original) {
+        this.uid = uid;
+        this.mailboxId = mailboxId;
+        this.size = original.size;
+        this.answered = original.answered;
+        this.deleted = original.deleted;
+        this.draft = original.draft;
+        this.flagged = original.flagged;
+        this.recent = original.recent;
+        this.seen = original.seen;
+        this.internalDate = original.internalDate;
+        this.subType  = original.subType;
+        this.mediaType = original.mediaType;
+        this.properties = original.properties;
+        this.headers = original.headers;
+        this.lineCount = original.lineCount;
+        this.document = original.document;
+        this.bodyStartOctet = original.bodyStartOctet;
+    }
+    
+    public SimpleMailboxMembership(Date internalDate, long uid, int size, int bodyStartOctet, byte[] document, 
+            Flags flags, List<Header> headers, PropertyBuilder propertyBuilder, final long mailboxId) {
+        this.uid = uid;
+        this.document = document;
+        
+        this.size = size;
+        this.bodyStartOctet = bodyStartOctet;
+        setFlags(flags);
+        lineCount = propertyBuilder.getTextualLineCount();
+        this.headers = headers;
+        this.internalDate = internalDate;
+        this.mailboxId = mailboxId;
+        this.properties = propertyBuilder.toProperties();
+        this.mediaType = propertyBuilder.getMediaType();
+        this.subType = propertyBuilder.getSubType();
+    }
+
+
+    public Document getDocument() {
+        return this;
+    }
+
+    public Date getInternalDate() {
+        return internalDate;
+    }
+
+    public Long getMailboxId() {
+        return mailboxId;
+    }
+
+    public int getSize() {
+        return size;
+    }
+
+    public long getUid() {
+        return uid;
+    }
+
+    public boolean isAnswered() {
+        return answered;
+    }
+
+    public boolean isDeleted() {
+        return deleted;
+    }
+
+    public boolean isDraft() {
+        return draft;
+    }
+
+    public boolean isFlagged() {
+        return flagged;
+    }
+
+    public boolean isRecent() {
+        return recent;
+    }
+
+    public boolean isSeen() {
+        return seen;
+    }
+
+    public synchronized void setFlags(Flags flags) {
+        answered = flags.contains(Flags.Flag.ANSWERED);
+        deleted = flags.contains(Flags.Flag.DELETED);
+        draft = flags.contains(Flags.Flag.DRAFT);
+        flagged = flags.contains(Flags.Flag.FLAGGED);
+        recent = flags.contains(Flags.Flag.RECENT);
+        seen = flags.contains(Flags.Flag.SEEN);
+    }
+
+    public void unsetRecent() {
+        recent = false;
+    }
+
+    public RewindableInputStream getBodyContent() throws IOException {
+        return new DelegatingRewindableInputStream(new LazySkippingInputStream(new ByteArrayInputStream(document),bodyStartOctet), getFullContentOctets());
+       
+    }
+
+    public long getBodyOctets() {
+        return getFullContentOctets() - bodyStartOctet;
+    }
+
+    public RewindableInputStream getFullContent() throws IOException {
+        return new DelegatingRewindableInputStream(new ByteArrayInputStream(document), getFullContentOctets());
+    }
+
+    public long getFullContentOctets() {
+        return document.length;
+    }
+
+    public List<Header> getHeaders() {
+        return headers;
+    }
+
+    public String getMediaType() {
+        return mediaType;
+    }
+
+    public List<Property> getProperties() {
+        return properties;
+    }
+
+    public String getSubType() {
+        return subType;
+    }
+
+    public Long getTextualLineCount() {
+        return lineCount;
+    }
+
+    @Override
+    public int hashCode() {
+        final int PRIME = 31;
+        int result = 1;
+        result = PRIME * result + (int) (uid ^ (uid >>> 32));
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        final SimpleMailboxMembership other = (SimpleMailboxMembership) obj;
+        if (uid != other.uid)
+            return false;
+        return true;
+    }
+
+    public int compareTo(MailboxMembership<Long> o) {
+        final long otherUid = getUid();
+        return uid < otherUid ? -1 : uid == otherUid ? 0 : 1;
+    }
+
+    /**
+     * Representation suitable for logging and debugging.
+     *
+     * @return a <code>String</code> representation 
+     * of this object.
+     */
+    public String toString()
+    {
+        return super.toString() + "["
+            + "uid = " + this.uid + " "
+            + "mailboxId = " + this.mailboxId + " "
+            + "size = " + this.size + " "
+            + "answered = " + this.answered + " "
+            + "deleted = " + this.deleted + " "
+            + "draft = " + this.draft + " "
+            + "flagged = " + this.flagged + " "
+            + "recent = " + this.recent + " "
+            + "seen = " + this.seen + " "
+            + "internalDate = " + this.internalDate + " "
+            + "subType = " + this.subType + " "
+            + "mediaType = " + this.mediaType + " "
+            + " ]";
+    }
+    
+    
+}

Added: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/user/InMemorySubscriptionMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/user/InMemorySubscriptionMapper.java?rev=951398&view=auto
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/user/InMemorySubscriptionMapper.java (added)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/user/InMemorySubscriptionMapper.java Fri Jun  4 13:07:05 2010
@@ -0,0 +1,100 @@
+/****************************************************************
+ * 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.inmemory.user;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.store.user.SubscriptionMapper;
+import org.apache.james.imap.store.user.model.Subscription;
+
+public class InMemorySubscriptionMapper implements SubscriptionMapper {
+    
+    private static final int INITIAL_SIZE = 64;
+    private final Map<String, List<Subscription>> subscriptionsByUser;
+    
+    public InMemorySubscriptionMapper() {
+        subscriptionsByUser = new ConcurrentHashMap<String, List<Subscription>>(INITIAL_SIZE);
+    }
+
+    public synchronized void delete(Subscription subscription) {
+        final String user = subscription.getUser();
+        final List<Subscription> subscriptions = subscriptionsByUser.get(user);
+        if (subscriptions != null) {
+            subscriptions.remove(subscription);
+        }
+    }
+
+    public Subscription findFindMailboxSubscriptionForUser(String user, String mailbox) {
+        final List<Subscription> subscriptions = subscriptionsByUser.get(user);
+        Subscription result = null;
+        if (subscriptions != null) {
+            for(Subscription subscription:subscriptions) {
+                if (subscription.getMailbox().equals(mailbox)) {
+                    result = subscription;
+                    break;
+                }
+            }
+        }
+        return result;
+    }
+
+    @SuppressWarnings("unchecked")
+    public List<Subscription> findSubscriptionsForUser(String user) {
+        final List<Subscription> subcriptions = subscriptionsByUser.get(user);
+        final List<Subscription> results;
+        if (subcriptions == null) {
+            results = Collections.EMPTY_LIST;
+        } else {
+            // Make a copy to prevent concurrent modifications
+            results = new ArrayList<Subscription>(subcriptions);
+        }
+        return results;
+    }
+
+    public synchronized void save(Subscription subscription) {
+        final String user = subscription.getUser();
+        final List<Subscription> subscriptions = subscriptionsByUser.get(user);
+        if (subscriptions == null) {
+            final List<Subscription> newSubscriptions  = new ArrayList<Subscription>();
+            newSubscriptions.add(subscription);
+            subscriptionsByUser.put(user, newSubscriptions);
+        } else {
+            subscriptions.add(subscription);
+        }
+    }
+
+    public void execute(Transaction transaction) throws MailboxException {
+        transaction.run();
+    }
+    
+    public void deleteAll() {
+        subscriptionsByUser.clear();
+    }
+
+    public void endRequest() {
+        // TODO Auto-generated method stub
+        
+    }
+
+}



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