You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by rd...@apache.org on 2008/12/29 16:47:36 UTC

svn commit: r729918 - in /james/protocols/imap/trunk: jpa/src/main/java/org/apache/james/imap/jpa/ jpa/src/main/java/org/apache/james/imap/jpa/om/ mailbox/src/main/java/org/apache/james/mailboxmanager/mailbox/ processor/src/main/java/org/apache/james/i...

Author: rdonkin
Date: Mon Dec 29 07:47:35 2008
New Revision: 729918

URL: http://svn.apache.org/viewvc?rev=729918&view=rev
Log:
Store only id, not POJO

Modified:
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
    james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java
    james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/mailboxmanager/mailbox/Mailbox.java
    james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java?rev=729918&r1=729917&r2=729918&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java (original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailbox.java Mon Dec 29 07:47:35 2008
@@ -56,8 +56,6 @@
 import org.apache.james.mailboxmanager.impl.UidChangeTracker;
 import org.apache.james.mailboxmanager.mailbox.Mailbox;
 import org.apache.james.mailboxmanager.util.UidRange;
-import org.apache.torque.NoRowsException;
-import org.apache.torque.TooManyRowsException;
 import org.apache.torque.TorqueException;
 
 import EDU.oswego.cs.dl.util.concurrent.ReadWriteLock;
@@ -70,14 +68,14 @@
 
     private boolean open = true;
 
-    private MailboxRow mailboxRow;
+    private long mailboxId;
 
     private final UidChangeTracker tracker;
 
     private final ReadWriteLock lock;
 
     private final MessageSearches searches;
-    
+
     private final MailboxMapper mapper;
     private final MessageMapper messageMapper;
 
@@ -85,20 +83,24 @@
             final Log log) {
         this.searches = new MessageSearches();
         setLog(log);
-        this.mailboxRow = mailboxRow;
+        this.mailboxId = mailboxRow.getMailboxId();
         this.tracker = new UidChangeTracker(mailboxRow.getLastUid());
         this.lock = lock;
         this.mapper = new MailboxMapper();
         this.messageMapper = new MessageMapper();
     }
 
-    public synchronized String getName() {
+    public synchronized String getName() throws MailboxManagerException {
         checkAccess();
-        return mailboxRow.getName();
+        try {
+            return getMailboxRow().getName();
+        } catch (TorqueException e) {
+            throw new MailboxManagerException(e);
+        }
     }
 
     public int getMessageCount(MailboxSession mailboxSession)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
         try {
             lock.readLock().acquire();
             try {
@@ -118,14 +120,14 @@
 
     public MessageResult appendMessage(MimeMessage message, Date internalDate,
             FetchGroup fetchGroup, MailboxSession mailboxSession)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
 
         try {
             checkAccess();
 
-            final MailboxRow myMailboxRow = reserveNextUid();
+            final MailboxRow mailbox = reserveNextUid();
 
-            if (myMailboxRow != null) {
+            if (mailbox != null) {
                 try {
                     // To be thread safe, we first get our own copy and the
                     // exclusive
@@ -135,8 +137,7 @@
                     // is
                     // inserted long before 4, when
                     // mail 4 is big and comes over a slow connection.
-                    long uid = myMailboxRow.getLastUid();
-                    this.mailboxRow = myMailboxRow;
+                    long uid = mailbox.getLastUid();
 
                     MessageRow messageRow = new MessageRow();
                     messageRow.setMailboxId(getMailboxRow().getMailboxId());
@@ -170,20 +171,20 @@
     }
 
     private void populateFlags(MimeMessage message, MessageRow messageRow)
-            throws MessagingException, TorqueException {
+    throws MessagingException, TorqueException {
         final Flags flags = message.getFlags();
         buildFlags(messageRow, flags);
     }
 
     private void buildFlags(MessageRow messageRow, final Flags flags)
-            throws TorqueException {
+    throws TorqueException {
         MessageFlags messageFlags = new MessageFlags();
         messageFlags.setFlags(flags);
         messageRow.addMessageFlags(messageFlags);
     }
 
     private MessageBody populateBody(MimeMessage message) throws IOException,
-            MessagingException {
+    MessagingException {
         MessageBody mb = new MessageBody();
 
         InputStream is = message.getInputStream();
@@ -194,11 +195,11 @@
     }
 
     private void addHeaders(MimeMessage message, MessageRow messageRow)
-            throws MessagingException, TorqueException {
+    throws MessagingException, TorqueException {
         int line_number = 0;
 
         for (Enumeration lines = message.getAllHeaderLines(); lines
-                .hasMoreElements();) {
+        .hasMoreElements();) {
             String line = (String) lines.nextElement();
             int colon = line.indexOf(": ");
             if (colon > 0) {
@@ -214,7 +215,7 @@
     }
 
     private int size(MimeMessage message) throws IOException,
-            MessagingException {
+    MessagingException {
         // TODO very ugly size mesurement
         ByteArrayOutputStream sizeBos = new ByteArrayOutputStream();
         message.writeTo(new CRLFOutputStream(sizeBos));
@@ -223,7 +224,7 @@
     }
 
     private void save(MessageRow messageRow) throws TorqueException,
-            InterruptedException {
+    InterruptedException {
         try {
             lock.writeLock().acquire();
             messageMapper.save(messageRow);
@@ -233,7 +234,7 @@
     }
 
     private MailboxRow reserveNextUid() throws InterruptedException,
-            MailboxManagerException {
+    MailboxManagerException {
         final MailboxRow myMailboxRow;
         try {
             lock.writeLock().acquire();
@@ -274,14 +275,14 @@
     }
 
     private JPAResultIterator getMessages(FetchGroup result, UidRange range,List rows) 
-                throws TorqueException, MessagingException, MailboxManagerException {
+    throws TorqueException, MessagingException, MailboxManagerException {
         final JPAResultIterator results = getResults(result, rows);
         getUidChangeTracker().found(range, results.getMessageFlags());
         return results;
     }
 
     private JPAResultIterator getResults(FetchGroup result, List rows)
-            throws TorqueException {
+    throws TorqueException {
         Collections.sort(rows, MessageRowUtils.getUidComparator());
         final JPAResultIterator results = new JPAResultIterator(rows,
                 result);
@@ -289,7 +290,7 @@
     }
 
     private static UidRange uidRangeForMessageSet(MessageRange set)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
         if (set.getType() == MessageRange.TYPE_UID) {
             return new UidRange(set.getUidFrom(), set.getUidTo());
         } else if (set.getType() == MessageRange.TYPE_ALL) {
@@ -317,7 +318,7 @@
     }
 
     public long[] recent(boolean reset, MailboxSession mailboxSession)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
         try {
             lock.readLock().acquire();
             try {
@@ -383,7 +384,7 @@
 
 
     public int getUnseenCount(MailboxSession mailboxSession)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
         try {
             lock.readLock().acquire();
             try {
@@ -421,12 +422,12 @@
     }
 
     private Iterator doExpunge(final MessageRange set, FetchGroup fetchGroup)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
         checkAccess();
         try {
             // TODO put this into a serializable transaction
             final MailboxRow mailboxRow = getMailboxRow();
-            
+
             final List messageRows = mapper.findMarkedForDeletionInMailbox(set, mailboxRow);
             final long[] uids = uids(messageRows);
             final OrFetchGroup orFetchGroup = new OrFetchGroup(fetchGroup,
@@ -507,7 +508,7 @@
             final JPAResultIterator resultIterator = new JPAResultIterator(
                     messageRows, orFetchGroup);
             final org.apache.james.mailboxmanager.impl.MessageFlags[] messageFlags = resultIterator
-                    .getMessageFlags();
+            .getMessageFlags();
             tracker.flagsUpdated(messageFlags, mailboxSession.getSessionId());
             tracker.found(uidRange, messageFlags);
             return resultIterator;
@@ -517,7 +518,7 @@
     }
 
     public void addListener(MailboxListener listener)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
         checkAccess();
         tracker.addMailboxListener(listener);
     }
@@ -530,7 +531,7 @@
     }
 
     public long getUidValidity(MailboxSession mailboxSession)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
         try {
             lock.readLock().acquire();
             try {
@@ -543,33 +544,25 @@
 
         } catch (InterruptedException e) {
             throw new MailboxManagerException(e);
+        } catch (TorqueException e) {
+            throw new MailboxManagerException(e);
         }
 
     }
 
     public long getUidNext(MailboxSession mailboxSession)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
         try {
             lock.readLock().acquire();
             try {
                 checkAccess();
-                try {
-                    MailboxRow myMailboxRow = mapper.refresh(mailboxRow);
-                    if (myMailboxRow != null) {
-                        mailboxRow = myMailboxRow;
-                        getUidChangeTracker().foundLastUid(
-                                mailboxRow.getLastUid());
-                        return getUidChangeTracker().getLastUid() + 1;
-                    } else {
-                        throw new MailboxManagerException(
-                                "Mailbox has been deleted");
-                    }
-                } catch (NoRowsException e) {
-                    throw new MailboxManagerException(e);
-                } catch (TooManyRowsException e) {
-                    throw new MailboxManagerException(e);
-                } catch (TorqueException e) {
-                    throw new MailboxManagerException(e);
+                MailboxRow mailbox = getMailboxRow();
+                if (mailbox != null) {
+                    getUidChangeTracker().foundLastUid(mailbox.getLastUid());
+                    return getUidChangeTracker().getLastUid() + 1;
+                } else {
+                    throw new MailboxManagerException(
+                            "Mailbox has been deleted");
                 }
             } finally {
                 lock.readLock().release();
@@ -577,6 +570,8 @@
 
         } catch (InterruptedException e) {
             throw new MailboxManagerException(e);
+        }  catch (TorqueException e) {
+            throw new MailboxManagerException(e);
         }
     }
 
@@ -590,12 +585,8 @@
         return tracker;
     }
 
-    protected MailboxRow getMailboxRow() {
-        return mailboxRow;
-    }
-
-    protected void setMailboxRow(MailboxRow mailboxRow) {
-        this.mailboxRow = mailboxRow;
+    protected MailboxRow getMailboxRow() throws TorqueException {
+        return mapper.findById(mailboxId);
     }
 
     public Iterator search(SearchQuery query, FetchGroup fetchGroup,
@@ -615,9 +606,9 @@
                         }
                     } catch (TorqueException e) {
                         getLog()
-                                .info(
-                                        "Cannot test message against search criteria. Will continue to test other messages.",
-                                        e);
+                        .info(
+                                "Cannot test message against search criteria. Will continue to test other messages.",
+                                e);
                         if (getLog().isDebugEnabled())
                             getLog().debug("UID: " + row.getUid());
                     }
@@ -669,7 +660,7 @@
     }
 
     private void copy(List rows, MailboxSession session)
-            throws MailboxManagerException {
+    throws MailboxManagerException {
         try {
             for (Iterator iter = rows.iterator(); iter.hasNext();) {
                 MessageRow fromRow = (MessageRow) iter.next();
@@ -685,7 +676,6 @@
                     // inserted long before 4, when
                     // mail 4 is big and comes over a slow connection.
                     long uid = mailbox.getLastUid();
-                    this.mailboxRow = mailbox;
 
                     MessageRow newRow = new MessageRow();
                     newRow.setMailboxId(getMailboxRow().getMailboxId());
@@ -697,9 +687,9 @@
 
                     final List headers = fromRow.getMessageHeaders();
                     for (Iterator iterator = headers.iterator(); iterator
-                            .hasNext();) {
+                    .hasNext();) {
                         final MessageHeader fromHeader = (MessageHeader) iterator
-                                .next();
+                        .next();
                         final MessageHeader newHeader = new MessageHeader(
                                 fromHeader.getField(), fromHeader.getValue(),
                                 fromHeader.getLineNumber());

Modified: james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java?rev=729918&r1=729917&r2=729918&view=diff
==============================================================================
--- james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java (original)
+++ james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/om/MailboxMapper.java Mon Dec 29 07:47:35 2008
@@ -21,17 +21,12 @@
 
 import java.util.List;
 
-import javax.mail.Flags;
-
 import org.apache.james.mailboxmanager.MailboxManagerException;
 import org.apache.james.mailboxmanager.MessageRange;
 import org.apache.torque.TorqueException;
 import org.apache.torque.util.CountHelper;
 import org.apache.torque.util.Criteria;
 
-import com.workingdogs.village.DataSetException;
-import com.workingdogs.village.Record;
-
 /**
  * Data access management for mailbox.
  */
@@ -135,4 +130,8 @@
         return criteria;
     }
 
+    public MailboxRow findById(long mailboxId) throws TorqueException {
+        return MailboxRowPeer.retrieveByPK(mailboxId);
+    }
+
 }

Modified: james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/mailboxmanager/mailbox/Mailbox.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/mailboxmanager/mailbox/Mailbox.java?rev=729918&r1=729917&r2=729918&view=diff
==============================================================================
--- james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/mailboxmanager/mailbox/Mailbox.java (original)
+++ james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/mailboxmanager/mailbox/Mailbox.java Mon Dec 29 07:47:35 2008
@@ -44,7 +44,7 @@
      * @return Full folder name with namespace
      * @throws MailboxManagerException
      */
-    String getName();
+    String getName() throws MailboxManagerException;
 
     int getMessageCount(MailboxSession mailboxSession)
             throws MailboxManagerException;

Modified: james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java
URL: http://svn.apache.org/viewvc/james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java?rev=729918&r1=729917&r2=729918&view=diff
==============================================================================
--- james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java (original)
+++ james/protocols/imap/trunk/processor/src/main/java/org/apache/james/imap/processor/base/SelectedMailboxSessionImpl.java Mon Dec 29 07:47:35 2008
@@ -61,6 +61,8 @@
 
     private boolean recentUidRemoved;
 
+    private final String name;
+
     public SelectedMailboxSessionImpl(Mailbox mailbox, List uids,
             MailboxSession mailboxSession) throws MailboxManagerException {
         this.mailbox = mailbox;
@@ -74,6 +76,7 @@
         mailbox.addListener(events);
         converter = new UidToMsnConverter(uids);
         mailbox.addListener(converter);
+        name = mailbox.getName();
     }
 
     /**
@@ -254,7 +257,7 @@
     }
 
     public String getName() {
-        return mailbox.getName();
+        return name;
     }
 
     private void checkExpungedRecents() {



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