Author: rdonkin
Date: Tue Jan  6 12:09:45 2009
New Revision: 732092

URL: http://svn.apache.org/viewvc?rev=732092&view=rev
Log:
Push exception handling into mappers

Added:
    
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/StorageException.java
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/JPAMailboxManager.java
    
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MailboxMapper.java
    
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/Mapper.java
    
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MessageMapper.java
    
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/map/openjpa/OpenJPAMailboxMapper.java
    
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxNotFoundException.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=732092&r1=732091&r2=732092&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
 Tue Jan  6 12:09:45 2009
@@ -33,7 +33,6 @@
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceException;
 
 import org.apache.commons.logging.Log;
 import org.apache.james.api.imap.AbstractLogEnabled;
@@ -43,8 +42,9 @@
 import org.apache.james.imap.jpa.mail.model.Header;
 import org.apache.james.imap.jpa.mail.model.Mailbox;
 import org.apache.james.imap.jpa.mail.model.Message;
-import org.apache.james.imap.mailbox.MailboxListener;
 import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxListener;
+import org.apache.james.imap.mailbox.MailboxNotFoundException;
 import org.apache.james.imap.mailbox.MailboxSession;
 import org.apache.james.imap.mailbox.MessageRange;
 import org.apache.james.imap.mailbox.MessageResult;
@@ -74,14 +74,9 @@
         this.entityManagerFactory = entityManagerfactory;
     }
 
-    public int getMessageCount(MailboxSession mailboxSession)
-    throws MailboxException {
-        try {
-            final MessageMapper messageMapper = createMessageMapper();
-            return (int) messageMapper.countMessagesInMailbox(mailboxId);
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
-        }
+    public int getMessageCount(MailboxSession mailboxSession) throws 
MailboxException {
+        final MessageMapper messageMapper = createMessageMapper();
+        return (int) messageMapper.countMessagesInMailbox(mailboxId);
     }
 
     public MessageResult appendMessage(MimeMessage mimeMessage, Date 
internalDate,
@@ -89,7 +84,9 @@
     throws MailboxException {
         final Mailbox mailbox = reserveNextUid();
 
-        if (mailbox != null) {
+        if (mailbox == null) {
+            throw new MailboxNotFoundException("Mailbox has been deleted");
+        } else {
             try {
                 // To be thread safe, we first get our own copy and the
                 // exclusive
@@ -105,25 +102,21 @@
                 final Flags flags = mimeMessage.getFlags();
                 final List<Header> headers = headers(mailboxId, uid, 
mimeMessage);
                 final Message message = new Message(mailboxId, uid, 
internalDate, size, flags, body, headers);
-                try {
-                    final MessageMapper mapper = createMessageMapper();
-                    mapper.begin();
-                    mapper.save(message);
-                    mapper.commit();
-                } catch (PersistenceException e) {
-                    throw new MailboxException(e);
-                }
-                MessageResult messageResult = fillMessageResult(message, 
fetchGroup);
+                final MessageMapper mapper = createMessageMapper();
+
+                mapper.begin();
+                mapper.save(message);
+                mapper.commit();
+
+                final MessageResult messageResult = fillMessageResult(message, 
fetchGroup);
                 getUidChangeTracker().found(messageResult);
+
                 return messageResult;
             } catch (IOException e) {
                 throw new MailboxException(e);
             } catch (MessagingException e) {
                 throw new MailboxException(e);
-            }
-        } else {
-            // mailboxRow==null
-            throw new MailboxException("Mailbox has been deleted");
+            }    
         }
     }
 
@@ -152,8 +145,7 @@
         return results;
     }
 
-    private int size(MimeMessage message) throws IOException,
-    MessagingException {
+    private int size(MimeMessage message) throws IOException, 
MessagingException {
         // TODO very ugly size mesurement
         ByteArrayOutputStream sizeBos = new ByteArrayOutputStream();
         message.writeTo(new CRLFOutputStream(sizeBos));
@@ -162,26 +154,17 @@
     }
 
     private Mailbox reserveNextUid() throws  MailboxException {
-        final Mailbox mailbox;
-        try {
-            final MailboxMapper mapper = createMailboxMapper();
-            mailbox = mapper.consumeNextUid(mailboxId);
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
-        } 
+        final MailboxMapper mapper = createMailboxMapper();
+        final Mailbox mailbox = mapper.consumeNextUid(mailboxId);
         return mailbox;
     }
 
     public Iterator getMessages(final MessageRange set, FetchGroup fetchGroup,
             MailboxSession mailboxSession) throws MailboxException {
         UidRange range = uidRangeForMessageSet(set);
-        try {
-            final MessageMapper messageMapper = createMessageMapper();
-            final List<Message> rows = new 
ArrayList<Message>(messageMapper.findInMailbox(set, mailboxId));
-            return getMessages(fetchGroup, range, rows);
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
-        }
+        final MessageMapper messageMapper = createMessageMapper();
+        final List<Message> rows = new 
ArrayList<Message>(messageMapper.findInMailbox(set, mailboxId));
+        return getMessages(fetchGroup, range, rows);
     }
 
     private JPAResultIterator getMessages(FetchGroup result, UidRange range, 
List<Message> messages) {
@@ -224,25 +207,21 @@
     }
 
     public long[] recent(boolean reset, MailboxSession mailboxSession) throws 
MailboxException {
-        try {
-            final MessageMapper mapper = createMessageMapper();
-            mapper.begin();
-            final List<Message> messages = 
mapper.findRecentMessagesInMailbox(mailboxId);
-            final long[] results = new long[messages.size()];
-
-            int count = 0;
-            for (Message message:messages) {
-                results[count++] = message.getUid();
-                if (reset) {
-                    message.unsetRecent();
-                }
+        final MessageMapper mapper = createMessageMapper();
+        mapper.begin();
+        final List<Message> messages = 
mapper.findRecentMessagesInMailbox(mailboxId);
+        final long[] results = new long[messages.size()];
+
+        int count = 0;
+        for (Message message:messages) {
+            results[count++] = message.getUid();
+            if (reset) {
+                message.unsetRecent();
             }
+        }
 
-            mapper.commit();
-            return results;
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
-        } 
+        mapper.commit();
+        return results;
     }
 
     public MessageResult getFirstUnseen(FetchGroup fetchGroup,
@@ -261,21 +240,15 @@
                 result = null;
             }
             return result;
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
         } catch (MessagingException e) {
             throw new MailboxException(e);
         }
     }
 
     public int getUnseenCount(MailboxSession mailboxSession) throws 
MailboxException {
-        try {
-            final MessageMapper messageMapper = createMessageMapper();
-            final int count = (int) 
messageMapper.countUnseenMessagesInMailbox(mailboxId);
-            return count;
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
-        }
+        final MessageMapper messageMapper = createMessageMapper();
+        final int count = (int) 
messageMapper.countUnseenMessagesInMailbox(mailboxId);
+        return count;
     }
 
     public Iterator expunge(MessageRange set, FetchGroup fetchGroup,
@@ -285,25 +258,21 @@
 
     private Iterator doExpunge(final MessageRange set, FetchGroup fetchGroup)
     throws MailboxException {
-        try {
-            final MessageMapper mapper = createMessageMapper();
-            mapper.begin();
-            final List<Message> messages = 
mapper.findMarkedForDeletionInMailbox(set, mailboxId);
-            final long[] uids = uids(messages);
-            final OrFetchGroup orFetchGroup = new OrFetchGroup(fetchGroup, 
FetchGroup.FLAGS);
-            final JPAResultIterator resultIterator = new 
JPAResultIterator(messages, orFetchGroup);
-            // ensure all results are loaded before deletion
-            final List<MessageResult> messageResults = resultIterator.toList();
-
-            for (Message message:messages) {
-                mapper.delete(message);
-            }
-            mapper.commit();
-            getUidChangeTracker().expunged(uids);
-            return messageResults.iterator();
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
-        }
+        final MessageMapper mapper = createMessageMapper();
+        mapper.begin();
+        final List<Message> messages = 
mapper.findMarkedForDeletionInMailbox(set, mailboxId);
+        final long[] uids = uids(messages);
+        final OrFetchGroup orFetchGroup = new OrFetchGroup(fetchGroup, 
FetchGroup.FLAGS);
+        final JPAResultIterator resultIterator = new 
JPAResultIterator(messages, orFetchGroup);
+        // ensure all results are loaded before deletion
+        final List<MessageResult> messageResults = resultIterator.toList();
+
+        for (Message message:messages) {
+            mapper.delete(message);
+        }
+        mapper.commit();
+        getUidChangeTracker().expunged(uids);
+        return messageResults.iterator();
     }
 
 
@@ -327,40 +296,36 @@
     private Iterator doSetFlags(Flags flags, boolean value, boolean replace,
             final MessageRange set, FetchGroup fetchGroup,
             MailboxSession mailboxSession) throws MailboxException {
-        try {
-            final MessageMapper mapper = createMessageMapper();
-            mapper.begin();
-            final List<Message> messages = mapper.findInMailbox(set, 
mailboxId);
-            UidRange uidRange = uidRangeForMessageSet(set);
-            getUidChangeTracker().found(uidRange,
-                    MessageRowUtils.toMessageFlags(messages));
-            for (final Message message:messages) {
-                if (replace) {
-                    message.setFlags(flags);
+        final MessageMapper mapper = createMessageMapper();
+        mapper.begin();
+        final List<Message> messages = mapper.findInMailbox(set, mailboxId);
+        UidRange uidRange = uidRangeForMessageSet(set);
+        getUidChangeTracker().found(uidRange,
+                MessageRowUtils.toMessageFlags(messages));
+        for (final Message message:messages) {
+            if (replace) {
+                message.setFlags(flags);
+            } else {
+                Flags current = message.createFlags();
+                if (value) {
+                    current.add(flags);
                 } else {
-                    Flags current = message.createFlags();
-                    if (value) {
-                        current.add(flags);
-                    } else {
-                        current.remove(flags);
-                    }
-                    message.setFlags(current);
+                    current.remove(flags);
                 }
-                mapper.save(message);
+                message.setFlags(current);
             }
-            final OrFetchGroup orFetchGroup = new OrFetchGroup(fetchGroup,
-                    FetchGroup.FLAGS);
-            final JPAResultIterator resultIterator = new JPAResultIterator(
-                    messages, orFetchGroup);
-            final org.apache.james.imap.mailbox.util.MessageFlags[] 
messageFlags = resultIterator
-            .getMessageFlags();
-            mapper.commit();
-            tracker.flagsUpdated(messageFlags, mailboxSession.getSessionId());
-            tracker.found(uidRange, messageFlags);
-            return resultIterator;
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
+            mapper.save(message);
         }
+        final OrFetchGroup orFetchGroup = new OrFetchGroup(fetchGroup,
+                FetchGroup.FLAGS);
+        final JPAResultIterator resultIterator = new JPAResultIterator(
+                messages, orFetchGroup);
+        final org.apache.james.imap.mailbox.util.MessageFlags[] messageFlags = 
resultIterator
+        .getMessageFlags();
+        mapper.commit();
+        tracker.flagsUpdated(messageFlags, mailboxSession.getSessionId());
+        tracker.found(uidRange, messageFlags);
+        return resultIterator;
     }
 
     public void addListener(MailboxListener listener) throws MailboxException {
@@ -374,11 +339,11 @@
 
     public long getUidNext(MailboxSession mailboxSession) throws 
MailboxException {
         Mailbox mailbox = getMailboxRow();
-        if (mailbox != null) {
+        if (mailbox == null) {
+            throw new MailboxNotFoundException("Mailbox has been deleted");
+        } else {
             getUidChangeTracker().foundLastUid(mailbox.getLastUid());
             return getUidChangeTracker().getLastUid() + 1;
-        } else {
-            throw new MailboxException("Mailbox has been deleted");
         }
     }
 
@@ -387,12 +352,8 @@
     }
 
     private Mailbox getMailboxRow() throws MailboxException {
-        try {
-            final MailboxMapper mapper = createMailboxMapper();
-            return mapper.findMailboxById(mailboxId);
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
-        }
+        final MailboxMapper mapper = createMailboxMapper();
+        return mapper.findMailboxById(mailboxId);
     }
 
     private MailboxMapper createMailboxMapper() {
@@ -402,29 +363,25 @@
 
     public Iterator search(SearchQuery query, FetchGroup fetchGroup,
             MailboxSession mailboxSession) throws MailboxException {
-        try {
-            final MessageMapper messageMapper = createMessageMapper();
-            final List<Message> messages = 
messageMapper.searchMailbox(mailboxId, query);
-            final List<Message> filteredMessages = new 
ArrayList<Message>(messages.size());
-            for (Message message:messages) {
-                try {
-                    if (searches.isMatch(query, message)) {
-                        filteredMessages.add(message);
-                    }
-                } catch (MailboxException e) {
-                    getLog()
-                    .info(
-                            "Cannot test message against search criteria. Will 
continue to test other messages.",
-                            e);
-                    if (getLog().isDebugEnabled())
-                        getLog().debug("UID: " + message.getUid());
+        final MessageMapper messageMapper = createMessageMapper();
+        final List<Message> messages = messageMapper.searchMailbox(mailboxId, 
query);
+        final List<Message> filteredMessages = new 
ArrayList<Message>(messages.size());
+        for (Message message:messages) {
+            try {
+                if (searches.isMatch(query, message)) {
+                    filteredMessages.add(message);
                 }
+            } catch (MailboxException e) {
+                getLog()
+                .info(
+                        "Cannot test message against search criteria. Will 
continue to test other messages.",
+                        e);
+                if (getLog().isDebugEnabled())
+                    getLog().debug("UID: " + message.getUid());
             }
-
-            return getResults(fetchGroup, filteredMessages);
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
         }
+
+        return getResults(fetchGroup, filteredMessages);
     }
 
     public boolean isWriteable() {
@@ -467,11 +424,9 @@
                     toMailbox.getUidChangeTracker().found(messageResult);
                 }
             }
-            
+
             mapper.commit();
 
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
         } catch (MessagingException e) {
             throw new MailboxException(e);
         }

Modified: 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java?rev=732092&r1=732091&r2=732092&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
 (original)
+++ 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxManager.java
 Tue Jan  6 12:09:45 2009
@@ -28,8 +28,6 @@
 import java.util.Random;
 
 import javax.persistence.EntityManagerFactory;
-import javax.persistence.NoResultException;
-import javax.persistence.PersistenceException;
 
 import org.apache.commons.logging.Log;
 import org.apache.james.api.imap.AbstractLogEnabled;
@@ -37,8 +35,8 @@
 import org.apache.james.imap.jpa.mail.map.openjpa.OpenJPAMailboxMapper;
 import org.apache.james.imap.jpa.mail.model.Mailbox;
 import org.apache.james.imap.mailbox.ListResult;
-import org.apache.james.imap.mailbox.MailboxExistsException;
 import org.apache.james.imap.mailbox.MailboxException;
+import org.apache.james.imap.mailbox.MailboxExistsException;
 import org.apache.james.imap.mailbox.MailboxExpression;
 import org.apache.james.imap.mailbox.MailboxListener;
 import org.apache.james.imap.mailbox.MailboxManager;
@@ -68,42 +66,34 @@
     }
 
     public org.apache.james.imap.mailbox.Mailbox getMailbox(String mailboxName)
-            throws MailboxException {
+    throws MailboxException {
         return doGetMailbox(mailboxName);
     }
 
     private JPAMailbox doGetMailbox(String mailboxName) throws 
MailboxException {
-        try {
-            synchronized (mailboxes) {
-                final MailboxMapper mapper = createMailboxMapper();
-                Mailbox mailboxRow = mapper.findMailboxByName(mailboxName);
+        synchronized (mailboxes) {
+            final MailboxMapper mapper = createMailboxMapper();
+            Mailbox mailboxRow = mapper.findMailboxByName(mailboxName);
 
-                if (mailboxRow == null) {
-                    getLog().info("Mailbox '" + mailboxName + "' not found.");
-                    throw new MailboxNotFoundException(mailboxName);
-                    
-                } else {
-                    getLog().debug("Loaded mailbox " + mailboxName);
+            if (mailboxRow == null) {
+                getLog().info("Mailbox '" + mailboxName + "' not found.");
+                throw new MailboxNotFoundException(mailboxName);
 
-                    JPAMailbox result = (JPAMailbox) 
mailboxes.get(mailboxName);
-                    if (result == null) {
-                        result = new JPAMailbox(mailboxRow, getLog(), 
entityManagerFactory);
-                        mailboxes.put(mailboxName, result);
-                    }
-                    return result;
+            } else {
+                getLog().debug("Loaded mailbox " + mailboxName);
+
+                JPAMailbox result = (JPAMailbox) mailboxes.get(mailboxName);
+                if (result == null) {
+                    result = new JPAMailbox(mailboxRow, getLog(), 
entityManagerFactory);
+                    mailboxes.put(mailboxName, result);
                 }
+                return result;
             }
-        } catch (NoResultException e) {
-            getLog().info("Mailbox '" + mailboxName + "' not found.");
-            throw new MailboxNotFoundException(mailboxName);
-            
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
         }
     }
 
     public void createMailbox(String namespaceName)
-            throws MailboxException {
+    throws MailboxException {
         getLog().debug("createMailbox " + namespaceName);
         final int length = namespaceName.length();
         if (length == 0) {
@@ -124,7 +114,7 @@
                     // TODO: add explicit support for namespaces
                     if (index > 0 && count++ > 1) {
                         final String mailbox = namespaceName
-                                .substring(0, index);
+                        .substring(0, index);
                         if (!mailboxExists(mailbox)) {
                             doCreate(mailbox);
                         }
@@ -142,84 +132,68 @@
 
     private void doCreate(String namespaceName) throws MailboxException {
         Mailbox mailbox = new Mailbox(namespaceName, 
Math.abs(random.nextInt()));
-        try {
-            final MailboxMapper mapper = createMailboxMapper();
-            mapper.begin();
-            mapper.save(mailbox);
-            mapper.commit();
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
-        }
+        final MailboxMapper mapper = createMailboxMapper();
+        mapper.begin();
+        mapper.save(mailbox);
+        mapper.commit();
     }
 
     public void deleteMailbox(String mailboxName, MailboxSession session)
-            throws MailboxException {
+    throws MailboxException {
         getLog().info("deleteMailbox " + mailboxName);
         synchronized (mailboxes) {
-            try {
-                // TODO put this into a serilizable transaction
-                final MailboxMapper mapper = createMailboxMapper();
-                mapper.begin();
-                Mailbox mr = mapper.findMailboxByName(mailboxName);
-                if (mr == null) {
-                    throw new MailboxNotFoundException("Mailbox not found");
-                }
-                mapper.delete(mr);
-                mapper.commit();
-                final JPAMailbox mailbox = mailboxes.remove(mailboxName);
-                if (mailbox != null) {
-                    mailbox.deleted(session);
-                }
-            } catch (NoResultException e) {
-                throw new MailboxNotFoundException(mailboxName);
-            } catch (PersistenceException e) {
-                throw new MailboxException(e);
+            // TODO put this into a serilizable transaction
+            final MailboxMapper mapper = createMailboxMapper();
+            mapper.begin();
+            Mailbox mr = mapper.findMailboxByName(mailboxName);
+            if (mr == null) {
+                throw new MailboxNotFoundException("Mailbox not found");
+            }
+            mapper.delete(mr);
+            mapper.commit();
+            final JPAMailbox mailbox = mailboxes.remove(mailboxName);
+            if (mailbox != null) {
+                mailbox.deleted(session);
             }
         }
     }
 
     public void renameMailbox(String from, String to)
-            throws MailboxException {
+    throws MailboxException {
         final Log log = getLog();
         if (log.isDebugEnabled()) log.debug("renameMailbox " + from + " to " + 
to);
-        try {
-            synchronized (mailboxes) {
-                if (mailboxExists(to)) {
-                    throw new MailboxExistsException(to);
-                }
-                
-                final MailboxMapper mapper = createMailboxMapper();            
    
-                mapper.begin();
-                // TODO put this into a serilizable transaction
-                final Mailbox mailbox = mapper.findMailboxByName(from);
+        synchronized (mailboxes) {
+            if (mailboxExists(to)) {
+                throw new MailboxExistsException(to);
+            }
 
-                if (mailbox == null) {
-                    throw new MailboxNotFoundException(from);
-                }
-                mailbox.setName(to);
-                mapper.save(mailbox);
+            final MailboxMapper mapper = createMailboxMapper();                
+            mapper.begin();
+            // TODO put this into a serilizable transaction
+            final Mailbox mailbox = mapper.findMailboxByName(from);
 
-                changeMailboxName(from, to);
+            if (mailbox == null) {
+                throw new MailboxNotFoundException(from);
+            }
+            mailbox.setName(to);
+            mapper.save(mailbox);
 
-                // rename submailbox
-                final List<Mailbox> subMailboxes = 
mapper.findMailboxWithNameLike(from + HIERARCHY_DELIMITER + "%");
-                for (Mailbox sub:subMailboxes) {
-                    final String subOriginalName = sub.getName();
-                    final String subNewName = to + 
subOriginalName.substring(from.length());
-                    sub.setName(subNewName);
-                    mapper.save(sub);
-                    
-                    changeMailboxName(subOriginalName, subNewName);
-                    
-                    if (log.isDebugEnabled()) log.debug("Rename mailbox 
sub-mailbox " + subOriginalName + " to "
-                                    + subNewName);
-                }
-                mapper.commit();
+            changeMailboxName(from, to);
+
+            // rename submailbox
+            final List<Mailbox> subMailboxes = 
mapper.findMailboxWithNameLike(from + HIERARCHY_DELIMITER + "%");
+            for (Mailbox sub:subMailboxes) {
+                final String subOriginalName = sub.getName();
+                final String subNewName = to + 
subOriginalName.substring(from.length());
+                sub.setName(subNewName);
+                mapper.save(sub);
+
+                changeMailboxName(subOriginalName, subNewName);
+
+                if (log.isDebugEnabled()) log.debug("Rename mailbox 
sub-mailbox " + subOriginalName + " to "
+                        + subNewName);
             }
-        } catch (NoResultException e) {
-            throw new MailboxNotFoundException(from);
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
+            mapper.commit();
         }
     }
 
@@ -244,7 +218,7 @@
     }
 
     public ListResult[] list(final MailboxExpression mailboxExpression)
-            throws MailboxException {
+    throws MailboxException {
         final char localWildcard = mailboxExpression.getLocalWildcard();
         final char freeWildcard = mailboxExpression.getFreeWildcard();
         final String base = mailboxExpression.getBase();
@@ -259,69 +233,49 @@
                 HIERARCHY_DELIMITER).replace(freeWildcard, SQL_WILDCARD_CHAR)
                 .replace(localWildcard, SQL_WILDCARD_CHAR);
 
-        try {
-            final MailboxMapper mapper = createMailboxMapper();
-            final List<Mailbox> mailboxes = 
mapper.findMailboxWithNameLike(search);
-            final List<ListResult> listResults = new 
ArrayList<ListResult>(mailboxes.size());
-            for (Mailbox mailbox: mailboxes) {
-                final String name = mailbox.getName();
-                if (name.startsWith(base)) {
-                    final String match = name.substring(baseLength);
-                    if (mailboxExpression.isExpressionMatch(match,
-                            HIERARCHY_DELIMITER)) {
-                        listResults.add(new ListResultImpl(name, "."));
-                    }
+        final MailboxMapper mapper = createMailboxMapper();
+        final List<Mailbox> mailboxes = mapper.findMailboxWithNameLike(search);
+        final List<ListResult> listResults = new 
ArrayList<ListResult>(mailboxes.size());
+        for (Mailbox mailbox: mailboxes) {
+            final String name = mailbox.getName();
+            if (name.startsWith(base)) {
+                final String match = name.substring(baseLength);
+                if (mailboxExpression.isExpressionMatch(match,
+                        HIERARCHY_DELIMITER)) {
+                    listResults.add(new ListResultImpl(name, "."));
                 }
             }
-            final ListResult[] results = (ListResult[]) listResults
-                    .toArray(ListResult.EMPTY_ARRAY);
-            Arrays.sort(results);
-            return results;
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
         }
+        final ListResult[] results = (ListResult[]) listResults
+        .toArray(ListResult.EMPTY_ARRAY);
+        Arrays.sort(results);
+        return results;
 
     }
 
-
-    public void setSubscription(String mailboxName, boolean value) {
-        // TODO implement subscriptions
-    }
-
-    public boolean mailboxExists(String mailboxName)
-            throws MailboxException {
-        try {
-            synchronized (mailboxes) {
-                final MailboxMapper mapper = createMailboxMapper();
-                final long count = mapper.countMailboxesWithName(mailboxName);
-                if (count == 0) {
-                    mailboxes.remove(mailboxName);
-                    return false;
+    public boolean mailboxExists(String mailboxName) throws MailboxException {
+        synchronized (mailboxes) {
+            final MailboxMapper mapper = createMailboxMapper();
+            final long count = mapper.countMailboxesWithName(mailboxName);
+            if (count == 0) {
+                mailboxes.remove(mailboxName);
+                return false;
+            } else {
+                if (count == 1) {
+                    return true;
                 } else {
-                    if (count == 1) {
-                        return true;
-                    } else {
-                        throw new MailboxException("Expected one mailbox but 
found " + count + " mailboxes");
-                    }
+                    throw new MailboxException("Expected one mailbox but found 
" + count + " mailboxes");
                 }
             }
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
         }
     }
 
-
-
     public void deleteEverything() throws MailboxException {
-        try {
-            final MailboxMapper mapper = createMailboxMapper();
-            mapper.begin();
-            mapper.deleteAll();
-            mapper.commit();
-            mailboxes.clear();
-        } catch (PersistenceException e) {
-            throw new MailboxException(e);
-        }
+        final MailboxMapper mapper = createMailboxMapper();
+        mapper.begin();
+        mapper.deleteAll();
+        mapper.commit();
+        mailboxes.clear();
     }
 
     private MailboxMapper createMailboxMapper() {
@@ -338,7 +292,7 @@
             mailboxPath = HIERARCHY_DELIMITER + mailboxPath;
         }
         final String result = USER_NAMESPACE + HIERARCHY_DELIMITER + userName
-                + mailboxPath;
+        + mailboxPath;
         return result;
     }
 
@@ -347,7 +301,7 @@
     }
 
     public void subscribe(String user, String mailbox)
-            throws SubscriptionException {
+    throws SubscriptionException {
         subscriber.subscribe(user, mailbox);
     }
 
@@ -356,7 +310,7 @@
     }
 
     public void unsubscribe(String user, String mailbox)
-            throws SubscriptionException {
+    throws SubscriptionException {
         subscriber.unsubscribe(user, mailbox);
     }
 
@@ -364,5 +318,4 @@
         final JPAMailbox mailbox = doGetMailbox(mailboxName);
         mailbox.addListener(listener);
     }
-
 }

Modified: 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MailboxMapper.java?rev=732092&r1=732091&r2=732092&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MailboxMapper.java
 (original)
+++ 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MailboxMapper.java
 Tue Jan  6 12:09:45 2009
@@ -22,47 +22,94 @@
 import java.util.List;
 
 import javax.persistence.EntityManager;
+import javax.persistence.NoResultException;
+import javax.persistence.PersistenceException;
 
 import org.apache.james.imap.jpa.mail.model.Mailbox;
+import org.apache.james.imap.mailbox.MailboxNotFoundException;
+import org.apache.james.imap.mailbox.StorageException;
 
 /**
  * Data access management for mailbox.
  */
 public abstract class MailboxMapper extends Mapper {
-    
+
     public MailboxMapper(EntityManager entityManager) {
         super(entityManager);
     }
 
-    public void save(Mailbox mailbox) {
-        entityManager.persist(mailbox);
-    }
-
-    public Mailbox findMailboxByName(String name) {
-        return (Mailbox) 
entityManager.createNamedQuery("findMailboxByName").setParameter("nameParam", 
name).getSingleResult();
-    }
-
-    public void delete(Mailbox mailbox) {
-        entityManager.remove(mailbox);
+    public void save(Mailbox mailbox) throws StorageException {
+        try {
+            entityManager.persist(mailbox);
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        } 
+    }
+
+    public Mailbox findMailboxByName(String name) throws StorageException, 
MailboxNotFoundException {
+        try {
+            return (Mailbox) 
entityManager.createNamedQuery("findMailboxByName").setParameter("nameParam", 
name).getSingleResult();
+        } catch (NoResultException e) {
+            throw new MailboxNotFoundException(name);
+            
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        } 
+    }
+
+    public void delete(Mailbox mailbox) throws StorageException {
+        try {  
+            entityManager.remove(mailbox);
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        } 
     }
 
     @SuppressWarnings("unchecked")
-    public List<Mailbox> findMailboxWithNameLike(String name) {
-        return 
entityManager.createNamedQuery("findMailboxWithNameLike").setParameter("nameParam",
 name).getResultList();
-    }
-
-    public void deleteAll() {
-        entityManager.createNamedQuery("deleteAll").executeUpdate();
-    }
-
-    public long countMailboxesWithName(String name) {
-        return (Long) 
entityManager.createNamedQuery("countMailboxesWithName").setParameter("nameParam",
 name).getSingleResult();
-    }
-
-    public Mailbox findMailboxById(long mailboxId) {
-        return (Mailbox) 
entityManager.createNamedQuery("findMailboxById").setParameter("idParam", 
mailboxId).getSingleResult();
+    public List<Mailbox> findMailboxWithNameLike(String name) throws 
StorageException {
+        try {
+            return 
entityManager.createNamedQuery("findMailboxWithNameLike").setParameter("nameParam",
 name).getResultList();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        } 
+    }
+
+    public void deleteAll() throws StorageException {
+        try {
+            entityManager.createNamedQuery("deleteAll").executeUpdate();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        } 
+    }
+
+    public long countMailboxesWithName(String name) throws StorageException {
+        try {
+            return (Long) 
entityManager.createNamedQuery("countMailboxesWithName").setParameter("nameParam",
 name).getSingleResult();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        } 
+    }
+
+    public Mailbox findMailboxById(long mailboxId) throws StorageException, 
MailboxNotFoundException  {
+        try {
+            return (Mailbox) 
entityManager.createNamedQuery("findMailboxById").setParameter("idParam", 
mailboxId).getSingleResult();
+        } catch (NoResultException e) {
+            throw new MailboxNotFoundException(mailboxId);   
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        } 
+    }
+
+    public Mailbox consumeNextUid(long mailboxId) throws StorageException, 
MailboxNotFoundException {
+        try {
+            return doConsumeNextUid(mailboxId);
+        } catch (NoResultException e) {
+            throw new MailboxNotFoundException(mailboxId);
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        } 
     }
 
     /** Locking is required and is implementation specific */
-    public abstract Mailbox consumeNextUid(long mailboxId);
+    protected abstract Mailbox doConsumeNextUid(long mailboxId) throws 
PersistenceException;
 }

Modified: 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/Mapper.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/Mapper.java?rev=732092&r1=732091&r2=732092&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/Mapper.java
 (original)
+++ 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/Mapper.java
 Tue Jan  6 12:09:45 2009
@@ -19,6 +19,9 @@
 package org.apache.james.imap.jpa.mail;
 
 import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
+
+import org.apache.james.imap.mailbox.StorageException;
 
 abstract class Mapper {
 
@@ -29,11 +32,19 @@
         this.entityManager = entityManager;
     }
     
-    public void begin() {
-        entityManager.getTransaction().begin();
+    public void begin() throws StorageException {
+        try {
+            entityManager.getTransaction().begin();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        }
     }
     
-    public void commit() {
-        entityManager.getTransaction().commit();
+    public void commit() throws StorageException {
+        try {
+            entityManager.getTransaction().commit();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        }
     }
 }

Modified: 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MessageMapper.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MessageMapper.java?rev=732092&r1=732091&r2=732092&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MessageMapper.java
 (original)
+++ 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/MessageMapper.java
 Tue Jan  6 12:09:45 2009
@@ -21,131 +21,153 @@
 import java.util.List;
 
 import javax.persistence.EntityManager;
+import javax.persistence.PersistenceException;
 
 import org.apache.james.imap.jpa.mail.model.Message;
 import org.apache.james.imap.mailbox.MessageRange;
 import org.apache.james.imap.mailbox.SearchQuery;
+import org.apache.james.imap.mailbox.StorageException;
 import org.apache.james.imap.mailbox.SearchQuery.Criterion;
 import org.apache.james.imap.mailbox.SearchQuery.NumericRange;
 
 public class MessageMapper extends Mapper {
-    
+
     public MessageMapper(EntityManager entityManager) {
         super(entityManager);
     }
 
-    public List<Message> findInMailbox(MessageRange set, long mailboxId) {
-        final List<Message> results;
-        switch (set.getType()) {
-            case MessageRange.TYPE_UID:
-                final long from = set.getUidFrom();
-                final long to = set.getUidTo();
-                if (from == to) {
-                    results = findMessagesInMailboxWithUID(mailboxId, from);
-                } else if (to > 0) {
-                    results = findMessagesInMailboxBetweenUIDs(mailboxId, 
from, to);
-                } else {
-                    results = findMessagesInMailboxAfterUID(mailboxId, from);
-                }
-                break;
-            default:
-                //TODO: Log?
-            case MessageRange.TYPE_ALL:
-                results = findMessagesInMailbox(mailboxId);
-                break;
+    public List<Message> findInMailbox(MessageRange set, long mailboxId) 
throws StorageException {
+        try {
+            final List<Message> results;
+            switch (set.getType()) {
+                case MessageRange.TYPE_UID:
+                    final long from = set.getUidFrom();
+                    final long to = set.getUidTo();
+                    if (from == to) {
+                        results = findMessagesInMailboxWithUID(mailboxId, 
from);
+                    } else if (to > 0) {
+                        results = findMessagesInMailboxBetweenUIDs(mailboxId, 
from, to);
+                    } else {
+                        results = findMessagesInMailboxAfterUID(mailboxId, 
from);
+                    }
+                    break;
+                default:
+                    //TODO: Log?
+                case MessageRange.TYPE_ALL:
+                    results = findMessagesInMailbox(mailboxId);
+                    break;
+            }
+            return results;
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
         }
-        return results;
     }
 
     @SuppressWarnings("unchecked")
     private List<Message> findMessagesInMailboxAfterUID(long mailboxId, long 
uid) {
         return entityManager.createNamedQuery("findMessagesInMailboxAfterUID")
-            .setParameter("idParam", mailboxId)
-            .setParameter("uidParam", uid).getResultList();
+        .setParameter("idParam", mailboxId)
+        .setParameter("uidParam", uid).getResultList();
     }
-    
+
     @SuppressWarnings("unchecked")
     private List<Message> findMessagesInMailboxWithUID(long mailboxId, long 
uid) {
         return entityManager.createNamedQuery("findMessagesInMailboxWithUID")
-            .setParameter("idParam", mailboxId)
-            .setParameter("uidParam", uid).getResultList();
+        .setParameter("idParam", mailboxId)
+        .setParameter("uidParam", uid).getResultList();
     }
-    
+
     @SuppressWarnings("unchecked")
     private List<Message> findMessagesInMailboxBetweenUIDs(long mailboxId, 
long from, long to) {
         return 
entityManager.createNamedQuery("findMessagesInMailboxBetweenUIDs")
-            .setParameter("idParam", mailboxId)
-            .setParameter("fromParam", from)
-            .setParameter("toParam", to).getResultList();
+        .setParameter("idParam", mailboxId)
+        .setParameter("fromParam", from)
+        .setParameter("toParam", to).getResultList();
     }
-    
+
     @SuppressWarnings("unchecked")
     private List<Message> findMessagesInMailbox(long mailboxId) {
         return 
entityManager.createNamedQuery("findMessagesInMailbox").setParameter("idParam", 
mailboxId).getResultList();
     }
 
-    public List<Message> findMarkedForDeletionInMailbox(final MessageRange 
set, final long mailboxId) {
-        final List<Message> results;
-        switch (set.getType()) {
-            case MessageRange.TYPE_UID:
-                final long from = set.getUidFrom();
-                final long to = set.getUidTo();
-                if (from == to) {
-                    results = findDeletedMessagesInMailboxWithUID(mailboxId, 
from);
-                } else if (to > 0) {
-                    results = 
findDeletedMessagesInMailboxBetweenUIDs(mailboxId, from, to);
-                } else {
-                    results = findDeletedMessagesInMailboxAfterUID(mailboxId, 
from);
-                }
-                break;
-            default:
-                //TODO: Log?
-            case MessageRange.TYPE_ALL:
-                results = findDeletedMessagesInMailbox(mailboxId);
-                break;
+    public List<Message> findMarkedForDeletionInMailbox(final MessageRange 
set, final long mailboxId) throws StorageException {
+        try {
+            final List<Message> results;
+            switch (set.getType()) {
+                case MessageRange.TYPE_UID:
+                    final long from = set.getUidFrom();
+                    final long to = set.getUidTo();
+                    if (from == to) {
+                        results = 
findDeletedMessagesInMailboxWithUID(mailboxId, from);
+                    } else if (to > 0) {
+                        results = 
findDeletedMessagesInMailboxBetweenUIDs(mailboxId, from, to);
+                    } else {
+                        results = 
findDeletedMessagesInMailboxAfterUID(mailboxId, from);
+                    }
+                    break;
+                default:
+                    //TODO: Log?
+                case MessageRange.TYPE_ALL:
+                    results = findDeletedMessagesInMailbox(mailboxId);
+                    break;
+            }
+            return results;
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
         }
-        return results;
     }
-    
+
     @SuppressWarnings("unchecked")
     private List<Message> findDeletedMessagesInMailbox(long mailboxId) {
         return 
entityManager.createNamedQuery("findDeletedMessagesInMailbox").setParameter("idParam",
 mailboxId).getResultList();
     }
-    
+
     @SuppressWarnings("unchecked")
     private List<Message> findDeletedMessagesInMailboxAfterUID(long mailboxId, 
long uid) {
         return 
entityManager.createNamedQuery("findDeletedMessagesInMailboxBetweenUIDs")
-            .setParameter("idParam", mailboxId)
-            .setParameter("uidParam", uid).getResultList();
+        .setParameter("idParam", mailboxId)
+        .setParameter("uidParam", uid).getResultList();
     }
-    
+
     @SuppressWarnings("unchecked")
     private List<Message> findDeletedMessagesInMailboxWithUID(long mailboxId, 
long uid) {
         return 
entityManager.createNamedQuery("findDeletedMessagesInMailboxBetweenUIDs")
-            .setParameter("idParam", mailboxId)
-            .setParameter("uidParam", uid).getResultList();
+        .setParameter("idParam", mailboxId)
+        .setParameter("uidParam", uid).getResultList();
     }
-    
+
     @SuppressWarnings("unchecked")
     private List<Message> findDeletedMessagesInMailboxBetweenUIDs(long 
mailboxId, long from, long to) {
         return 
entityManager.createNamedQuery("findDeletedMessagesInMailboxBetweenUIDs")
-            .setParameter("idParam", mailboxId)
-            .setParameter("fromParam", from)
-            .setParameter("toParam", to).getResultList();
+        .setParameter("idParam", mailboxId)
+        .setParameter("fromParam", from)
+        .setParameter("toParam", to).getResultList();
     }
 
-    public long countMessagesInMailbox(long mailboxId) {
-        return (Long) 
entityManager.createNamedQuery("countMessagesInMailbox").setParameter("idParam",
 mailboxId).getSingleResult();
+    public long countMessagesInMailbox(long mailboxId) throws StorageException 
{
+        try {
+            return (Long) 
entityManager.createNamedQuery("countMessagesInMailbox").setParameter("idParam",
 mailboxId).getSingleResult();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        }
     }
-    
-    public long countUnseenMessagesInMailbox(long mailboxId){
-        return (Long) 
entityManager.createNamedQuery("countUnseenMessagesInMailbox").setParameter("idParam",
 mailboxId).getSingleResult();
+
+    public long countUnseenMessagesInMailbox(long mailboxId) throws 
StorageException {
+        try {
+            return (Long) 
entityManager.createNamedQuery("countUnseenMessagesInMailbox").setParameter("idParam",
 mailboxId).getSingleResult();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        }
     }
 
     @SuppressWarnings("unchecked")
-    public List<Message> searchMailbox(long mailboxId, SearchQuery query) {
-        final String jql = formulateJQL(mailboxId, query);
-        return entityManager.createQuery(jql).getResultList();
+    public List<Message> searchMailbox(long mailboxId, SearchQuery query) 
throws StorageException {
+        try {
+            final String jql = formulateJQL(mailboxId, query);
+            return entityManager.createQuery(jql).getResultList();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        }
     }
 
     private String formulateJQL(long mailboxId, SearchQuery query) {
@@ -160,7 +182,7 @@
                 for (int i = 0; i < ranges.length; i++) {
                     final long low = ranges[i].getLowValue();
                     final long high = ranges[i].getHighValue();
-                    
+
                     if (low == Long.MAX_VALUE) {
                         queryBuilder.append(" AND message.uid<=").append(high);
                     } else if (low == high) {
@@ -174,22 +196,38 @@
         final String jql = queryBuilder.toString();
         return jql;
     }
-    
-    public void delete(Message message)  {
-        entityManager.remove(message);
+
+    public void delete(Message message) throws StorageException {
+        try {
+            entityManager.remove(message);
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        }
     }
-    
+
     @SuppressWarnings("unchecked")
-    public List<Message> findUnseenMessagesInMailboxOrderByUid(final long 
mailboxId)  {
-        return 
entityManager.createNamedQuery("findUnseenMessagesInMailboxOrderByUid").setParameter("idParam",
 mailboxId).getResultList();
+    public List<Message> findUnseenMessagesInMailboxOrderByUid(final long 
mailboxId)  throws StorageException {
+        try {
+            return 
entityManager.createNamedQuery("findUnseenMessagesInMailboxOrderByUid").setParameter("idParam",
 mailboxId).getResultList();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        }
     }
-    
+
     @SuppressWarnings("unchecked")
-    public List<Message> findRecentMessagesInMailbox(final long mailboxId) {
-        return 
entityManager.createNamedQuery("findRecentMessagesInMailbox").setParameter("idParam",
 mailboxId).getResultList();
+    public List<Message> findRecentMessagesInMailbox(final long mailboxId) 
throws StorageException {
+        try {
+            return 
entityManager.createNamedQuery("findRecentMessagesInMailbox").setParameter("idParam",
 mailboxId).getResultList();
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        }
     }
 
-    public void save(Message message) {
-        entityManager.persist(message);
+    public void save(Message message) throws StorageException {
+        try {
+            entityManager.persist(message);
+        } catch (PersistenceException e) {
+            throw new StorageException(e);
+        }
     }
 }

Modified: 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/map/openjpa/OpenJPAMailboxMapper.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/map/openjpa/OpenJPAMailboxMapper.java?rev=732092&r1=732091&r2=732092&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/map/openjpa/OpenJPAMailboxMapper.java
 (original)
+++ 
james/protocols/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/map/openjpa/OpenJPAMailboxMapper.java
 Tue Jan  6 12:09:45 2009
@@ -35,7 +35,7 @@
         super(entityManager);
     }
 
-    public Mailbox consumeNextUid(long mailboxId) {
+    public Mailbox doConsumeNextUid(long mailboxId) {
         OpenJPAEntityManager oem = OpenJPAPersistence.cast(entityManager);
         final boolean originalLocking = oem.getOptimistic();
         oem.setOptimistic(false);

Modified: 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxNotFoundException.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxNotFoundException.java?rev=732092&r1=732091&r2=732092&view=diff
==============================================================================
--- 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxNotFoundException.java
 (original)
+++ 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/MailboxNotFoundException.java
 Tue Jan  6 12:09:45 2009
@@ -39,6 +39,14 @@
 
     private final String mailboxName;
 
+    private final long id;
+    
+    public MailboxNotFoundException(long id) {
+        super(message(Long.toString(id)));
+        this.id = id;
+        mailboxName = null;
+    }
+    
     /**
      * 
      * @param mailboxName
@@ -47,14 +55,23 @@
     public MailboxNotFoundException(String mailboxName) {
         super(message(mailboxName));
         this.mailboxName = mailboxName;
+        this.id = 0;
     }
 
     /**
      * Gets the name of the mailbox which cannot be found.
      * 
-     * @return name
+     * @return name or null when only mailbox ID is known
      */
     public final String getMailboxName() {
         return mailboxName;
     }
+
+    /**
+     * Gets the storage id of the mailbox.
+     * @return storage id, or zero when this is not known
+     */
+    public long getId() {
+        return id;
+    }
 }

Added: 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/StorageException.java
URL: 
http://svn.apache.org/viewvc/james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/StorageException.java?rev=732092&view=auto
==============================================================================
--- 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/StorageException.java
 (added)
+++ 
james/protocols/imap/trunk/mailbox/src/main/java/org/apache/james/imap/mailbox/StorageException.java
 Tue Jan  6 12:09:45 2009
@@ -0,0 +1,36 @@
+/****************************************************************
+ * 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.mailbox;
+
+/**
+ * Indicates a general problem in the underlying storage layer.
+ * Used to wrap undiagnosed storage exceptions.
+ */
+public class StorageException extends MailboxException {
+
+    private static final long serialVersionUID = -2645843238080782034L;
+
+    public StorageException(Exception cause) {
+        super(cause);
+    }
+
+    public StorageException(Throwable cause) {
+        super(cause);
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to