You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2010/04/08 16:10:42 UTC

svn commit: r931951 - in /james/imap/trunk: deployment/src/test/java/org/apache/james/imap/functional/jpa/ jcr/src/main/java/org/apache/james/imap/jcr/mail/model/ jpa/ jpa/src/main/java/org/apache/james/imap/jpa/ jpa/src/main/java/org/apache/james/imap...

Author: norman
Date: Thu Apr  8 14:10:41 2010
New Revision: 931951

URL: http://svn.apache.org/viewvc?rev=931951&view=rev
Log:
Allow to use "direct" streams via OpenJPA to improve performance (IMAP-128)

Added:
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMailboxMembership.java
      - copied, changed from r931782, james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMailboxMembership.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/AbstractRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InMemoryRewindableInputStream.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/FileRewindableInputStreamTest.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/InMemoryRewindableInputStreamTest.java
Modified:
    james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java
    james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java
    james/imap/trunk/jpa/pom.xml
    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/JPAMailboxManager.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMessage.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMessage.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailbox.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/openjpa/OpenJPAMailboxManager.java
    james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
    james/imap/trunk/parent/pom.xml
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/RewindableInputStreamTest.java
    james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java

Modified: james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java (original)
+++ james/imap/trunk/deployment/src/test/java/org/apache/james/imap/functional/jpa/JPAHostSystem.java Thu Apr  8 14:10:41 2010
@@ -56,6 +56,7 @@ public class JPAHostSystem extends ImapH
         properties.put("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)");
         properties.put("openjpa.MetaDataFactory", "jpa(Types=org.apache.james.imap.jpa.mail.model.JPAHeader;" +
                 "org.apache.james.imap.jpa.mail.model.JPAMailbox;" +
+                "org.apache.james.imap.jpa.mail.model.AbstractJPAMailboxMembership;" +
                 "org.apache.james.imap.jpa.mail.model.JPAMailboxMembership;" +
                 "org.apache.james.imap.jpa.mail.model.AbstractJPAMessage;" +
                 "org.apache.james.imap.jpa.mail.model.JPAMessage;" +

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java (original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/model/JCRMessage.java Thu Apr  8 14:10:41 2010
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.JcrConstant
 import org.apache.james.imap.jcr.JCRImapConstants;
 import org.apache.james.imap.jcr.JCRUtils;
 import org.apache.james.imap.jcr.Persistent;
+import org.apache.james.imap.store.DelegatingRewindableInputStream;
 import org.apache.james.imap.store.LazySkippingInputStream;
 import org.apache.james.imap.store.RewindableInputStream;
 import org.apache.james.imap.store.StreamUtils;
@@ -132,7 +133,7 @@ public class JCRMessage extends Abstract
      * @see org.apache.james.imap.store.mail.model.Document#getFullContent()
      */
     public RewindableInputStream getFullContent() throws IOException {
-        return new RewindableInputStream(getFullContentInternal());
+        return new DelegatingRewindableInputStream(getFullContentInternal(), getFullContentOctets());
     }
     
     
@@ -427,7 +428,7 @@ public class JCRMessage extends Abstract
      * @see org.apache.james.imap.store.mail.model.Document#getBodyContent()
      */
     public RewindableInputStream getBodyContent() throws IOException {
-        return new RewindableInputStream(new LazySkippingInputStream(getFullContentInternal(), getBodyStartOctet()));
+        return new DelegatingRewindableInputStream(new LazySkippingInputStream(getFullContentInternal(), getBodyStartOctet()), getFullContentOctets());
     }
 
 

Modified: james/imap/trunk/jpa/pom.xml
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/pom.xml?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/jpa/pom.xml (original)
+++ james/imap/trunk/jpa/pom.xml Thu Apr  8 14:10:41 2010
@@ -92,7 +92,7 @@
         <artifactId>openjpa-maven-plugin</artifactId>
         <version>1.0</version>
         <configuration>
-          <includes>org/apache/james/imap/jpa/*/model/*.class</includes>
+          <includes>org/apache/james/imap/jpa/*/model/**/*.class</includes>
           <addDefaultConstructor>true</addDefaultConstructor>
           <enforcePropertyRestrictions>true</enforcePropertyRestrictions>
           <toolProperties>
@@ -102,7 +102,7 @@
             </property>   
             <property>
               <name>metaDataFactory</name>
-              <value>jpa(Types=org.apache.james.imap.jpa.mail.model.JPAHeader;org.apache.james.imap.jpa.mail.model.JPAMailbox;org.apache.james.imap.jpa.mail.model.JPAMailboxMembership;org.apache.james.imap.jpa.mail.model.AbstractJPAMessage;org.apache.james.imap.jpa.mail.model.JPAMessage;org.apache.james.imap.jpa.mail.model.openjpa.JPAStreamingMessage;org.apache.james.imap.jpa.mail.model.JPAProperty;org.apache.james.imap.jpa.user.model.JPASubscription)</value>
+              <value>jpa(Types=org.apache.james.imap.jpa.mail.model.JPAHeader;org.apache.james.imap.jpa.mail.model.JPAMailbox;org.apache.james.imap.jpa.mail.model.AbstractJPAMailboxMembership;org.apache.james.imap.jpa.mail.model.JPAMailboxMembership;org.apache.james.imap.jpa.mail.model.openjpa.JPAStreamingMailboxMembership;org.apache.james.imap.jpa.mail.model.AbstractJPAMessage;org.apache.james.imap.jpa.mail.model.JPAMessage;org.apache.james.imap.jpa.mail.model.openjpa.JPAStreamingMessage;org.apache.james.imap.jpa.mail.model.JPAProperty;org.apache.james.imap.jpa.user.model.JPASubscription)</value>
             </property>           
           </toolProperties>
         </configuration>

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=931951&r1=931950&r2=931951&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 Thu Apr  8 14:10:41 2010
@@ -29,6 +29,7 @@ import javax.persistence.EntityManagerFa
 
 import org.apache.james.imap.jpa.mail.JPAMailboxMapper;
 import org.apache.james.imap.jpa.mail.JPAMessageMapper;
+import org.apache.james.imap.jpa.mail.model.AbstractJPAMailboxMembership;
 import org.apache.james.imap.jpa.mail.model.JPAHeader;
 import org.apache.james.imap.jpa.mail.model.JPAMailboxMembership;
 import org.apache.james.imap.mailbox.MailboxException;
@@ -49,12 +50,12 @@ import org.apache.james.imap.store.mail.
 public abstract class JPAMailbox extends StoreMailbox<Long> {
 
     protected final EntityManagerFactory entityManagerFactory;
-
+    
     public JPAMailbox(final Mailbox<Long> mailbox, MailboxSession session, final EntityManagerFactory entityManagerfactory) {
         super(mailbox, session);
-        this.entityManagerFactory = entityManagerfactory;
-    }    
-
+        this.entityManagerFactory = entityManagerfactory;        
+    }  
+    
     /**
      * Create MailboxMapper 
      * 
@@ -87,14 +88,15 @@ public abstract class JPAMailbox extends
         for (Header header: headers) {
             jpaHeaders.add((JPAHeader) header);
         }
-        final MailboxMembership<Long> message = new JPAMailboxMembership(mailboxId, uid, internalDate, 
-                size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
+        final MailboxMembership<Long> message = new JPAMailboxMembership(mailboxId, uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
         return message;
+
+       
     }
     
     @Override
     protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid) throws MailboxException{
-        MailboxMembership<Long> newRow = new JPAMailboxMembership(getMailboxId(), uid, (JPAMailboxMembership) originalMessage);
+        final MailboxMembership<Long> newRow = new JPAMailboxMembership(getMailboxId(), uid, (AbstractJPAMailboxMembership) originalMessage);
         return newRow;
     }
     

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java Thu Apr  8 14:10:41 2010
@@ -61,6 +61,7 @@ public abstract class JPAMailboxManager 
             
         });
     }
+
     
     /**
      * Delete every Mailbox which exists

Copied: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMailboxMembership.java (from r931782, james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java)
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMailboxMembership.java?p2=james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMailboxMembership.java&p1=james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java&r1=931782&r2=931951&rev=931951&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/AbstractJPAMailboxMembership.java Thu Apr  8 14:10:41 2010
@@ -19,30 +19,24 @@
 package org.apache.james.imap.jpa.mail.model;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.Serializable;
 import java.util.Date;
 import java.util.List;
 
 import javax.mail.Flags;
 import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
 import javax.persistence.Id;
 import javax.persistence.IdClass;
-import javax.persistence.ManyToOne;
+import javax.persistence.MappedSuperclass;
 import javax.persistence.NamedQueries;
 import javax.persistence.NamedQuery;
 
-import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.mailbox.MailboxException;
 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.PropertyBuilder;
 
-@Entity(name="Membership")
-@IdClass(JPAMailboxMembership.MailboxIdUidKey.class)
+@MappedSuperclass
+@IdClass(AbstractJPAMailboxMembership.MailboxIdUidKey.class)
 @NamedQueries({
     @NamedQuery(name="findRecentMessagesInMailbox",
             query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.recent = TRUE"),
@@ -69,7 +63,7 @@ import org.apache.james.imap.store.mail.
     @NamedQuery(name="countMessagesInMailbox",
             query="SELECT COUNT(membership) FROM Membership membership WHERE membership.mailboxId = :idParam")                     
 })
-public class JPAMailboxMembership extends AbstractMailboxMembership<Long> {
+public abstract class AbstractJPAMailboxMembership extends AbstractMailboxMembership<Long> {
 
     private static final String TOSTRING_SEPARATOR = " ";
 
@@ -139,27 +133,20 @@ public class JPAMailboxMembership extend
     /** The value for the seen field */
     @Basic(optional=false) private boolean seen = false;
 
-    /** The value for the body field. Lazy loaded */
-    @ManyToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY) private JPAMessage message;
     
     /**
      * For enhancement only.
      */
     @Deprecated
-    public JPAMailboxMembership() {}
+    public AbstractJPAMailboxMembership() {}
 
-    public JPAMailboxMembership(long mailboxId, long uid, Date internalDate, int size, Flags flags, 
-            InputStream content, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws MailboxException {
+    public AbstractJPAMailboxMembership(long mailboxId, long uid, Date internalDate, int size, Flags flags, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws MailboxException {
         super();
         this.mailboxId = mailboxId;
         this.uid = uid;
         this.internalDate = internalDate;
         this.size = size;
-        try {
-            this.message = new JPAMessage(content, size, bodyStartOctet, headers, propertyBuilder);
-        } catch (IOException e) {
-            throw new MailboxException(HumanReadableText.FAILURE_MAILBOX_EXISTS,e);
-        }
+       
         setFlags(flags);
     }
 
@@ -171,7 +158,7 @@ public class JPAMailboxMembership extend
      * @param original message to be copied, not null
      * @throws IOException 
      */
-    public JPAMailboxMembership(long mailboxId, long uid, JPAMailboxMembership original) throws MailboxException {
+    public AbstractJPAMailboxMembership(long mailboxId, long uid, AbstractJPAMailboxMembership original) throws MailboxException {
         super();
         this.mailboxId = mailboxId;
         this.uid = uid;
@@ -183,11 +170,6 @@ public class JPAMailboxMembership extend
         this.flagged = original.isFlagged();
         this.recent = original.isRecent();
         this.seen = original.isSeen();
-        try {
-            this.message = new JPAMessage((JPAMessage) original.getDocument());
-        } catch (IOException e) {
-            throw new MailboxException(HumanReadableText.FAILURE_MAILBOX_EXISTS,e);
-        }
     }
 
     /**
@@ -260,14 +242,7 @@ public class JPAMailboxMembership extend
         return seen;
     }
     
-    /**
-     * Gets the message member.
-     * @return message, not null
-     */
-    public Document getDocument() {
-        return message;
-    }
-    
+  
     /**
      * @see org.apache.james.imap.store.mail.model.MailboxMembership#unsetRecent()
      */
@@ -306,7 +281,7 @@ public class JPAMailboxMembership extend
             return false;
         if (getClass() != obj.getClass())
             return false;
-        final JPAMailboxMembership other = (JPAMailboxMembership) obj;
+        final AbstractJPAMailboxMembership other = (AbstractJPAMailboxMembership) obj;
         if (mailboxId != other.mailboxId)
             return false;
         if (uid != other.uid)

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java (original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailboxMembership.java Thu Apr  8 14:10:41 2010
@@ -1,335 +1,79 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-package org.apache.james.imap.jpa.mail.model;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Serializable;
-import java.util.Date;
-import java.util.List;
-
-import javax.mail.Flags;
-import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.Id;
-import javax.persistence.IdClass;
-import javax.persistence.ManyToOne;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-
-import org.apache.james.imap.api.display.HumanReadableText;
-import org.apache.james.imap.mailbox.MailboxException;
-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.PropertyBuilder;
-
-@Entity(name="Membership")
-@IdClass(JPAMailboxMembership.MailboxIdUidKey.class)
-@NamedQueries({
-    @NamedQuery(name="findRecentMessagesInMailbox",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.recent = TRUE"),
-    @NamedQuery(name="findUnseenMessagesInMailboxOrderByUid",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.seen = FALSE ORDER BY membership.uid ASC"),
-    @NamedQuery(name="findMessagesInMailbox",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam"),
-    @NamedQuery(name="findMessagesInMailboxBetweenUIDs",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid BETWEEN :fromParam AND :toParam"),        
-    @NamedQuery(name="findMessagesInMailboxWithUID",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid=:uidParam"),                    
-    @NamedQuery(name="findMessagesInMailboxAfterUID",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid>=:uidParam"),                    
-    @NamedQuery(name="findDeletedMessagesInMailbox",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.deleted=TRUE"),                   
-    @NamedQuery(name="findDeletedMessagesInMailboxBetweenUIDs",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid BETWEEN :fromParam AND :toParam AND membership.deleted=TRUE"),        
-    @NamedQuery(name="findDeletedMessagesInMailboxWithUID",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid=:uidParam AND membership.deleted=TRUE"),                    
-    @NamedQuery(name="findDeletedMessagesInMailboxAfterUID",
-            query="SELECT membership FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.uid>=:uidParam AND membership.deleted=TRUE"),                    
-    @NamedQuery(name="countUnseenMessagesInMailbox",
-            query="SELECT COUNT(membership) FROM Membership membership WHERE membership.mailboxId = :idParam AND membership.seen=FALSE"),                     
-    @NamedQuery(name="countMessagesInMailbox",
-            query="SELECT COUNT(membership) FROM Membership membership WHERE membership.mailboxId = :idParam")                     
-})
-public class JPAMailboxMembership extends AbstractMailboxMembership<Long> {
-
-    private static final String TOSTRING_SEPARATOR = " ";
-
-    /** Identifies composite key */
-    public static class MailboxIdUidKey implements Serializable {
-        private static final long serialVersionUID = 7847632032426660997L;
-        /** The value for the mailboxId field */
-        public long mailboxId;
-        /** The value for the uid field */
-        public long uid;
-
-        public MailboxIdUidKey() {}
-
-        @Override
-        public int hashCode() {
-            final int PRIME = 31;
-            int result = 1;
-            result = PRIME * result + (int) (mailboxId ^ (mailboxId >>> 32));
-            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 MailboxIdUidKey other = (MailboxIdUidKey) obj;
-            if (mailboxId != other.mailboxId)
-                return false;
-            if (uid != other.uid)
-                return false;
-            return true;
-        }
-    }
-
-    /** The value for the mailboxId field */
-    @Id private long mailboxId;
-
-    /** The value for the uid field */
-    @Id private long uid;
-
-    /** The value for the internalDate field */
-    @Basic(optional=false) private Date internalDate;
-
-    /** The value for the size field */
-    @Basic(optional=false) private int size = 0;
-
-    /** The value for the answered field */
-    @Basic(optional=false) private boolean answered = false;
-
-    /** The value for the deleted field */
-    @Basic(optional=false) private boolean deleted = false;
-
-    /** The value for the draft field */
-    @Basic(optional=false) private boolean draft = false;
-
-    /** The value for the flagged field */
-    @Basic(optional=false) private boolean flagged = false;
-
-    /** The value for the recent field */
-    @Basic(optional=false) private boolean recent = false;
-
-    /** The value for the seen field */
-    @Basic(optional=false) private boolean seen = false;
-
-    /** The value for the body field. Lazy loaded */
-    @ManyToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY) private JPAMessage message;
-    
-    /**
-     * For enhancement only.
-     */
-    @Deprecated
-    public JPAMailboxMembership() {}
-
-    public JPAMailboxMembership(long mailboxId, long uid, Date internalDate, int size, Flags flags, 
-            InputStream content, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws MailboxException {
-        super();
-        this.mailboxId = mailboxId;
-        this.uid = uid;
-        this.internalDate = internalDate;
-        this.size = size;
-        try {
-            this.message = new JPAMessage(content, size, bodyStartOctet, headers, propertyBuilder);
-        } catch (IOException e) {
-            throw new MailboxException(HumanReadableText.FAILURE_MAILBOX_EXISTS,e);
-        }
-        setFlags(flags);
-    }
-
-    /**
-     * Constructs a copy of the given message.
-     * All properties are cloned except mailbox and UID.
-     * @param mailboxId new mailbox ID
-     * @param uid new UID
-     * @param original message to be copied, not null
-     * @throws IOException 
-     */
-    public JPAMailboxMembership(long mailboxId, long uid, JPAMailboxMembership original) throws MailboxException {
-        super();
-        this.mailboxId = mailboxId;
-        this.uid = uid;
-        this.internalDate = original.getInternalDate();
-        this.size = original.getSize();
-        this.answered = original.isAnswered();
-        this.deleted = original.isDeleted();
-        this.draft = original.isDraft();
-        this.flagged = original.isFlagged();
-        this.recent = original.isRecent();
-        this.seen = original.isSeen();
-        try {
-            this.message = new JPAMessage((JPAMessage) original.getDocument());
-        } catch (IOException e) {
-            throw new MailboxException(HumanReadableText.FAILURE_MAILBOX_EXISTS,e);
-        }
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#getInternalDate()
-     */
-    public Date getInternalDate() {
-        return internalDate;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#getMailboxId()
-     */
-    public Long getMailboxId() {
-        return mailboxId;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#getSize()
-     */
-    public int getSize() {
-        return size;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#getUid()
-     */
-    public long getUid() {
-        return uid;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isAnswered()
-     */
-    public boolean isAnswered() {
-        return answered;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isDeleted()
-     */
-    public boolean isDeleted() {
-        return deleted;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isDraft()
-     */
-    public boolean isDraft() {
-        return draft;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isFlagged()
-     */
-    public boolean isFlagged() {
-        return flagged;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isRecent()
-     */
-    public boolean isRecent() {
-        return recent;
-    }
-
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#isSeen()
-     */
-    public boolean isSeen() {
-        return seen;
-    }
-    
-    /**
-     * Gets the message member.
-     * @return message, not null
-     */
-    public Document getDocument() {
-        return message;
-    }
-    
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#unsetRecent()
-     */
-    public void unsetRecent() {
-        recent = false;
-    }
-    
-    /**
-     * @see org.apache.james.imap.store.mail.model.MailboxMembership#setFlags(javax.mail.Flags)
-     */
-    public 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);
-    }
-
-  
-
-    @Override
-    public int hashCode() {
-        final int PRIME = 31;
-        int result = 1;
-        result = PRIME * result + (int) (mailboxId ^ (mailboxId >>> 32));
-        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 JPAMailboxMembership other = (JPAMailboxMembership) obj;
-        if (mailboxId != other.mailboxId)
-            return false;
-        if (uid != other.uid)
-            return false;
-        return true;
-    }
-
-    public String toString()
-    {
-        final String retValue = 
-            "mailbox("
-            + "mailboxId = " + this.mailboxId + TOSTRING_SEPARATOR
-            + "uid = " + this.uid + TOSTRING_SEPARATOR
-            + "internalDate = " + this.internalDate + TOSTRING_SEPARATOR
-            + "size = " + this.size + TOSTRING_SEPARATOR
-            + "answered = " + this.answered + TOSTRING_SEPARATOR
-            + "deleted = " + this.deleted + TOSTRING_SEPARATOR
-            + "draft = " + this.draft + TOSTRING_SEPARATOR
-            + "flagged = " + this.flagged + TOSTRING_SEPARATOR
-            + "recent = " + this.recent + TOSTRING_SEPARATOR
-            + "seen = " + this.seen + TOSTRING_SEPARATOR
-            + " )";
-
-        return retValue;
-    }
-}
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jpa.mail.model;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.ManyToOne;
+
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.store.mail.model.Document;
+import org.apache.james.imap.store.mail.model.PropertyBuilder;
+
+@Entity(name="Membership")
+public class JPAMailboxMembership extends AbstractJPAMailboxMembership{
+
+
+    /** The value for the body field. Lazy loaded */
+    @ManyToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY) private JPAMessage message;
+  
+    
+    /**
+     * For enhancement only.
+     */
+    @Deprecated
+    public JPAMailboxMembership() {}
+
+    public JPAMailboxMembership(long mailboxId, long uid, Date internalDate, int size, Flags flags, 
+            InputStream content, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws MailboxException {
+        super(mailboxId, uid, internalDate, size, flags, bodyStartOctet, headers, propertyBuilder);  
+        try {
+            this.message = new JPAMessage(content, size, bodyStartOctet, headers, propertyBuilder);
+        } catch (IOException e) {
+            throw new MailboxException(HumanReadableText.FAILURE_MAILBOX_EXISTS,e);
+        }
+    }
+
+    public JPAMailboxMembership(long mailboxId, long uid, AbstractJPAMailboxMembership original) throws MailboxException {
+        super(mailboxId, uid, original);
+        try {
+            this.message = new JPAMessage((JPAMessage) original.getDocument());
+        } catch (IOException e) {
+            throw new MailboxException(HumanReadableText.FAILURE_MAILBOX_EXISTS,e);
+        }
+    }
+    
+    /**
+     * Gets the message member.
+     * @return message, not null
+     */
+    public Document getDocument() {
+        return message;
+    }
+    
+
+}

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=931951&r1=931950&r2=931951&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 Thu Apr  8 14:10:41 2010
@@ -29,6 +29,9 @@ import javax.persistence.Entity;
 import javax.persistence.FetchType;
 import javax.persistence.Lob;
 
+import org.apache.james.imap.store.DelegatingRewindableInputStream;
+import org.apache.james.imap.store.FileRewindableInputStream;
+import org.apache.james.imap.store.InMemoryRewindableInputStream;
 import org.apache.james.imap.store.LazySkippingInputStream;
 import org.apache.james.imap.store.RewindableInputStream;
 import org.apache.james.imap.store.StreamUtils;
@@ -66,7 +69,7 @@ public class JPAMessage extends Abstract
      * @see org.apache.james.imap.store.mail.model.Document#getFullContent()
      */
     public RewindableInputStream getFullContent() throws IOException{
-        return new RewindableInputStream(new ByteArrayInputStream(content));
+        return new DelegatingRewindableInputStream(new ByteArrayInputStream(content),getFullContentOctets());
     }
 
     /*
@@ -74,7 +77,7 @@ public class JPAMessage extends Abstract
      * @see org.apache.james.imap.store.mail.model.Document#getBodyContent()
      */
     public RewindableInputStream getBodyContent() throws IOException {
-        return new RewindableInputStream(new LazySkippingInputStream(new ByteArrayInputStream(content), getBodyStartOctet()));
+        return new DelegatingRewindableInputStream(new LazySkippingInputStream(new ByteArrayInputStream(content), getBodyStartOctet()),getFullContentOctets());
     }
 
 }

Added: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMailboxMembership.java?rev=931951&view=auto
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMailboxMembership.java (added)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/openjpa/JPAStreamingMailboxMembership.java Thu Apr  8 14:10:41 2010
@@ -0,0 +1,79 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.imap.jpa.mail.model.openjpa;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.Flags;
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.FetchType;
+import javax.persistence.ManyToOne;
+
+import org.apache.james.imap.api.display.HumanReadableText;
+import org.apache.james.imap.jpa.mail.model.AbstractJPAMailboxMembership;
+import org.apache.james.imap.jpa.mail.model.JPAHeader;
+import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.store.mail.model.Document;
+import org.apache.james.imap.store.mail.model.PropertyBuilder;
+
+@Entity(name="Membership")
+public class JPAStreamingMailboxMembership extends AbstractJPAMailboxMembership{
+
+
+    /** The value for the body field. Lazy loaded */
+    @ManyToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY) private JPAStreamingMessage message;
+  
+    
+    /**
+     * For enhancement only.
+     */
+    @Deprecated
+    public JPAStreamingMailboxMembership() {}
+
+    public JPAStreamingMailboxMembership(long mailboxId, long uid, Date internalDate, int size, Flags flags, 
+            InputStream content, int bodyStartOctet, final List<JPAHeader> headers, final PropertyBuilder propertyBuilder) throws MailboxException {
+        super(mailboxId, uid, internalDate, size, flags, bodyStartOctet, headers, propertyBuilder);  
+        this.message = new JPAStreamingMessage(content, size, bodyStartOctet, headers, propertyBuilder);
+        
+       
+    }
+
+    public JPAStreamingMailboxMembership(long mailboxId, long uid, AbstractJPAMailboxMembership original) throws MailboxException {
+        super(mailboxId, uid, original);
+        try {
+            this.message = new JPAStreamingMessage((JPAStreamingMessage) original.getDocument());
+        } catch (IOException e) {
+            throw new MailboxException(HumanReadableText.FAILURE_MAILBOX_EXISTS,e);
+        }
+    }
+    
+    /**
+     * Gets the message member.
+     * @return message, not null
+     */
+    public Document getDocument() {
+        return message;
+    }
+    
+
+}

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=931951&r1=931950&r2=931951&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 Thu Apr  8 14:10:41 2010
@@ -31,6 +31,7 @@ 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.DelegatingRewindableInputStream;
 import org.apache.james.imap.store.LazySkippingInputStream;
 import org.apache.james.imap.store.RewindableInputStream;
 import org.apache.james.imap.store.StreamUtils;
@@ -77,7 +78,7 @@ public class JPAStreamingMessage extends
      * @see org.apache.james.imap.store.mail.model.Document#getFullContent()
      */
     public RewindableInputStream getFullContent() throws IOException {
-        return new RewindableInputStream(content);
+        return new DelegatingRewindableInputStream(content,getFullContentOctets());
     }
 
     /*
@@ -85,7 +86,7 @@ public class JPAStreamingMessage extends
      * @see org.apache.james.imap.store.mail.model.Document#getBodyContent()
      */
     public RewindableInputStream getBodyContent() throws IOException {
-        return new RewindableInputStream(new LazySkippingInputStream(content, getBodyStartOctet()));
+        return new DelegatingRewindableInputStream(new LazySkippingInputStream(content, getBodyStartOctet()),getFullContentOctets());
 
     }
 

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=931951&r1=931950&r2=931951&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 Thu Apr  8 14:10:41 2010
@@ -19,15 +19,28 @@
 
 package org.apache.james.imap.jpa.openjpa;
 
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.mail.Flags;
 import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
 
 import org.apache.james.imap.jpa.JPAMailbox;
 import org.apache.james.imap.jpa.JPAUtils;
 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;
 import org.apache.james.imap.jpa.mail.openjpa.OpenJPAMailboxMapper;
+import org.apache.james.imap.mailbox.MailboxException;
 import org.apache.james.imap.mailbox.MailboxSession;
+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;
 
 /**
  * OpenJPA implementation of Mailbox
@@ -36,11 +49,17 @@ import org.apache.james.imap.store.mail.
 public class OpenJPAMailbox extends JPAMailbox{
 
     public final static String MAILBOX_MAPPER = "MAILBOX_MAPPER";
+    private final boolean useStreaming;
     public OpenJPAMailbox(Mailbox<Long> mailbox,
     		MailboxSession session, EntityManagerFactory entityManagerfactory) {
-		super(mailbox, session, entityManagerfactory);
+		this(mailbox,session, entityManagerfactory, false);
 	}
 
+    public OpenJPAMailbox(Mailbox<Long> mailbox,
+            MailboxSession session, EntityManagerFactory entityManagerfactory, final boolean useStreaming) {
+        super(mailbox, session, entityManagerfactory);
+        this.useStreaming = useStreaming;
+    }
 
     /*
      * (non-Javadoc)
@@ -56,4 +75,26 @@ public class OpenJPAMailbox extends JPAM
         return mapper;
     }
 
+    @Override
+    protected MailboxMembership<Long> copyMessage(MailboxMembership<Long> originalMessage, long uid) throws MailboxException {
+        if (useStreaming) {
+            return  new JPAStreamingMailboxMembership(getMailboxId(), uid, (AbstractJPAMailboxMembership) originalMessage);
+        } else {
+            return super.copyMessage(originalMessage, uid);
+        }
+    }
+
+    @Override
+    protected MailboxMembership<Long> createMessage(Date internalDate, long uid, int size, int bodyStartOctet, InputStream document, Flags flags, List<Header> headers, PropertyBuilder propertyBuilder) throws MailboxException {
+        if (useStreaming) {
+            final List<JPAHeader> jpaHeaders = new ArrayList<JPAHeader>(headers.size());
+            for (Header header: headers) {
+                jpaHeaders.add((JPAHeader) header);
+            }
+            return new JPAStreamingMailboxMembership(mailboxId, uid, internalDate, size, flags, document, bodyStartOctet, jpaHeaders, propertyBuilder);
+        } else {
+            return super.createMessage(internalDate, uid, size, bodyStartOctet, document, flags, headers, propertyBuilder);
+        }
+    }
+
 }

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=931951&r1=931950&r2=931951&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 Thu Apr  8 14:10:41 2010
@@ -34,22 +34,27 @@ import org.apache.james.imap.store.mail.
  * OpenJPA implementation of MailboxManager
  *
  */
-public class OpenJPAMailboxManager extends JPAMailboxManager{
+public class OpenJPAMailboxManager extends JPAMailboxManager {
 
-	public OpenJPAMailboxManager(Authenticator authenticator,
-			Subscriber subscriber, EntityManagerFactory entityManagerFactory) {
-		super(authenticator, subscriber, entityManagerFactory);
-	}
+    private boolean useStreaming;
 
-	@Override
-	protected MailboxMapper<Long> createMailboxMapper(MailboxSession session) {
-        return new OpenJPAMailboxMapper(entityManagerFactory.createEntityManager());
-	}
+    public OpenJPAMailboxManager(Authenticator authenticator, Subscriber subscriber, EntityManagerFactory entityManagerFactory, boolean useStreaming) {
+        super(authenticator, subscriber, entityManagerFactory);
+        this.useStreaming = useStreaming;
+    }
+
+    public OpenJPAMailboxManager(Authenticator authenticator, Subscriber subscriber, EntityManagerFactory entityManagerFactory) {
+        this(authenticator, subscriber, entityManagerFactory, false);
+    }
 
+    @Override
+    protected MailboxMapper<Long> createMailboxMapper(MailboxSession session) {
+        return new OpenJPAMailboxMapper(entityManagerFactory.createEntityManager());
+    }
 
     protected StoreMailbox<Long> createMailbox(Mailbox<Long> mailboxRow, MailboxSession session) {
         StoreMailbox<Long> result;
-        result = new OpenJPAMailbox(mailboxRow, session, entityManagerFactory);
+        result = new OpenJPAMailbox(mailboxRow, session, entityManagerFactory, useStreaming);
         return result;
     }
 }

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java (original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/SimpleMailboxMembership.java Thu Apr  8 14:10:41 2010
@@ -26,6 +26,7 @@ import java.util.List;
 
 import javax.mail.Flags;
 
+import org.apache.james.imap.store.DelegatingRewindableInputStream;
 import org.apache.james.imap.store.LazySkippingInputStream;
 import org.apache.james.imap.store.RewindableInputStream;
 import org.apache.james.imap.store.mail.model.AbstractMailboxMembership;
@@ -151,7 +152,7 @@ public class SimpleMailboxMembership ext
     }
 
     public RewindableInputStream getBodyContent() throws IOException {
-        return new RewindableInputStream(new LazySkippingInputStream(new ByteArrayInputStream(document),bodyStartOctet));
+        return new DelegatingRewindableInputStream(new LazySkippingInputStream(new ByteArrayInputStream(document),bodyStartOctet), getFullContentOctets());
        
     }
 
@@ -160,7 +161,7 @@ public class SimpleMailboxMembership ext
     }
 
     public RewindableInputStream getFullContent() throws IOException {
-        return new RewindableInputStream(new ByteArrayInputStream(document));
+        return new DelegatingRewindableInputStream(new ByteArrayInputStream(document), getFullContentOctets());
     }
 
     public long getFullContentOctets() {

Modified: james/imap/trunk/parent/pom.xml
URL: http://svn.apache.org/viewvc/james/imap/trunk/parent/pom.xml?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/parent/pom.xml (original)
+++ james/imap/trunk/parent/pom.xml Thu Apr  8 14:10:41 2010
@@ -578,7 +578,7 @@
     <javax.mail.groupId>javax.mail</javax.mail.groupId>
     <javax.mail.artifactId>mail</javax.mail.artifactId>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    <version.openjpa>1.2.1</version.openjpa>
+    <version.openjpa>1.2.2</version.openjpa>
     <version.javax.persistence>1.0.2</version.javax.persistence>
     <version.commons-lang>2.4</version.commons-lang>
     <version.commons-collections>3.2.1</version.commons-collections>

Added: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/AbstractRewindableInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/AbstractRewindableInputStream.java?rev=931951&view=auto
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/AbstractRewindableInputStream.java (added)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/AbstractRewindableInputStream.java Thu Apr  8 14:10:41 2010
@@ -0,0 +1,128 @@
+package org.apache.james.imap.store;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * {@link FilterInputStream} which support the get rewinded. This is done by copy over every byte
+ * over to another {@link OutputStream}. What {@link OutputStream} to use is up to the implementations.
+ * 
+ * The rewinding will get delayed as long as possible. So if you call
+ * rewind, it will only get performed when needed
+ * 
+ *
+ */
+public abstract class AbstractRewindableInputStream extends RewindableInputStream{
+
+    protected boolean end = false;
+
+    public AbstractRewindableInputStream(InputStream in) throws IOException {
+        super(in);
+    }
+
+    protected abstract OutputStream getRewindOutputStream() throws IOException;
+    
+    protected abstract InputStream getRewindInputStream() throws IOException;
+
+    protected abstract void dispose() throws IOException;
+    
+    protected abstract void afterRewindComplete() throws IOException;
+    
+    @Override
+    public void close() throws IOException {
+        try {
+            in.close();
+            OutputStream out = getRewindOutputStream();
+            if (out != null) {
+                out.close();
+            }
+            InputStream in = getRewindInputStream();
+            if (in != null) {
+                in.close();
+            }
+        } finally {
+            dispose();
+        }
+    }
+
+    
+    
+    @Override
+    public int read() throws IOException {   
+        int i;
+        if (needsRewind()) {
+
+            rewindIfNeeded();
+        }
+        
+        if (end == false) {
+            i = in.read();
+            if (i == -1) {
+                end = true;
+            } else {
+                getRewindOutputStream().write(i);
+            }
+        } else {
+            i = getRewindInputStream().read();
+        }
+        return i;
+    }
+
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+        if (len == 0) {
+            return 0;
+        }
+        if (needsRewind()) {
+            rewindIfNeeded();
+        }    
+        
+        int i;
+        if (end == false) {
+            i = in.read(b, off, len);
+            if (i == -1) {
+                end = true;
+            }
+            getRewindOutputStream().write(b, off, len);
+        } else {
+            i = getRewindInputStream().read(b,off,len);
+        }
+        return i;
+    }
+
+    @Override
+    public void rewindIfNeeded() throws IOException {
+        if (needsRewind()) {
+            rewindDone();
+            
+            if (end == false) {
+                while ( read() != -1);
+            }
+            // we don't need the original inputstream anymore so close it
+            in.close();
+            afterRewindComplete();
+        }        
+    }
+
+    @Override
+    public int available() throws IOException {
+        if (end == false) {
+            return in.available();
+        } else {
+            return getRewindInputStream().available();
+        }
+    }
+
+    @Override
+    public long skip(long n) throws IOException {
+        for (int i = 0; i < n; i++) {
+            if (read() == -1) {
+                return n -i;
+            }
+            if (end) break;
+        }
+        return 0;
+    }
+}

Added: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingRewindableInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingRewindableInputStream.java?rev=931951&view=auto
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingRewindableInputStream.java (added)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/DelegatingRewindableInputStream.java Thu Apr  8 14:10:41 2010
@@ -0,0 +1,98 @@
+/****************************************************************
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * {@link RewindableInputStream} implementation which just delegate the calls to {@link FileRewindableInputStream} 
+ * or {@link InMemoryRewindableInputStream} depending on the size 
+ * 
+ *
+ */
+public class DelegatingRewindableInputStream extends RewindableInputStream{
+
+    public final static long  MAX_INMEMORY_SIZE= 524288;
+    
+    public DelegatingRewindableInputStream(InputStream in, long size, long maxInmemorySize) throws IOException {
+        super(null);
+        if (size > maxInmemorySize) {
+            this.in = new FileRewindableInputStream(in);
+        } else {
+            this.in = new InMemoryRewindableInputStream(in);
+
+        }
+    }
+
+    public DelegatingRewindableInputStream(InputStream in, long size) throws IOException {
+        this(in, size, MAX_INMEMORY_SIZE);
+    }
+
+    @Override
+    public int available() throws IOException {
+        return in.available();
+    }
+
+    @Override
+    public void close() throws IOException {
+        in.close();
+    }
+
+    @Override
+    public synchronized void mark(int readlimit) {
+        in.mark(readlimit);
+    }
+
+    @Override
+    public boolean markSupported() {
+        return in.markSupported();
+    }
+
+    @Override
+    public int read() throws IOException {
+        return in.read();
+    }
+
+    @Override
+    public int read(byte[] b, int off, int len) throws IOException {
+        return in.read(b, off, len);
+    }
+
+    @Override
+    public int read(byte[] b) throws IOException {
+        return in.read(b);
+    }
+
+    @Override
+    public synchronized void reset() throws IOException {
+        in.reset();
+    }
+
+    @Override
+    public long skip(long n) throws IOException {
+        return in.skip(n);
+    }
+
+    @Override
+    protected void rewindIfNeeded() throws IOException {
+        ((RewindableInputStream)in).rewindIfNeeded();
+    }
+
+}

Added: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java?rev=931951&view=auto
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java (added)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/FileRewindableInputStream.java Thu Apr  8 14:10:41 2010
@@ -0,0 +1,79 @@
+/****************************************************************
+ * 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;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * {@link RewindableInputStream} implementations which stores the data into a {@link File}. This is
+ * useful for big data
+ * 
+ */
+public class FileRewindableInputStream extends AbstractRewindableInputStream{
+
+    private File f;
+    private FileOutputStream fOut;
+    private FileInputStream fIn;
+
+    public FileRewindableInputStream(InputStream in) throws IOException {
+        super(in);
+    }
+
+    @Override
+    protected OutputStream getRewindOutputStream() throws IOException {
+        if (f == null) {
+            f = File.createTempFile("rewindable", ".tmp");
+        }
+        if (fOut == null) {
+            fOut = new FileOutputStream(f);
+        
+        }
+        return fOut;
+    }
+    
+    @Override
+    protected void afterRewindComplete() throws IOException {
+        fIn = new FileInputStream(f);        
+    }
+
+    @Override
+    protected void dispose() throws IOException {
+        if (f != null) {
+            f.delete();
+        }
+    }
+
+    @Override
+    protected InputStream getRewindInputStream() throws IOException {
+        if (f == null) {
+            f = File.createTempFile("rewindable", ".tmp");
+        }
+        if (fIn == null) {
+
+            fIn = new FileInputStream(f);
+        }
+        return fIn;
+    }
+}

Added: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InMemoryRewindableInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InMemoryRewindableInputStream.java?rev=931951&view=auto
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InMemoryRewindableInputStream.java (added)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/InMemoryRewindableInputStream.java Thu Apr  8 14:10:41 2010
@@ -0,0 +1,62 @@
+/****************************************************************
+ * 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;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+/**
+ * {@link RewindableInputStream} implementations which stores the data into a {@link ByteArrayOutputStream}. This is
+ * only useful for small data, because it is complete handled in memory
+ * 
+ */
+public class InMemoryRewindableInputStream extends AbstractRewindableInputStream{
+
+    private ByteArrayOutputStream out;
+    private ByteArrayInputStream in;
+    public InMemoryRewindableInputStream(InputStream wrappedIn) throws IOException {
+        super(wrappedIn);
+        this.out = new ByteArrayOutputStream();
+        this.in = new ByteArrayInputStream(out.toByteArray());
+    }
+
+    @Override
+    protected void afterRewindComplete() throws IOException {
+        in = new ByteArrayInputStream(out.toByteArray());
+    }
+
+    @Override
+    protected void dispose() throws IOException {
+        // nothing todo
+    }
+
+    @Override
+    protected InputStream getRewindInputStream() {
+        return in;
+    }
+
+    @Override
+    protected OutputStream getRewindOutputStream() {
+        return out;
+    }
+
+}

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/ResultUtils.java Thu Apr  8 14:10:41 2010
@@ -260,38 +260,42 @@ public class ResultUtils {
         }
         headersToString.append("\r\n");
         final RewindableInputStream bodyContent = document.getBodyContent();
-        final MessageInputStream stream = new MessageInputStream(headersToString, bodyContent);
+        final MessageInputStream stream = new MessageInputStream(headersToString, bodyContent, document.getFullContentOctets());
         return stream;
     }
 
 
-    private static final class MessageInputStream extends RewindableInputStream {
+    private static final class MessageInputStream extends DelegatingRewindableInputStream {
         private final StringBuffer headers;
         private int headerPosition = 0;
 
         public MessageInputStream(final StringBuffer headers,
-                final RewindableInputStream bodyContent) throws IOException{
-            super(bodyContent);
+                final RewindableInputStream bodyContent, long bodySize) throws IOException{
+            super(bodyContent, bodySize);
             
             this.headers = headers;
             bodyContent.rewind();
         }
 
         public int read() throws IOException {
-            rewindIfNeeded();
+            if (needsRewind()) {
+                rewind();
+            }
             final int result;
             if (headerPosition < headers.length()) {
                 result = headers.charAt(headerPosition++);
             } else  { 
-                result = in.read();
+                result = super.read();
             }
             return result;
         }
 
         @Override
         public int read(byte[] b, int off, int len) throws IOException {
-
-            rewindIfNeeded();
+            if (needsRewind()) {
+                rewind();
+            }
+            
             if (headerPosition < headers.length()) {
                 int headersLeft = headers.length() - headerPosition;
                 if (len > headersLeft) {
@@ -304,7 +308,7 @@ public class ResultUtils {
                         b[off +i] = (byte) a;
                     }
                     int bytesLeft = len - headersLeft;
-                    return i + in.read(b, off +i, bytesLeft);
+                    return i + super.read(b, off +i, bytesLeft);
                 } else {
 
                     for (int i = 0 ; i < len; i++) {
@@ -317,21 +321,13 @@ public class ResultUtils {
                     return len;
                 }
             }
-            return in.read(b, off, len);
+            return super.read(b, off, len);
         }
 
         @Override
         public int read(byte[] b) throws IOException {
             return read(b, 0, b.length);
         }
-
-        @Override
-        protected void rewindIfNeeded() throws IOException {
-            if (needsRewind()) {
-                headerPosition = 0;
-                ((RewindableInputStream)in).rewindIfNeeded();
-            }
-        }
         
         
     }

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java (original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/RewindableInputStream.java Thu Apr  8 14:10:41 2010
@@ -18,164 +18,53 @@
  ****************************************************************/
 package org.apache.james.imap.store;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.FilterInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.OutputStream;
 
 /**
- * {@link FilterInputStream} which support the get rewinded. This is done by copy over every byte
- * to a File after it was read. The rewinding will get delayed as long as possible. So if you call
+ * {@link FilterInputStream} which support the get rewinded.
+ * 
+ * The rewinding will get delayed as long as possible. So if you call
  * rewind, it will only get performed when needed
  * 
  *
  */
-public class RewindableInputStream extends FilterInputStream{
+public abstract class RewindableInputStream extends FilterInputStream{
 
-    private File f;
-    private OutputStream fOut;
-    private InputStream fIn;
-    protected boolean end = false;
-    protected boolean rewind;
+    private boolean rewind;
 
-    public RewindableInputStream(InputStream in) throws IOException {
+    protected RewindableInputStream(InputStream in) {
         super(in);
-        f = File.createTempFile("rewindable", ".tmp");
-        fOut = new FileOutputStream(f);
-        fIn = new FileInputStream(f);
-    }
-
-    @Override
-    public void close() throws IOException {
-        try {
-            in.close();
-            fOut.close();
-            fIn.close();
-        } finally {
-            f.delete();
-        }
-    }
-
-    @Override
-    public int read() throws IOException {        
-        // rewind if we need to
-        rewindIfNeeded();
-        
-        int i;
-
-        if (end == false) {
-            i = in.read();
-            if (i == -1) {
-                end = true;
-            } else {
-                fOut.write(i);
-            }
-        } else {
-            i = fIn.read();
-        }
-        return i;
-    }
-
-    @Override
-    public int read(byte[] b, int off, int len) throws IOException {
-        if (len == 0) {
-            return 0;
-        }
-        
-        // rewind if we need to
-        rewindIfNeeded();
-        
-        int i;
-        if (end == false) {
-            i = in.read(b, off, len);
-            if (i == -1) {
-                end = true;
-            }
-            fOut.write(b, off, len);
-        } else {
-            i = fIn.read(b,off,len);
-        }
-        return i;
-    }
-
-    @Override
-    public int read(byte[] b) throws IOException {
-        return read(b,0,b.length);
-    }
-    
-    /**
-     * Mark the stream for rewind. The rewind itself will get delayed as long as possible
-     */
-    public void rewind() {
-        rewind = true;
     }
 
     /**
-     * Check if the stream needs to get rewind
+     * Return if the stream needs to get rewinded
      * 
-     * @return true if the stream is marked for rewind
+     * @return needsRewind
      */
-    protected boolean needsRewind() {
+    public final boolean needsRewind() {
         return rewind;
     }
     
     /**
-     * Do the real rewind if needed
-     * 
-     * @throws IOException
+     * Rewind was done
      */
-    protected void rewindIfNeeded() throws IOException {
-        if (needsRewind()) {
-            rewind = false;
-
-            if (end == false) {
-                while ( read() != -1);
-            }
-            fIn = new FileInputStream(f);
-        }
+    protected final void rewindDone() {
+        this.rewind = false;
     }
     
-    @Override
-    public int available() throws IOException {
-        if (end == false) {
-            return in.available();
-        } else {
-            return fIn.available();
-        }
-    }
-
-    /**
-     * Mark is not supported
-     */
-    public synchronized void mark(int readlimit) {
-        // do nothing
-    }
-
     /**
-     * Mark is not supported
+     * Mark the stream for rewind. The rewind itself should get delayed as long as possible
      */
-    public boolean markSupported() {
-        return false;
+    public final void rewind() {
+        this.rewind = true;
     }
 
     /**
-     * Reset is not supported
+     * Perform the actual rewind 
+     * @throws IOException
      */
-    public synchronized void reset() throws IOException {
-        // do nothing
-    }
+    protected abstract void rewindIfNeeded() throws IOException;
 
-    @Override
-    public long skip(long n) throws IOException {
-        for (int i = 0; i < n; i++) {
-            if (read() == -1) {
-                return n -i;
-            }
-            if (end) break;
-        }
-        return 0;
-    }
 }

Added: james/imap/trunk/store/src/test/java/org/apache/james/imap/store/FileRewindableInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/test/java/org/apache/james/imap/store/FileRewindableInputStreamTest.java?rev=931951&view=auto
==============================================================================
--- james/imap/trunk/store/src/test/java/org/apache/james/imap/store/FileRewindableInputStreamTest.java (added)
+++ james/imap/trunk/store/src/test/java/org/apache/james/imap/store/FileRewindableInputStreamTest.java Thu Apr  8 14:10:41 2010
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class FileRewindableInputStreamTest extends RewindableInputStreamTest{
+
+    @Override
+    protected RewindableInputStream create(InputStream in) throws IOException {
+        return new FileRewindableInputStream(in);
+    }
+
+}

Added: james/imap/trunk/store/src/test/java/org/apache/james/imap/store/InMemoryRewindableInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/test/java/org/apache/james/imap/store/InMemoryRewindableInputStreamTest.java?rev=931951&view=auto
==============================================================================
--- james/imap/trunk/store/src/test/java/org/apache/james/imap/store/InMemoryRewindableInputStreamTest.java (added)
+++ james/imap/trunk/store/src/test/java/org/apache/james/imap/store/InMemoryRewindableInputStreamTest.java Thu Apr  8 14:10:41 2010
@@ -0,0 +1,31 @@
+/****************************************************************
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+public class InMemoryRewindableInputStreamTest extends RewindableInputStreamTest{
+
+    @Override
+    protected RewindableInputStream create(InputStream in) throws IOException {
+        return new InMemoryRewindableInputStream(in);
+    }
+
+}

Modified: james/imap/trunk/store/src/test/java/org/apache/james/imap/store/RewindableInputStreamTest.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/test/java/org/apache/james/imap/store/RewindableInputStreamTest.java?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/store/src/test/java/org/apache/james/imap/store/RewindableInputStreamTest.java (original)
+++ james/imap/trunk/store/src/test/java/org/apache/james/imap/store/RewindableInputStreamTest.java Thu Apr  8 14:10:41 2010
@@ -21,12 +21,14 @@ package org.apache.james.imap.store;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
+
 import static org.junit.Assert.*;
 
 import org.junit.Before;
 import org.junit.Test;
 
-public class RewindableInputStreamTest {
+public abstract class RewindableInputStreamTest {
 
     private RewindableInputStream in;
     private final static String CONTENT = "test\nblah!\n";
@@ -36,10 +38,12 @@ public class RewindableInputStreamTest {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         out.write(CONTENT.getBytes());
 
-        in = new RewindableInputStream(new ByteArrayInputStream(out.toByteArray()));
+        in = create(new ByteArrayInputStream(out.toByteArray()));
 
     }
 
+    protected abstract RewindableInputStream create(InputStream in) throws IOException;
+    
     public void tearDown() throws IOException {
         in.close();
     }

Modified: james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java?rev=931951&r1=931950&r2=931951&view=diff
==============================================================================
--- james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java (original)
+++ james/imap/trunk/store/src/test/java/org/apache/james/imap/store/SimpleMessage.java Thu Apr  8 14:10:41 2010
@@ -88,7 +88,7 @@ public class SimpleMessage implements Do
      * @see org.apache.james.imap.jpa.mail.model.Document#getBodyContent()
      */
     public RewindableInputStream getBodyContent() throws IOException {
-        return new RewindableInputStream(new ByteArrayInputStream(body));
+        return new InMemoryRewindableInputStream(new ByteArrayInputStream(body));
     }
 
     /**
@@ -97,7 +97,7 @@ public class SimpleMessage implements Do
      * @throws IOException 
      */
     public RewindableInputStream getFullContent() throws IOException {
-        return new RewindableInputStream(new ByteArrayInputStream(fullContent));
+        return new InMemoryRewindableInputStream(new ByteArrayInputStream(fullContent));
     }
     
     /**



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