james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r940314 - in /james/imap/trunk: jcr/src/main/java/org/apache/james/imap/jcr/ jcr/src/main/java/org/apache/james/imap/jcr/mail/ jcr/src/main/resources/org/apache/james/imap/jcr/ jpa/src/main/java/org/apache/james/imap/jpa/ jpa/src/main/java/...
Date Sun, 02 May 2010 19:42:08 GMT
Author: norman
Date: Sun May  2 19:42:07 2010
New Revision: 940314

URL: http://svn.apache.org/viewvc?rev=940314&view=rev
Log:
More refactoring to simplify api

Added:
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.java
Modified:
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
    james/imap/trunk/jcr/src/main/resources/org/apache/james/imap/jcr/imap.cnd
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java?rev=940314&r1=940313&r2=940314&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailbox.java Sun May 
2 19:42:07 2010
@@ -43,11 +43,13 @@ import org.apache.james.imap.mailbox.Sub
 import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.PasswordAwareUser;
 import org.apache.james.imap.store.StoreMailbox;
+import org.apache.james.imap.store.mail.MailboxMapper;
 import org.apache.james.imap.store.mail.MessageMapper;
 import org.apache.james.imap.store.mail.model.Header;
 import org.apache.james.imap.store.mail.model.Mailbox;
 import org.apache.james.imap.store.mail.model.MailboxMembership;
 import org.apache.james.imap.store.mail.model.PropertyBuilder;
+import org.apache.james.imap.store.transaction.TransactionalMapper;
 
 /**
  * JCR implementation of a {@link StoreMailbox}
@@ -59,7 +61,7 @@ public class JCRMailbox extends StoreMai
     private final String workspace;
     private final Log log;
     private final int scaling;
-    
+
     public JCRMailbox(final MailboxEventDispatcher dispatcher, final org.apache.james.imap.jcr.mail.model.JCRMailbox
mailbox, final Repository repository, final String workspace, final int scaling, final Log
log) {
         super(dispatcher, mailbox);
         this.repository = repository;
@@ -117,6 +119,7 @@ public class JCRMailbox extends StoreMai
      * 
      * @param session
      * @return mailboxMapper
+     * @throws MailboxException 
      * @throws MailboxException
      */
     protected JCRMailboxMapper createMailboxMapper(MailboxSession session) throws MailboxException
{
@@ -125,17 +128,19 @@ public class JCRMailbox extends StoreMai
         return mapper;
 
     }
-    
-    @Override
-    protected Mailbox<String> getMailboxRow(MailboxSession session) throws MailboxException
{
-        final JCRMailboxMapper mapper = createMailboxMapper(session);
-        return mapper.findMailboxById(getMailboxId());
-    }
 
     @Override
     protected Mailbox<String> reserveNextUid(MailboxSession session) throws MailboxException
{
-        final JCRMailboxMapper mapper = createMailboxMapper(session);
-        return mapper.consumeNextUid(getMailboxId());
+        final MailboxMapper<String> mapper = getMailboxMapperForRequest(session);
+        final org.apache.james.imap.jcr.mail.model.JCRMailbox mailbox = (org.apache.james.imap.jcr.mail.model.JCRMailbox)
mapper.findMailboxById(getMailboxId());
+        mapper.execute(new TransactionalMapper.Transaction() {
+
+            public void run() throws MailboxException {
+                mailbox.consumeUid();
+            }
+            
+        });
+        return mailbox;
     }
 
     /**

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java?rev=940314&r1=940313&r2=940314&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
(original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
Sun May  2 19:42:07 2010
@@ -238,29 +238,4 @@ public class JCRMailboxMapper extends Ab
             throw new StorageException(HumanReadableText.SAVE_FAILED, e);
         }
     }
-    
-    /**
-     * Consume the next uid for the {@link Mailbox} with the given uuid
-     * 
-     * @param uuid
-     * @return mailbox
-     * @throws StorageException
-     * @throws MailboxNotFoundException
-     */
-    public Mailbox<String> consumeNextUid(String uuid) throws StorageException, MailboxNotFoundException
{
-
-        final JCRMailbox mailbox = (JCRMailbox) findMailboxById(uuid);
-        try {
-            execute(new Transaction() {
-                
-                public void run() throws MailboxException {
-                    mailbox.consumeUid();
-                }
-            });
-        } catch (MailboxException e) {
-            throw (StorageException)e;
-        }
-        return mailbox;
-
-    }
 }

Modified: james/imap/trunk/jcr/src/main/resources/org/apache/james/imap/jcr/imap.cnd
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/resources/org/apache/james/imap/jcr/imap.cnd?rev=940314&r1=940313&r2=940314&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/resources/org/apache/james/imap/jcr/imap.cnd (original)
+++ james/imap/trunk/jcr/src/main/resources/org/apache/james/imap/jcr/imap.cnd Sun May  2
19:42:07 2010
@@ -47,7 +47,7 @@
  [imap:messageProperties] > nt:unstructured
     + imap:messageProperty multiple
        
-[imap:mailbox] >  mix:referenceable, nt:base
+[imap:mailbox] >  mix:referenceable, mix:lockable, nt:base
     - imap:mailboxUidValidity (LONG) mandatory
     - imap:mailboxName (STRING) mandatory
     - imap:mailboxLastUid (LONG) mandatory

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java?rev=940314&r1=940313&r2=940314&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java Sun May 
2 19:42:07 2010
@@ -55,19 +55,8 @@ public abstract class JPAMailbox extends
         super(dispatcher, mailbox);
         this.entityManagerFactory = entityManagerfactory;        
     }  
-    
-    /**
-     * Create MailboxMapper 
-     * 
-     * @return mapper
-     */
-    protected abstract JPAMailboxMapper createMailboxMapper(MailboxSession session);
 
-    @Override
-    protected Mailbox<Long> getMailboxRow(MailboxSession session) throws MailboxException
{
-        final MailboxMapper<Long> mapper = createMailboxMapper(session);
-        return mapper.findMailboxById(getMailboxId());
-    }
+
 
     
     @Override
@@ -101,4 +90,14 @@ public abstract class JPAMailbox extends
         final Header header = new JPAHeader(lineNumber, name, value);
         return header;
     }
+
+
+
+
+    @Override
+    protected MailboxMapper<Long> createMailboxMapper(MailboxSession session) {
+        return new JPAMailboxMapper(entityManagerFactory);
+    }
+    
+    
 }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java?rev=940314&r1=940313&r2=940314&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java
(original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java
Sun May  2 19:42:07 2010
@@ -30,7 +30,6 @@ import javax.persistence.EntityTransacti
 import javax.persistence.Query;
 
 import org.apache.james.imap.jpa.JPAMailbox;
-import org.apache.james.imap.jpa.mail.JPAMailboxMapper;
 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;
@@ -60,16 +59,6 @@ public class OpenJPAMailbox extends JPAM
         this.useStreaming = useStreaming;
     }
 
-    /*
-     * (non-Javadoc)
-     * @see org.apache.james.imap.jpa.JPAMailbox#createMailboxMapper(org.apache.james.imap.mailbox.MailboxSession)
-     */
-	protected JPAMailboxMapper createMailboxMapper(MailboxSession session) {	    	    
-        JPAMailboxMapper mapper = new JPAMailboxMapper(entityManagerFactory);
-
-        return mapper;
-    }
-
     @Override
     protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage,
long uid, MailboxSession session) throws MailboxException {
         if (useStreaming) {

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java?rev=940314&r1=940313&r2=940314&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
(original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryStoreMailbox.java
Sun May  2 19:42:07 2010
@@ -39,6 +39,7 @@ import org.apache.james.imap.mailbox.Sto
 import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.store.MailboxMembershipComparator;
 import org.apache.james.imap.store.StoreMailbox;
+import org.apache.james.imap.store.mail.MailboxMapper;
 import org.apache.james.imap.store.mail.MessageMapper;
 import org.apache.james.imap.store.mail.model.Header;
 import org.apache.james.imap.store.mail.model.Mailbox;
@@ -97,10 +98,6 @@ public class InMemoryStoreMailbox extend
         return this;
     }
 
-    @Override
-    protected Mailbox<Long> getMailboxRow(MailboxSession session) throws MailboxException
{
-        return mailbox;
-    }
 
     @Override
     protected Mailbox<Long> reserveNextUid(MailboxSession session) throws MailboxException
{
@@ -257,4 +254,18 @@ public class InMemoryStoreMailbox extend
     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> getMailboxRow(MailboxSession session) throws MailboxException
{
+        return mailbox;
+    }
+
+    
 }

Added: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.java?rev=940314&view=auto
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.java (added)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.java Sun
May  2 19:42:07 2010
@@ -0,0 +1,29 @@
+/****************************************************************
+ * 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.store;
+
+public interface StoreConstants {
+
+    public final static String MAILBOX_MAPPER = "MAILBOX_MAPPER"; 
+    
+    public final static String MESSAGE_MAPPER = "MESSAGE_MAPPER";
+
+    public static final String USER_NAMESPACE_PREFIX = "#mail";
+
+}

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java?rev=940314&r1=940313&r2=940314&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailbox.java Sun
May  2 19:42:07 2010
@@ -53,6 +53,7 @@ import org.apache.james.imap.mailbox.Sea
 import org.apache.james.imap.mailbox.MessageResult.FetchGroup;
 import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
 import org.apache.james.imap.mailbox.util.UidRange;
+import org.apache.james.imap.store.mail.MailboxMapper;
 import org.apache.james.imap.store.mail.MessageMapper;
 import org.apache.james.imap.store.mail.model.Header;
 import org.apache.james.imap.store.mail.model.Mailbox;
@@ -73,7 +74,7 @@ import com.sun.mail.imap.protocol.Messag
  * 
  *
  */
-public abstract class StoreMailbox<Id> implements org.apache.james.imap.mailbox.Mailbox
{
+public abstract class StoreMailbox<Id> implements org.apache.james.imap.mailbox.Mailbox,
StoreConstants {
 
     private static final int INITIAL_SIZE_FLAGS = 32;
 
@@ -83,7 +84,6 @@ public abstract class StoreMailbox<Id> i
     
     private MailboxEventDispatcher dispatcher;
     
-    public final static String MESSAGE_MAPPER = "MESSAGE_MAPPER";
     
     public StoreMailbox(final MailboxEventDispatcher dispatcher, final Mailbox<Id>
mailbox) {
         this.mailboxId = mailbox.getMailboxId();
@@ -140,7 +140,11 @@ public abstract class StoreMailbox<Id> i
      * @return mailbox
      * @throws MailboxException
      */
-    protected abstract Mailbox<Id> getMailboxRow(MailboxSession session) throws MailboxException;
+    
+    protected Mailbox<Id> getMailboxRow(MailboxSession session) throws MailboxException
{
+        final MailboxMapper<Id> mapper = getMailboxMapperForRequest(session);
+        return mapper.findMailboxById(getMailboxId());
+    }
 
     /**
      * Return the Id of the wrapped {@link Mailbox}
@@ -715,4 +719,29 @@ public abstract class StoreMailbox<Id> i
         return new MailboxMetaData(recent, permanentFlags, uidValidity, uidNext, messageCount,
unseenCount, firstUnseen, isWriteable());
     }
     
+    
+    /**
+     * Create MailboxMapper 
+     * 
+     * @return mapper
+     */
+    protected abstract MailboxMapper<Id> createMailboxMapper(MailboxSession session)
throws MailboxException;
+    
+    /**
+     * Return the {@link MailboxMapper} for the current Request. If none exists, it will
get created.
+     * 
+     * @param session
+     * @return mapper
+     * @throws MailboxException
+     */
+    @SuppressWarnings("unchecked")
+    public MailboxMapper<Id> getMailboxMapperForRequest(MailboxSession session) throws
MailboxException {
+        MailboxMapper<Id> mapper = (MailboxMapper<Id>) session.getAttributes().get(MAILBOX_MAPPER);
+        if (mapper == null) {
+            mapper = createMailboxMapper(session);
+            session.getAttributes().put(MAILBOX_MAPPER, mapper);
+        }
+        return mapper;
+    }
+
 }

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java?rev=940314&r1=940313&r2=940314&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
(original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
Sun May  2 19:42:07 2010
@@ -59,8 +59,7 @@ import org.apache.james.imap.store.trans
  *
  * @param <Id>
  */
-public abstract class StoreMailboxManager<Id> extends AbstractLogEnabled implements
MailboxManager {
-    public static final String USER_NAMESPACE_PREFIX = "#mail";
+public abstract class StoreMailboxManager<Id> extends AbstractLogEnabled implements
MailboxManager, StoreConstants {
     
     public static final char SQL_WILDCARD_CHAR = '%';
 
@@ -72,7 +71,6 @@ public abstract class StoreMailboxManage
     private final DelegatingMailboxListener delegatingListener = new DelegatingMailboxListener();
     private final Authenticator authenticator;    
     private final Subscriber subscriber;    
-    private final static String MAILBOX_MAPPER = "MAILBOX_MAPPER"; 
     private final char delimiter;
     
     public StoreMailboxManager(final Authenticator authenticator, final Subscriber subscriber)
{



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