james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r980539 - in /james/imap/trunk: jcr/src/main/java/org/apache/james/imap/jcr/ jcr/src/main/java/org/apache/james/imap/jcr/mail/ jpa/src/main/java/org/apache/james/imap/jpa/ jpa/src/main/java/org/apache/james/imap/jpa/mail/ jpa/src/main/java/...
Date Thu, 29 Jul 2010 18:43:48 GMT
Author: norman
Date: Thu Jul 29 18:43:47 2010
New Revision: 980539

URL: http://svn.apache.org/viewvc?rev=980539&view=rev
Log:
 Identify mailbox by Mailbox objects instead of mailboxId (IMAP-183). Thx to Tim-Christian Mundt for the patch, I only did some small adjustments to fix a bug in the memory based backend + jpa backend

Modified:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMessageManager.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMessageManager.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java?rev=980539&r1=980538&r2=980539&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMessageManager.java Thu Jul 29 18:43:47 2010
@@ -64,7 +64,7 @@ public class JCRMessageManager extends S
         for (Header header: headers) {
             jcrHeaders.add((JCRHeader) header);
         }
-        final MailboxMembership<String> message = new JCRMessage(getMailboxId(), uid, internalDate, 
+        final MailboxMembership<String> message = new JCRMessage(mailbox.getMailboxId(), uid, internalDate, 
                 size, flags, document, bodyStartOctet, jcrHeaders, propertyBuilder, log);
         return message;
     }

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java?rev=980539&r1=980538&r2=980539&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java Thu Jul 29 18:43:47 2010
@@ -50,6 +50,7 @@ import org.apache.james.imap.mailbox.Mes
 import org.apache.james.imap.mailbox.SearchQuery.Criterion;
 import org.apache.james.imap.mailbox.SearchQuery.NumericRange;
 import org.apache.james.imap.store.mail.MessageMapper;
+import org.apache.james.imap.store.mail.model.Mailbox;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
 
 /**
@@ -128,13 +129,13 @@ public class JCRMessageMapper extends Ab
      * 
      * See http://wiki.apache.org/jackrabbit/EncodingAndEscaping
      * 
-     * @param uuid
+     * @param mailbox
      * @return
      * @throws ItemNotFoundException
      * @throws RepositoryException
      */
-    private String getMailboxPath(String uuid) throws ItemNotFoundException, RepositoryException {
-        return ISO9075.encodePath(getSession().getNodeByIdentifier(uuid).getPath());
+    private String getMailboxPath(Mailbox<String> mailbox) throws ItemNotFoundException, RepositoryException {
+        return ISO9075.encodePath(getSession().getNodeByIdentifier(mailbox.getMailboxId()).getPath());
     }
     /*
      * (non-Javadoc)
@@ -142,10 +143,10 @@ public class JCRMessageMapper extends Ab
      * @see
      * org.apache.james.imap.store.mail.MessageMapper#countMessagesInMailbox()
      */
-    public long countMessagesInMailbox(String uuid) throws StorageException {
+    public long countMessagesInMailbox(Mailbox<String> mailbox) throws StorageException {
         try {
             // we use order by because without it count will always be 0 in jackrabbit
-            String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message) order by @" + JCRMessage.UID_PROPERTY;
+            String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message) order by @" + JCRMessage.UID_PROPERTY;
             QueryManager manager = getSession().getWorkspace().getQueryManager();
             QueryResult result = manager.createQuery(queryString, Query.XPATH).execute();
             NodeIterator nodes = result.getNodes();
@@ -171,11 +172,11 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#countUnseenMessagesInMailbox
      * ()
      */
-    public long countUnseenMessagesInMailbox(String uuid) throws StorageException {
+    public long countUnseenMessagesInMailbox(Mailbox<String> mailbox) throws StorageException {
         
         try {
             // we use order by because without it count will always be 0 in jackrabbit
-            String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.SEEN_PROPERTY +"='false'] order by @" + JCRMessage.UID_PROPERTY;
+            String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.SEEN_PROPERTY +"='false'] order by @" + JCRMessage.UID_PROPERTY;
             QueryManager manager = getSession().getWorkspace().getQueryManager();
             QueryResult result = manager.createQuery(queryString, Query.XPATH).execute();
             NodeIterator nodes = result.getNodes();
@@ -199,7 +200,7 @@ public class JCRMessageMapper extends Ab
      * (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(String uuid, MailboxMembership<String> message) throws StorageException {
+    public void delete(Mailbox<String> mailbox, MailboxMembership<String> message) throws StorageException {
         JCRMessage membership = (JCRMessage) message;
         if (membership.isPersistent()) {
             try {
@@ -218,7 +219,7 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#findInMailbox(org.apache
      * .james.imap.mailbox.MessageRange)
      */
-    public List<MailboxMembership<String>> findInMailbox(String uuid, MessageRange set) throws StorageException {
+    public List<MailboxMembership<String>> findInMailbox(Mailbox<String> mailbox, MessageRange set) throws StorageException {
         try {
             final List<MailboxMembership<String>> results;
             final long from = set.getUidFrom();
@@ -227,16 +228,16 @@ public class JCRMessageMapper extends Ab
             switch (type) {
                 default:
                 case ALL:
-                    results = findMessagesInMailbox(uuid);
+                    results = findMessagesInMailbox(mailbox);
                     break;
                 case FROM:
-                    results = findMessagesInMailboxAfterUID(uuid, from);
+                    results = findMessagesInMailboxAfterUID(mailbox, from);
                     break;
                 case ONE:
-                    results = findMessageInMailboxWithUID(uuid, from);
+                    results = findMessageInMailboxWithUID(mailbox, from);
                     break;
                 case RANGE:
-                    results = findMessagesInMailboxBetweenUIDs(uuid, from, to);
+                    results = findMessagesInMailboxBetweenUIDs(mailbox, from, to);
                     break;       
             }
             return results;
@@ -245,9 +246,9 @@ public class JCRMessageMapper extends Ab
         }
     }
 
-    private List<MailboxMembership<String>> findMessagesInMailboxAfterUID(String uuid, long uid) throws RepositoryException {
+    private List<MailboxMembership<String>> findMessagesInMailboxAfterUID(Mailbox<String> mailbox, long uid) throws RepositoryException {
         List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-        String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + ">=" + uid + "] order by @" + JCRMessage.UID_PROPERTY;
+        String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + ">=" + uid + "] order by @" + JCRMessage.UID_PROPERTY;
 
         QueryManager manager = getSession().getWorkspace().getQueryManager();
         QueryResult result = manager.createQuery(queryString, Query.XPATH).execute();
@@ -259,9 +260,9 @@ public class JCRMessageMapper extends Ab
         return list;
     }
 
-    private List<MailboxMembership<String>> findMessageInMailboxWithUID(String uuid, long uid) throws RepositoryException  {
+    private List<MailboxMembership<String>> findMessageInMailboxWithUID(Mailbox<String> mailbox, long uid) throws RepositoryException  {
         List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-        String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + "=" + uid + "]";
+        String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + "=" + uid + "]";
 
         QueryManager manager = getSession().getWorkspace().getQueryManager();
         Query query = manager.createQuery(queryString, Query.XPATH);
@@ -274,9 +275,9 @@ public class JCRMessageMapper extends Ab
         return list;
     }
 
-    private List<MailboxMembership<String>> findMessagesInMailboxBetweenUIDs(String uuid, long from, long to) throws RepositoryException {
+    private List<MailboxMembership<String>> findMessagesInMailboxBetweenUIDs(Mailbox<String> mailbox, long from, long to) throws RepositoryException {
         List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-        String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + ">=" + from + " and @" + JCRMessage.UID_PROPERTY + "<=" + to + "] order by @" + JCRMessage.UID_PROPERTY;
+        String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + ">=" + from + " and @" + JCRMessage.UID_PROPERTY + "<=" + to + "] order by @" + JCRMessage.UID_PROPERTY;
         
         QueryManager manager = getSession().getWorkspace().getQueryManager();
         QueryResult result = manager.createQuery(queryString, Query.XPATH).execute();
@@ -288,10 +289,10 @@ public class JCRMessageMapper extends Ab
         return list;
     }
     
-    private List<MailboxMembership<String>> findMessagesInMailbox(String uuid) throws RepositoryException {        
+    private List<MailboxMembership<String>> findMessagesInMailbox(Mailbox<String> mailbox) throws RepositoryException {        
         List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
         
-        String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message) order by @" + JCRMessage.UID_PROPERTY;
+        String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message) order by @" + JCRMessage.UID_PROPERTY;
         QueryManager manager = getSession().getWorkspace().getQueryManager();
         QueryResult result = manager.createQuery(queryString, Query.XPATH).execute();
 
@@ -304,9 +305,9 @@ public class JCRMessageMapper extends Ab
 
     
     
-    private List<MailboxMembership<String>> findDeletedMessagesInMailboxAfterUID(String uuid, long uid) throws RepositoryException {
+    private List<MailboxMembership<String>> findDeletedMessagesInMailboxAfterUID(Mailbox<String> mailbox, long uid) throws RepositoryException {
         List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-        String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + ">=" + uid + " and @" + JCRMessage.DELETED_PROPERTY+ "='true'] order by @" + JCRMessage.UID_PROPERTY;
+        String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + ">=" + uid + " and @" + JCRMessage.DELETED_PROPERTY+ "='true'] order by @" + JCRMessage.UID_PROPERTY;
  
         QueryManager manager = getSession().getWorkspace().getQueryManager();
         QueryResult result = manager.createQuery(queryString, Query.XPATH).execute();
@@ -318,9 +319,9 @@ public class JCRMessageMapper extends Ab
         return list;
     }
 
-    private List<MailboxMembership<String>> findDeletedMessageInMailboxWithUID(String uuid, long uid) throws RepositoryException  {
+    private List<MailboxMembership<String>> findDeletedMessageInMailboxWithUID(Mailbox<String> mailbox, long uid) throws RepositoryException  {
         List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-        String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + "=" + uid + " and @" + JCRMessage.DELETED_PROPERTY+ "='true']";
+        String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + "=" + uid + " and @" + JCRMessage.DELETED_PROPERTY+ "='true']";
         QueryManager manager = getSession().getWorkspace().getQueryManager();
         Query query = manager.createQuery(queryString, Query.XPATH);
         query.setLimit(1);
@@ -334,9 +335,9 @@ public class JCRMessageMapper extends Ab
         return list;
     }
 
-    private List<MailboxMembership<String>> findDeletedMessagesInMailboxBetweenUIDs(String uuid, long from, long to) throws RepositoryException {
+    private List<MailboxMembership<String>> findDeletedMessagesInMailboxBetweenUIDs(Mailbox<String> mailbox, long from, long to) throws RepositoryException {
         List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-        String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + ">=" + from + " and @" + JCRMessage.UID_PROPERTY + "<=" + to + " and @" + JCRMessage.DELETED_PROPERTY+ "='true'] order by @" + JCRMessage.UID_PROPERTY;
+        String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.UID_PROPERTY + ">=" + from + " and @" + JCRMessage.UID_PROPERTY + "<=" + to + " and @" + JCRMessage.DELETED_PROPERTY+ "='true'] order by @" + JCRMessage.UID_PROPERTY;
        
         QueryManager manager = getSession().getWorkspace().getQueryManager();
         QueryResult result = manager.createQuery(queryString, Query.XPATH).execute();
@@ -348,10 +349,10 @@ public class JCRMessageMapper extends Ab
         return list;
     }
     
-    private List<MailboxMembership<String>> findDeletedMessagesInMailbox(String uuid) throws RepositoryException {
+    private List<MailboxMembership<String>> findDeletedMessagesInMailbox(Mailbox<String> mailbox) throws RepositoryException {
         
         List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-        String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.DELETED_PROPERTY+ "='true'] order by @" + JCRMessage.UID_PROPERTY;
+        String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.DELETED_PROPERTY+ "='true'] order by @" + JCRMessage.UID_PROPERTY;
         
         QueryManager manager = getSession().getWorkspace().getQueryManager();
         QueryResult result = manager.createQuery(queryString, Query.XPATH).execute();
@@ -371,7 +372,7 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#findMarkedForDeletionInMailbox
      * (org.apache.james.imap.mailbox.MessageRange)
      */
-    public List<MailboxMembership<String>> findMarkedForDeletionInMailbox(String uuid, MessageRange set) throws StorageException {
+    public List<MailboxMembership<String>> findMarkedForDeletionInMailbox(Mailbox<String> mailbox, MessageRange set) throws StorageException {
         try {
             final List<MailboxMembership<String>> results;
             final long from = set.getUidFrom();
@@ -380,16 +381,16 @@ public class JCRMessageMapper extends Ab
             switch (type) {
                 default:
                 case ALL:
-                    results = findDeletedMessagesInMailbox(uuid);
+                    results = findDeletedMessagesInMailbox(mailbox);
                     break;
                 case FROM:
-                    results = findDeletedMessagesInMailboxAfterUID(uuid, from);
+                    results = findDeletedMessagesInMailboxAfterUID(mailbox, from);
                     break;
                 case ONE:
-                    results = findDeletedMessageInMailboxWithUID(uuid, from);
+                    results = findDeletedMessageInMailboxWithUID(mailbox, from);
                     break;
                 case RANGE:
-                    results = findDeletedMessagesInMailboxBetweenUIDs(uuid, from, to);
+                    results = findDeletedMessagesInMailboxBetweenUIDs(mailbox, from, to);
                     break;       
             }
             return results;
@@ -408,12 +409,12 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#findRecentMessagesInMailbox
      * ()
      */
-    public List<MailboxMembership<String>> findRecentMessagesInMailbox(String uuid, int limit) throws StorageException {
+    public List<MailboxMembership<String>> findRecentMessagesInMailbox(Mailbox<String> mailbox, int limit) throws StorageException {
         
         try {
  
             List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-            String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.RECENT_PROPERTY +"='true'] order by @" + JCRMessage.UID_PROPERTY;
+            String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.RECENT_PROPERTY +"='true'] order by @" + JCRMessage.UID_PROPERTY;
             
             QueryManager manager = getSession().getWorkspace().getQueryManager();
             Query query = manager.createQuery(queryString, Query.XPATH);
@@ -440,11 +441,11 @@ public class JCRMessageMapper extends Ab
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
      */
-    public List<MailboxMembership<String>> findUnseenMessagesInMailbox(String uuid, int limit) throws StorageException {
+    public List<MailboxMembership<String>> findUnseenMessagesInMailbox(Mailbox<String> mailbox, int limit) throws StorageException {
         try {
   
             List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-            String queryString = "/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)[@" + JCRMessage.SEEN_PROPERTY +"='false'] order by @" + JCRMessage.UID_PROPERTY;
+            String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@" + JCRMessage.SEEN_PROPERTY +"='false'] order by @" + JCRMessage.UID_PROPERTY;
 
             QueryManager manager = getSession().getWorkspace().getQueryManager();
             
@@ -471,7 +472,7 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#save(org.apache.james.
      * imap.store.mail.model.MailboxMembership)
      */
-    public void save(String uuid, MailboxMembership<String> message) throws StorageException {
+    public void save(Mailbox<String> mailbox, MailboxMembership<String> message) throws StorageException {
         final JCRMessage membership = (JCRMessage) message;
         try {
 
@@ -498,7 +499,7 @@ public class JCRMessageMapper extends Ab
                 final String min = convertIntToString(cal.get(Calendar.MINUTE));
 
                 Node node = null;
-                Node mailboxNode = getSession().getNodeByIdentifier(uuid);
+                Node mailboxNode = getSession().getNodeByIdentifier(mailbox.getMailboxId());
 
                 NodeLocker locker = getNodeLocker();
 
@@ -605,10 +606,10 @@ public class JCRMessageMapper extends Ab
      * org.apache.james.imap.store.mail.MessageMapper#searchMailbox(org.apache
      * .james.imap.mailbox.SearchQuery)
      */
-    public List<MailboxMembership<String>> searchMailbox(String uuid, SearchQuery query) throws StorageException {
+    public List<MailboxMembership<String>> searchMailbox(Mailbox<String> mailbox, SearchQuery query) throws StorageException {
         try {
             List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
-            final Query xQuery = formulateXPath(uuid, query);
+            final Query xQuery = formulateXPath(mailbox, query);
             
             QueryResult result = xQuery.execute();
             
@@ -631,9 +632,9 @@ public class JCRMessageMapper extends Ab
      * @throws RepositoryException 
      * @throws ItemNotFoundException 
      */
-    private Query formulateXPath(String uuid, SearchQuery query) throws ItemNotFoundException, RepositoryException {
+    private Query formulateXPath(Mailbox<String> mailbox, SearchQuery query) throws ItemNotFoundException, RepositoryException {
         final StringBuilder queryBuilder = new StringBuilder();
-        queryBuilder.append("/jcr:root" + getMailboxPath(uuid) + "//element(*,jamesMailbox:message)");
+        queryBuilder.append("/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)");
         final List<Criterion> criteria = query.getCriterias();
         boolean range = false;
         int rangeLength = -1;
@@ -684,12 +685,12 @@ public class JCRMessageMapper extends Ab
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MessageMapper#copy(java.lang.Object, long, org.apache.james.imap.store.mail.model.MailboxMembership)
      */
-    public MailboxMembership<String> copy(String uuid, long uid, MailboxMembership<String> oldmessage) throws StorageException{
+    public MailboxMembership<String> copy(Mailbox<String> mailbox, long uid, MailboxMembership<String> oldmessage) throws StorageException{
         try {
-            String newMessagePath = getSession().getNodeByIdentifier(uuid).getPath() + NODE_DELIMITER + String.valueOf(uid);
-            getSession().getWorkspace().copy(((JCRMessage)oldmessage).getNode().getPath(), getSession().getNodeByIdentifier(uuid).getPath() + NODE_DELIMITER + String.valueOf(uid));
+            String newMessagePath = getSession().getNodeByIdentifier(mailbox.getMailboxId()).getPath() + NODE_DELIMITER + String.valueOf(uid);
+            getSession().getWorkspace().copy(((JCRMessage)oldmessage).getNode().getPath(), getSession().getNodeByIdentifier(mailbox.getMailboxId()).getPath() + NODE_DELIMITER + String.valueOf(uid));
             Node node = getSession().getNode(newMessagePath);
-            node.setProperty(JCRMessage.MAILBOX_UUID_PROPERTY, uuid);
+            node.setProperty(JCRMessage.MAILBOX_UUID_PROPERTY, mailbox.getMailboxId());
             node.setProperty(JCRMessage.UID_PROPERTY, uid);
             return new JCRMessage(node,getLogger());
         } catch (RepositoryException e) {

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java?rev=980539&r1=980538&r2=980539&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMessageManager.java Thu Jul 29 18:43:47 2010
@@ -55,7 +55,7 @@ public class JPAMessageManager extends S
         for (Header header: headers) {
             jpaHeaders.add((JPAHeader) header);
         }
-        final MailboxMembership<Long> message = new JPAMailboxMembership(getMailboxId(), uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
+        final MailboxMembership<Long> message = new JPAMailboxMembership(mailbox.getMailboxId(), uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
         return message;
     }
 

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=980539&r1=980538&r2=980539&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 Thu Jul 29 18:43:47 2010
@@ -37,6 +37,7 @@ import org.apache.james.imap.mailbox.Mes
 import org.apache.james.imap.mailbox.SearchQuery.Criterion;
 import org.apache.james.imap.mailbox.SearchQuery.NumericRange;
 import org.apache.james.imap.store.mail.MessageMapper;
+import org.apache.james.imap.store.mail.model.Mailbox;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
 
 
@@ -53,7 +54,7 @@ public class JPAMessageMapper extends JP
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#findInMailbox(org.apache.james.imap.mailbox.MessageRange)
      */
-    public List<MailboxMembership<Long>> findInMailbox(Long mailboxId, MessageRange set) throws StorageException {
+    public List<MailboxMembership<Long>> findInMailbox(Mailbox<Long> mailbox, MessageRange set) throws StorageException {
         try {
             final List<MailboxMembership<Long>> results;
             final long from = set.getUidFrom();
@@ -62,16 +63,16 @@ public class JPAMessageMapper extends JP
             switch (type) {
                 default:
                 case ALL:
-                    results = findMessagesInMailbox(mailboxId);
+                    results = findMessagesInMailbox(mailbox);
                     break;
                 case FROM:
-                    results = findMessagesInMailboxAfterUID(mailboxId, from);
+                    results = findMessagesInMailboxAfterUID(mailbox, from);
                     break;
                 case ONE:
-                    results = findMessagesInMailboxWithUID(mailboxId, from);
+                    results = findMessagesInMailboxWithUID(mailbox, from);
                     break;
                 case RANGE:
-                    results = findMessagesInMailboxBetweenUIDs(mailboxId, from, to);
+                    results = findMessagesInMailboxBetweenUIDs(mailbox, from, to);
                     break;       
             }
             return results;
@@ -81,53 +82,53 @@ public class JPAMessageMapper extends JP
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findMessagesInMailboxAfterUID(Long mailboxId, long uid) {
+    private List<MailboxMembership<Long>> findMessagesInMailboxAfterUID(Mailbox<Long> mailbox, long uid) {
         return getEntityManager().createNamedQuery("findMessagesInMailboxAfterUID")
-        .setParameter("idParam", mailboxId)
+        .setParameter("idParam", mailbox.getMailboxId())
         .setParameter("uidParam", uid).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findMessagesInMailboxWithUID(Long mailboxId, long uid) {
+    private List<MailboxMembership<Long>> findMessagesInMailboxWithUID(Mailbox<Long> mailbox, long uid) {
         return getEntityManager().createNamedQuery("findMessagesInMailboxWithUID")
-        .setParameter("idParam", mailboxId)
+        .setParameter("idParam", mailbox.getMailboxId())
         .setParameter("uidParam", uid).setMaxResults(1).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findMessagesInMailboxBetweenUIDs(Long mailboxId, long from, long to) {
+    private List<MailboxMembership<Long>> findMessagesInMailboxBetweenUIDs(Mailbox<Long> mailbox, long from, long to) {
         return getEntityManager().createNamedQuery("findMessagesInMailboxBetweenUIDs")
-        .setParameter("idParam", mailboxId)
+        .setParameter("idParam", mailbox.getMailboxId())
         .setParameter("fromParam", from)
         .setParameter("toParam", to).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findMessagesInMailbox(Long mailboxId) {
-        return getEntityManager().createNamedQuery("findMessagesInMailbox").setParameter("idParam", mailboxId).getResultList();
+    private List<MailboxMembership<Long>> findMessagesInMailbox(Mailbox<Long> mailbox) {
+        return getEntityManager().createNamedQuery("findMessagesInMailbox").setParameter("idParam", mailbox.getMailboxId()).getResultList();
     }
 
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#findMarkedForDeletionInMailbox(org.apache.james.imap.mailbox.MessageRange)
      */
-    public List<MailboxMembership<Long>> findMarkedForDeletionInMailbox(Long mailboxId, final MessageRange set) throws StorageException {
+    public List<MailboxMembership<Long>> findMarkedForDeletionInMailbox(Mailbox<Long> mailbox, final MessageRange set) throws StorageException {
         try {
             final List<MailboxMembership<Long>> results;
             final long from = set.getUidFrom();
             final long to = set.getUidTo();
             switch (set.getType()) {
                 case ONE:
-                    results = findDeletedMessagesInMailboxWithUID(mailboxId, from);
+                    results = findDeletedMessagesInMailboxWithUID(mailbox, from);
                     break;
                 case RANGE:
-                    results = findDeletedMessagesInMailboxBetweenUIDs(mailboxId, from, to);
+                    results = findDeletedMessagesInMailboxBetweenUIDs(mailbox, from, to);
                     break;
                 case FROM:
-                    results = findDeletedMessagesInMailboxAfterUID(mailboxId, from);
+                    results = findDeletedMessagesInMailboxAfterUID(mailbox, from);
                     break;
                 default:
                 case ALL:
-                    results = findDeletedMessagesInMailbox(mailboxId);
+                    results = findDeletedMessagesInMailbox(mailbox);
                     break;
             }
             return results;
@@ -137,28 +138,28 @@ public class JPAMessageMapper extends JP
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findDeletedMessagesInMailbox(Long mailboxId) {
-        return getEntityManager().createNamedQuery("findDeletedMessagesInMailbox").setParameter("idParam", mailboxId).getResultList();
+    private List<MailboxMembership<Long>> findDeletedMessagesInMailbox(Mailbox<Long> mailbox) {
+        return getEntityManager().createNamedQuery("findDeletedMessagesInMailbox").setParameter("idParam", mailbox.getMailboxId()).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxAfterUID(Long mailboxId, long uid) {
+    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxAfterUID(Mailbox<Long> mailbox, long uid) {
         return getEntityManager().createNamedQuery("findDeletedMessagesInMailboxAfterUID")
-        .setParameter("idParam", mailboxId)
+        .setParameter("idParam", mailbox.getMailboxId())
         .setParameter("uidParam", uid).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxWithUID(Long mailboxId, long uid) {
+    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxWithUID(Mailbox<Long> mailbox, long uid) {
         return getEntityManager().createNamedQuery("findDeletedMessagesInMailboxWithUID")
-        .setParameter("idParam", mailboxId)
+        .setParameter("idParam", mailbox.getMailboxId())
         .setParameter("uidParam", uid).setMaxResults(1).getResultList();
     }
 
     @SuppressWarnings("unchecked")
-    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxBetweenUIDs(Long mailboxId, long from, long to) {
+    private List<MailboxMembership<Long>> findDeletedMessagesInMailboxBetweenUIDs(Mailbox<Long> mailbox, long from, long to) {
         return getEntityManager().createNamedQuery("findDeletedMessagesInMailboxBetweenUIDs")
-        .setParameter("idParam", mailboxId)
+        .setParameter("idParam", mailbox.getMailboxId())
         .setParameter("fromParam", from)
         .setParameter("toParam", to).getResultList();
     }
@@ -166,9 +167,9 @@ public class JPAMessageMapper extends JP
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#countMessagesInMailbox()
      */
-    public long countMessagesInMailbox(Long mailboxId) throws StorageException {
+    public long countMessagesInMailbox(Mailbox<Long> mailbox) throws StorageException {
         try {
-            return (Long) getEntityManager().createNamedQuery("countMessagesInMailbox").setParameter("idParam", mailboxId).getSingleResult();
+            return (Long) getEntityManager().createNamedQuery("countMessagesInMailbox").setParameter("idParam", mailbox.getMailboxId()).getSingleResult();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.COUNT_FAILED, e);
         }
@@ -177,9 +178,9 @@ public class JPAMessageMapper extends JP
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#countUnseenMessagesInMailbox()
      */
-    public long countUnseenMessagesInMailbox(Long mailboxId) throws StorageException {
+    public long countUnseenMessagesInMailbox(Mailbox<Long> mailbox) throws StorageException {
         try {
-            return (Long) getEntityManager().createNamedQuery("countUnseenMessagesInMailbox").setParameter("idParam", mailboxId).getSingleResult();
+            return (Long) getEntityManager().createNamedQuery("countUnseenMessagesInMailbox").setParameter("idParam", mailbox.getMailboxId()).getSingleResult();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.COUNT_FAILED, e);
         }
@@ -189,9 +190,9 @@ 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(Long mailboxId, SearchQuery query) throws StorageException {
+    public List<MailboxMembership<Long>> searchMailbox(Mailbox<Long> mailbox, SearchQuery query) throws StorageException {
         try {
-            final Query jQuery = formulateJQL(mailboxId, query);
+            final Query jQuery = formulateJQL(mailbox.getMailboxId(), query);
             return jQuery.getResultList();
         } catch (PersistenceException e) {
             throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
@@ -246,7 +247,7 @@ public class JPAMessageMapper extends JP
      * (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(Long uid, MailboxMembership<Long> message) throws StorageException {
+    public void delete(Mailbox<Long> mailbox, MailboxMembership<Long> message) throws StorageException {
         try {
             getEntityManager().remove(message);
         } catch (PersistenceException e) {
@@ -259,9 +260,9 @@ public class JPAMessageMapper extends JP
      * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
      */
     @SuppressWarnings("unchecked")
-    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox(Long mailboxId, int limit)  throws StorageException {
+    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox(Mailbox<Long> mailbox, int limit)  throws StorageException {
         try {
-            Query query = getEntityManager().createNamedQuery("findUnseenMessagesInMailboxOrderByUid").setParameter("idParam", mailboxId);
+            Query query = getEntityManager().createNamedQuery("findUnseenMessagesInMailboxOrderByUid").setParameter("idParam", mailbox.getMailboxId());
             if (limit > 0) {
                 query = query.setMaxResults(limit);
             }
@@ -275,9 +276,9 @@ public class JPAMessageMapper extends JP
      * @see org.apache.james.imap.store.mail.MessageMapper#findRecentMessagesInMailbox()
      */
     @SuppressWarnings("unchecked")
-    public List<MailboxMembership<Long>> findRecentMessagesInMailbox(Long mailboxId, int limit) throws StorageException {
+    public List<MailboxMembership<Long>> findRecentMessagesInMailbox(Mailbox<Long> mailbox, int limit) throws StorageException {
         try {
-            Query query = getEntityManager().createNamedQuery("findRecentMessagesInMailbox").setParameter("idParam", mailboxId);
+            Query query = getEntityManager().createNamedQuery("findRecentMessagesInMailbox").setParameter("idParam", mailbox.getMailboxId());
             if (limit > 0) {
                 query = query.setMaxResults(limit);
             }
@@ -290,7 +291,7 @@ public class JPAMessageMapper extends JP
     /**
      * @see org.apache.james.imap.store.mail.MessageMapper#save(MailboxMembership)
      */
-    public void save(Long mailboxId, MailboxMembership<Long> message) throws StorageException {
+    public void save(Mailbox<Long> mailbox, MailboxMembership<Long> message) throws StorageException {
         try {
             getEntityManager().persist(message);
         } catch (PersistenceException e) {
@@ -302,15 +303,15 @@ public class JPAMessageMapper extends JP
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MessageMapper#copy(java.lang.Object, long, org.apache.james.imap.store.mail.model.MailboxMembership)
      */
-    public MailboxMembership<Long> copy(Long mailboxId, long uid, MailboxMembership<Long> original) throws StorageException {
+    public MailboxMembership<Long> copy(Mailbox<Long> mailbox, long uid, MailboxMembership<Long> original) throws StorageException {
         try {
             MailboxMembership<Long> copy;
             if (original instanceof JPAStreamingMailboxMembership) {
-                copy = new JPAStreamingMailboxMembership(mailboxId, uid, (AbstractJPAMailboxMembership) original);
+                copy = new JPAStreamingMailboxMembership(mailbox.getMailboxId(), uid, (AbstractJPAMailboxMembership) original);
             } else {
-                copy = new JPAMailboxMembership(mailboxId, uid, (AbstractJPAMailboxMembership)original);
+                copy = new JPAMailboxMembership(mailbox.getMailboxId(), uid, (AbstractJPAMailboxMembership)original);
             }
-            save(mailboxId, copy);
+            save(mailbox, copy);
             return copy;
         } catch (MailboxException e) {
             throw new StorageException(e.getKey(),e);

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=980539&r1=980538&r2=980539&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 Thu Jul 29 18:43:47 2010
@@ -67,7 +67,7 @@ public class OpenJPAMessageManager exten
             for (Header header: headers) {
                 jpaHeaders.add((JPAHeader) header);
             }
-            return new JPAStreamingMailboxMembership(getMailboxId(), uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
+            return new JPAStreamingMailboxMembership(mailbox.getMailboxId(), uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
         } else {
             return super.createMessage(internalDate, uid, size, bodyStartOctet, document, flags, headers, propertyBuilder);
         }

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=980539&r1=980538&r2=980539&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 Thu Jul 29 18:43:47 2010
@@ -71,7 +71,7 @@ public class InMemoryStoreMessageManager
             e.printStackTrace();
             byteContent = new byte[0];
         }
-        return new SimpleMailboxMembership(internalDate, uid, size, bodyStartOctet, byteContent, flags, headers, propertyBuilder, getMailboxId());
+        return new SimpleMailboxMembership(internalDate, uid, size, bodyStartOctet, byteContent, flags, headers, propertyBuilder, mailbox.getMailboxId());
     }
     
 }

Modified: 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=980539&r1=980538&r2=980539&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java Thu Jul 29 18:43:47 2010
@@ -14,6 +14,7 @@ import org.apache.james.imap.mailbox.Sea
 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.Mailbox;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
 
 public class InMemoryMessageMapper implements MessageMapper<Long> {
@@ -25,11 +26,11 @@ public class InMemoryMessageMapper imple
         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);
+    private Map<Long, MailboxMembership<Long>> getMembershipByUidForMailbox(Mailbox<Long> mailbox) {
+        Map<Long, MailboxMembership<Long>> membershipByUid = mailboxByUid.get(mailbox.getMailboxId());
         if (membershipByUid == null) {
             membershipByUid = new ConcurrentHashMap<Long, MailboxMembership<Long>>(INITIAL_SIZE);
-            mailboxByUid.put(mailboxId, membershipByUid);
+            mailboxByUid.put(mailbox.getMailboxId(), membershipByUid);
         }
         return membershipByUid;
     }
@@ -38,17 +39,17 @@ public class InMemoryMessageMapper imple
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MessageMapper#countMessagesInMailbox()
      */
-    public long countMessagesInMailbox(Long mailboxId) throws StorageException {
-        return getMembershipByUidForMailbox(mailboxId).size();
+    public long countMessagesInMailbox(Mailbox<Long> mailbox) throws StorageException {
+        return getMembershipByUidForMailbox(mailbox).size();
     }
 
     /*
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MessageMapper#countUnseenMessagesInMailbox()
      */
-    public long countUnseenMessagesInMailbox(Long mailboxId) throws StorageException {
+    public long countUnseenMessagesInMailbox(Mailbox<Long> mailbox) throws StorageException {
         long count = 0;
-        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailboxId).values()) {
+        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailbox).values()) {
             if (!member.isSeen()) {
                 count++;
             }
@@ -60,8 +61,8 @@ public class InMemoryMessageMapper imple
      * (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());
+    public void delete(Mailbox<Long> mailbox, MailboxMembership<Long> message) throws StorageException {
+        getMembershipByUidForMailbox(mailbox).remove(message.getUid());
     }
 
     /*
@@ -69,15 +70,15 @@ public class InMemoryMessageMapper imple
      * @see org.apache.james.imap.store.mail.MessageMapper#findInMailbox(java.lang.Object, org.apache.james.imap.mailbox.MessageRange)
      */
     @SuppressWarnings("unchecked")
-    public List<MailboxMembership<Long>> findInMailbox(Long mailboxId, MessageRange set) throws StorageException {
+    public List<MailboxMembership<Long>> findInMailbox(Mailbox<Long> mailbox, 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());
+                results = new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailbox).values());
                 break;
             case FROM:
-                results = new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailboxId).values());
+                results = new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailbox).values());
                 for (final Iterator<MailboxMembership<Long>> it=results.iterator();it.hasNext();) {
                    if (it.next().getUid()< set.getUidFrom()) {
                        it.remove(); 
@@ -85,7 +86,7 @@ public class InMemoryMessageMapper imple
                 }
                 break;
             case RANGE:
-                results = new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailboxId).values());
+                results = new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailbox).values());
                 for (final Iterator<MailboxMembership<Long>> it=results.iterator();it.hasNext();) {
                    final long uid = it.next().getUid();
                 if (uid<set.getUidFrom() || uid>set.getUidTo()) {
@@ -95,7 +96,7 @@ public class InMemoryMessageMapper imple
                 break;
             case ONE:
                 results  = new ArrayList<MailboxMembership<Long>>(1);
-                final MailboxMembership member = getMembershipByUidForMailbox(mailboxId).get(set.getUidFrom());
+                final MailboxMembership member = getMembershipByUidForMailbox(mailbox).get(set.getUidFrom());
                 if (member != null) {
                     results.add(member);
                 }
@@ -112,8 +113,8 @@ public class InMemoryMessageMapper imple
      * (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);
+    public List<MailboxMembership<Long>> findMarkedForDeletionInMailbox(Mailbox<Long> mailbox, MessageRange set) throws StorageException {
+        final List<MailboxMembership<Long>> results = findInMailbox(mailbox, set);
         for(final Iterator<MailboxMembership<Long>> it=results.iterator();it.hasNext();) {
             if (!it.next().isDeleted()) {
                 it.remove();
@@ -126,9 +127,9 @@ public class InMemoryMessageMapper imple
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MessageMapper#findRecentMessagesInMailbox()
      */
-    public List<MailboxMembership<Long>> findRecentMessagesInMailbox(Long mailboxId,int limit) throws StorageException {
+    public List<MailboxMembership<Long>> findRecentMessagesInMailbox(Mailbox<Long> mailbox,int limit) throws StorageException {
         final List<MailboxMembership<Long>> results = new ArrayList<MailboxMembership<Long>>();
-        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailboxId).values()) {
+        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailbox).values()) {
             if (member.isRecent()) {
                 results.add(member);
             }
@@ -144,9 +145,9 @@ public class InMemoryMessageMapper imple
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
      */
-    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox(Long mailboxId, int limit) throws StorageException {
+    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox(Mailbox<Long> mailbox, int limit) throws StorageException {
         final List<MailboxMembership<Long>> results = new ArrayList<MailboxMembership<Long>>();
-        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailboxId).values()) {
+        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailbox).values()) {
             if (!member.isSeen()) {
                 results.add(member);
             }
@@ -162,16 +163,16 @@ public class InMemoryMessageMapper imple
      * (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);
+    public void save(Mailbox<Long> mailbox, MailboxMembership<Long> message) throws StorageException {
+        getMembershipByUidForMailbox(mailbox).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());
+    public List<MailboxMembership<Long>> searchMailbox(Mailbox<Long> mailbox, SearchQuery query) throws StorageException {
+        return new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailbox).values());
     }
 
     /**
@@ -196,9 +197,9 @@ public class InMemoryMessageMapper imple
      * (non-Javadoc)
      * @see org.apache.james.imap.store.mail.MessageMapper#copy(java.lang.Object, long, org.apache.james.imap.store.mail.model.MailboxMembership)
      */
-    public MailboxMembership<Long> copy(Long mailboxId, long uid, MailboxMembership<Long> original) throws StorageException {
-        SimpleMailboxMembership membership = new SimpleMailboxMembership(mailboxId, uid, (SimpleMailboxMembership) original);
-        save(mailboxId, membership);
+    public MailboxMembership<Long> copy(Mailbox<Long> mailbox, long uid, MailboxMembership<Long> original) throws StorageException {
+        SimpleMailboxMembership membership = new SimpleMailboxMembership(mailbox.getMailboxId(), uid, (SimpleMailboxMembership) original);
+        save(mailbox, membership);
         return membership;
     }
     

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java?rev=980539&r1=980538&r2=980539&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java Thu Jul 29 18:43:47 2010
@@ -80,7 +80,7 @@ public abstract class StoreMessageManage
     
     private MessageMapper<Id> messageMapper;
 
-    private final Mailbox<Id> mailbox;
+    protected final Mailbox<Id> mailbox;
     
     private MailboxEventDispatcher dispatcher;
 
@@ -119,21 +119,12 @@ public abstract class StoreMessageManage
         return mailbox;
     }
 
-    /**
-     * Return the Id of the wrapped {@link Mailbox}
-     * 
-     * @return id
-     */
-    protected Id getMailboxId() {
-        return mailbox.getMailboxId();
-    }
-
     /*
      * (non-Javadoc)
      * @see org.apache.james.imap.mailbox.Mailbox#getMessageCount(org.apache.james.imap.mailbox.MailboxSession)
      */
     public int getMessageCount(MailboxSession mailboxSession) throws MailboxException {
-        return (int) messageMapper.countMessagesInMailbox(getMailboxId());
+        return (int) messageMapper.countMessagesInMailbox(mailbox);
     }
 
     /*
@@ -269,7 +260,7 @@ public abstract class StoreMessageManage
             messageMapper.execute(new TransactionalMapper.Transaction() {
                 
                 public void run() throws MailboxException {
-                    messageMapper.save(getMailboxId(), message);
+                    messageMapper.save(mailbox, message);
                 }
             });
            
@@ -371,7 +362,7 @@ public abstract class StoreMessageManage
     public Iterator<MessageResult> getMessages(final MessageRange set, FetchGroup fetchGroup,
             MailboxSession mailboxSession) throws MailboxException {
         UidRange range = uidRangeForMessageSet(set);
-        final List<MailboxMembership<Id>> rows = new ArrayList<MailboxMembership<Id>>(messageMapper.findInMailbox(getMailboxId(), set));
+        final List<MailboxMembership<Id>> rows = new ArrayList<MailboxMembership<Id>>(messageMapper.findInMailbox(mailbox, set));
         return getMessages(fetchGroup, range, rows);
     }
 
@@ -409,7 +400,7 @@ public abstract class StoreMessageManage
         messageMapper.execute(new TransactionalMapper.Transaction() {
 
             public void run() throws MailboxException {
-                final List<MailboxMembership<Id>> members = messageMapper.findRecentMessagesInMailbox(getMailboxId(), -1);
+                final List<MailboxMembership<Id>> members = messageMapper.findRecentMessagesInMailbox(mailbox, -1);
 
                 for (MailboxMembership<Id> member:members) {
                     results.add(member.getUid());
@@ -417,7 +408,7 @@ public abstract class StoreMessageManage
                         member.unsetRecent();
                         
                         // only call save if we need to
-                        messageMapper.save(getMailboxId(), member);
+                        messageMapper.save(mailbox, member);
                     }
                 }
             }
@@ -429,7 +420,7 @@ public abstract class StoreMessageManage
 
     private Long getFirstUnseen(MailboxSession mailboxSession) throws MailboxException {
         try {
-            final List<MailboxMembership<Id>> members = messageMapper.findUnseenMessagesInMailbox(getMailboxId(),1);
+            final List<MailboxMembership<Id>> members = messageMapper.findUnseenMessagesInMailbox(mailbox,1);
             final Iterator<MailboxMembership<Id>> it = members.iterator();
             final Long result;
             if (it.hasNext()) {
@@ -445,7 +436,7 @@ public abstract class StoreMessageManage
     }
 
     private int getUnseenCount(MailboxSession mailboxSession) throws MailboxException {
-        final int count = (int) messageMapper.countUnseenMessagesInMailbox(getMailboxId());
+        final int count = (int) messageMapper.countUnseenMessagesInMailbox(mailbox);
         return count;
     }
 
@@ -464,10 +455,10 @@ public abstract class StoreMessageManage
         messageMapper.execute(new TransactionalMapper.Transaction() {
 
             public void run() throws MailboxException {
-                final List<MailboxMembership<Id>> members = messageMapper.findMarkedForDeletionInMailbox(getMailboxId(), set);
+                final List<MailboxMembership<Id>> members = messageMapper.findMarkedForDeletionInMailbox(mailbox, set);
                 for (MailboxMembership<Id> message:members) {
                     uids.add(message.getUid());
-                    messageMapper.delete(getMailboxId(), message);
+                    messageMapper.delete(mailbox, message);
                 }  
             }
             
@@ -496,7 +487,7 @@ public abstract class StoreMessageManage
         messageMapper.execute(new TransactionalMapper.Transaction(){
 
             public void run() throws MailboxException {
-                final List<MailboxMembership<Id>> members = messageMapper.findInMailbox(getMailboxId(), set);
+                final List<MailboxMembership<Id>> members = messageMapper.findInMailbox(mailbox, set);
                 for (final MailboxMembership<Id> member:members) {
                     originalFlagsByUid.put(member.getUid(), member.createFlags());
                     if (replace) {
@@ -511,7 +502,7 @@ public abstract class StoreMessageManage
                         member.setFlags(current);
                     }
                     newFlagsByUid.put(member.getUid(), member.createFlags());
-                    messageMapper.save(getMailboxId(), member);
+                    messageMapper.save(mailbox, member);
                 }
             }
             
@@ -550,7 +541,7 @@ public abstract class StoreMessageManage
      * @see org.apache.james.imap.mailbox.Mailbox#search(org.apache.james.imap.mailbox.SearchQuery, org.apache.james.imap.mailbox.MailboxSession)
      */
     public Iterator<Long> search(SearchQuery query, MailboxSession mailboxSession) throws MailboxException {
-        final List<MailboxMembership<Id>> members = messageMapper.searchMailbox(getMailboxId(), query);
+        final List<MailboxMembership<Id>> members = messageMapper.searchMailbox(mailbox, query);
         final Set<Long> uids = new TreeSet<Long>();
         for (MailboxMembership<Id> member:members) {
             try {
@@ -588,7 +579,7 @@ public abstract class StoreMessageManage
                 messageMapper.execute(new TransactionalMapper.Transaction() {
 
                     public void run() throws MailboxException {
-                        final MailboxMembership<Id> newRow = messageMapper.copy(getMailboxId(), uid, originalMessage);
+                        final MailboxMembership<Id> newRow = messageMapper.copy(mailbox, uid, originalMessage);
                         copiedRows.add(newRow);
                     }
                     
@@ -613,7 +604,7 @@ public abstract class StoreMessageManage
      */
     public void copyTo(MessageRange set, StoreMessageManager<Id> toMailbox, MailboxSession session) throws MailboxException {
         try {
-            final List<MailboxMembership<Id>> originalRows = messageMapper.findInMailbox(getMailboxId(), set);
+            final List<MailboxMembership<Id>> originalRows = messageMapper.findInMailbox(mailbox, set);
             toMailbox.copy(originalRows, session);
 
         } catch (MessagingException e) {

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java?rev=980539&r1=980538&r2=980539&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java Thu Jul 29 18:43:47 2010
@@ -20,16 +20,16 @@ package org.apache.james.imap.store.mail
 
 import java.util.List;
 
-import org.apache.james.imap.mailbox.Mailbox;
 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.mail.model.Document;
+import org.apache.james.imap.store.mail.model.Mailbox;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
 import org.apache.james.imap.store.transaction.TransactionalMapper;
 
 /**
- * Maps {@link Document} in a {@link Mailbox}. A {@link MessageMapper} has a lifecycle from the start of a request 
+ * Maps {@link Document} in a {@link org.apache.james.imap.mailbox.Mailbox}. A {@link MessageMapper} has a lifecycle from the start of a request 
  * to the end of the request.
  */
 public interface MessageMapper<Id> extends TransactionalMapper {
@@ -38,58 +38,64 @@ public interface MessageMapper<Id> exten
      * Return a List of {@link MailboxMembership} which represent the given {@link MessageRange}
      * The list must be ordered by the {@link Document} uid
      * 
+     * @param mailbox The mailbox to search
      * @param set
      * @return list
      * @throws StorageException
      */
-    public abstract List<MailboxMembership<Id>> findInMailbox(Id mailboxId, MessageRange set)
+    public abstract List<MailboxMembership<Id>> findInMailbox(Mailbox<Id> mailbox, MessageRange set)
             throws StorageException;
 
     /**
      * Return a List of {@link MailboxMembership} for the given {@link MessageRange} which are marked for deletion
      * The list must be ordered by the {@link Document} uid
+     * @param mailbox
      * @param set 
      * @return list
      * @throws StorageException
      */
     public abstract List<MailboxMembership<Id>> findMarkedForDeletionInMailbox(
-            Id mailboxId, final MessageRange set)
+            Mailbox<Id> mailbox, final MessageRange set)
             throws StorageException;
 
     /**
      * Return the count of messages in the mailbox
      * 
+     * @param mailbox
      * @return count
      * @throws StorageException
      */
-    public abstract long countMessagesInMailbox(Id mailboxId)
+    public abstract long countMessagesInMailbox(Mailbox<Id> mailbox)
             throws StorageException;
 
     /**
      * Return the count of unseen messages in the mailbox
      * 
+     * @param mailbox
      * @return unseenCount
      * @throws StorageException
      */
-    public abstract long countUnseenMessagesInMailbox(Id mailboxId)
+    public abstract long countUnseenMessagesInMailbox(Mailbox<Id> mailbox)
             throws StorageException;
 
     /**
      * Return a List of {@link MailboxMembership} which matched the {@link SearchQuery}
      * The list must be ordered by the {@link Document} uid
+     * @param mailbox
      * @param query
      * @return
      * @throws StorageException
      */
-    public abstract List<MailboxMembership<Id>> searchMailbox(Id mailboxId, SearchQuery query) throws StorageException;
+    public abstract List<MailboxMembership<Id>> searchMailbox(Mailbox<Id> mailbox, SearchQuery query) throws StorageException;
 
     /**
      * Delete the given {@link MailboxMembership}
      * 
+     * @param mailbox
      * @param message
      * @throws StorageException
      */
-    public abstract void delete(Id mailboxId, MailboxMembership<Id> message) throws StorageException;
+    public abstract void delete(Mailbox<Id> mailbox, MailboxMembership<Id> message) throws StorageException;
 
     /**
      * Return a List of {@link MailboxMembership} which are unseen. 
@@ -97,12 +103,12 @@ public interface MessageMapper<Id> exten
      * If a limit was given the list will maximal be the size of the limit. Id a 
      * limit smaller then 1 is given the List must contain all messages
      * 
-     * @param mailboxId
+     * @param mailbox
      * @param limit
      * @return list
      * @throws StorageException
      */
-    public abstract List<MailboxMembership<Id>> findUnseenMessagesInMailbox(Id mailboxId, int limit) throws StorageException;
+    public abstract List<MailboxMembership<Id>> findUnseenMessagesInMailbox(Mailbox<Id> mailbox, int limit) throws StorageException;
 
     /**
      * Return a List of {@link MailboxMembership} which are recent.
@@ -110,32 +116,33 @@ public interface MessageMapper<Id> exten
      * If a limit was given the list will maximal be the size of the limit. Id a 
      * limit smaller then 1 is given the List must contain all messages
      * 
-     * @param mailboxId
+     * @param mailbox
      * @param limit
      * @return recentList
      * @throws StorageException
      */
-    public abstract List<MailboxMembership<Id>> findRecentMessagesInMailbox(Id mailboxId, int limit) throws StorageException;
+    public abstract List<MailboxMembership<Id>> findRecentMessagesInMailbox(Mailbox<Id> mailbox, int limit) throws StorageException;
 
 
     /**
      * Save the given {@link MailboxMembership} to the underlying storage
      * 
+     * @param mailbox
      * @param message
      * @throws StorageException
      */
-    public abstract void save(Id mailboxId, MailboxMembership<Id> message) throws StorageException;
+    public abstract void save(Mailbox<Id> mailbox, MailboxMembership<Id> message) throws StorageException;
     
     
     /**
      * Copy the given {@link MailboxMembership} to a new mailbox
      * 
-     * @param mailboxId the id of the mailbox to copy to
-     * @param uid the uid to use for the new mailboxmembership
+     * @param mailbox the Mailbox to copy to
+     * @param uid the uid to use for the new MailboxMembership
      * @param original the original to copy
-     * @return membership. The copied instance
+     * @return The copied instance
      * @throws StorageException
      */
-    public abstract MailboxMembership<Id> copy(Id mailboxId, long uid, MailboxMembership<Id> original) throws StorageException;
+    public abstract MailboxMembership<Id> copy(Mailbox<Id> mailbox, long uid, MailboxMembership<Id> original) throws StorageException;
 
 }
\ No newline at end of file



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