james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r984718 - in /james/imap/trunk: jcr/src/main/java/org/apache/james/imap/jcr/mail/ jpa/src/main/java/org/apache/james/imap/jpa/mail/ memory/src/main/java/org/apache/james/imap/inmemory/mail/ store/src/main/java/org/apache/james/imap/store/ s...
Date Thu, 12 Aug 2010 10:44:46 GMT
Author: norman
Date: Thu Aug 12 10:44:45 2010
New Revision: 984718

URL: http://svn.apache.org/viewvc?rev=984718&view=rev
Log:
Replace findUnseenMessages(...) with findFirstUnseenMessageUid(..) to allow the Mapper implementation
to dedicite howto get the uid. (IMAP-191)

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

Modified: james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java?rev=984718&r1=984717&r2=984718&view=diff
==============================================================================
--- james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
(original)
+++ james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMessageMapper.java
Thu Aug 12 10:44:45 2010
@@ -440,30 +440,25 @@ public class JCRMessageMapper extends Ab
 
 
     /*
-     * TODO: Maybe we should better use an ItemVisitor and just traverse through the child
nodes. This could be a way faster
-     * 
      * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
+     * @see org.apache.james.imap.store.mail.MessageMapper#findFirstUnseenMessageUid(org.apache.james.imap.store.mail.model.Mailbox)
      */
-    public List<MailboxMembership<String>> findUnseenMessagesInMailbox(Mailbox<String>
mailbox, int limit) throws StorageException {
+    public Long findFirstUnseenMessageUid(Mailbox<String> mailbox) throws StorageException
{
         try {
-  
-            List<MailboxMembership<String>> list = new ArrayList<MailboxMembership<String>>();
             String queryString = "/jcr:root" + getMailboxPath(mailbox) + "//element(*,jamesMailbox:message)[@"
+ JCRMessage.SEEN_PROPERTY +"='false'] order by @" + JCRMessage.UID_PROPERTY;
 
             QueryManager manager = getSession().getWorkspace().getQueryManager();
             
             Query query = manager.createQuery(queryString, Query.XPATH);
-            if (limit > 0) {
-                query.setLimit(limit);
-            }
+            query.setLimit(1);
             QueryResult result = query.execute();
 
             NodeIterator iterator = result.getNodes();
-            while(iterator.hasNext()) {
-                list.add(new JCRMessage(iterator.nextNode(), getLogger()));
+            if(iterator.hasNext()) {
+                return new JCRMessage(iterator.nextNode(), getLogger()).getUid();
+            } else {
+                return null;
             }
-            return list;
         } catch (RepositoryException e) {
             throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
         }

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java?rev=984718&r1=984717&r2=984718&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java
(original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMessageMapper.java
Thu Aug 12 10:44:45 2010
@@ -262,17 +262,21 @@ public class JPAMessageMapper extends JP
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
+     * @see org.apache.james.imap.store.mail.MessageMapper#findFirstUnseenMessageUid(org.apache.james.imap.store.mail.model.Mailbox)
      */
     @SuppressWarnings("unchecked")
-    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox(Mailbox<Long>
mailbox, int limit)  throws StorageException {
+    public Long findFirstUnseenMessageUid(Mailbox<Long> mailbox)  throws StorageException
{
         try {
             Query query = getEntityManager().createNamedQuery("findUnseenMessagesInMailboxOrderByUid").setParameter("idParam",
mailbox.getMailboxId());
-            if (limit > 0) {
-                query = query.setMaxResults(limit);
+            query.setMaxResults(1);
+            List<MailboxMembership<Long>> result = query.getResultList();
+            if (result.isEmpty()) {
+                return null;
+            } else {
+                return result.get(0).getUid();
             }
-            return query.getResultList();
         } catch (PersistenceException e) {
+            e.printStackTrace();
             throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
         }
     }

Modified: james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java?rev=984718&r1=984717&r2=984718&view=diff
==============================================================================
--- james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java
(original)
+++ james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMessageMapper.java
Thu Aug 12 10:44:45 2010
@@ -145,20 +145,18 @@ public class InMemoryMessageMapper imple
 
     /*
      * (non-Javadoc)
-     * @see org.apache.james.imap.store.mail.MessageMapper#findUnseenMessagesInMailbox()
+     * @see org.apache.james.imap.store.mail.MessageMapper#findFirstUnseenMessageUid(org.apache.james.imap.store.mail.model.Mailbox)
      */
-    public List<MailboxMembership<Long>> findUnseenMessagesInMailbox(Mailbox<Long>
mailbox, int limit) throws StorageException {
-        final List<MailboxMembership<Long>> results = new ArrayList<MailboxMembership<Long>>();
-        for(MailboxMembership<Long> member:getMembershipByUidForMailbox(mailbox).values())
{
-            if (!member.isSeen()) {
-                results.add(member);
+    public Long findFirstUnseenMessageUid(Mailbox<Long> mailbox) throws StorageException
{
+        List<MailboxMembership<Long>> memberships = new ArrayList<MailboxMembership<Long>>(getMembershipByUidForMailbox(mailbox).values());
+        Collections.sort(memberships, MailboxMembershipComparator.INSTANCE);
+        for (int i = 0;  i < memberships.size(); i++) {
+            MailboxMembership<Long> m = memberships.get(i);
+            if (m.isSeen() == false) {
+                return m.getUid();
             }
         }
-        Collections.sort(results, MailboxMembershipComparator.INSTANCE);
-        if (limit > 0 && limit > results.size()) {
-            return results.subList(0, limit -1);
-        } 
-        return results;
+        return null;
     }
 
     /*

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java?rev=984718&r1=984717&r2=984718&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java
(original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMessageManager.java
Thu Aug 12 10:44:45 2010
@@ -391,22 +391,6 @@ public abstract class StoreMessageManage
         return ArrayUtils.toPrimitive(results.toArray(new Long[results.size()]));
     }
 
-    private Long getFirstUnseen(MailboxSession mailboxSession) throws MailboxException {
-        try {
-            final List<MailboxMembership<Id>> members = messageMapper.findUnseenMessagesInMailbox(mailbox,1);
-            final Iterator<MailboxMembership<Id>> it = members.iterator();
-            final Long result;
-            if (it.hasNext()) {
-                final MailboxMembership<Id> member = it.next();
-                result = member.getUid();
-            } else {
-                result = null;
-            }
-            return result;
-        } catch (MessagingException e) {
-            throw new MailboxException(HumanReadableText.FAILURE_MAIL_PARSE, e);
-        }
-    }
 
     private int getUnseenCount(MailboxSession mailboxSession) throws MailboxException {
         final int count = (int) messageMapper.countUnseenMessagesInMailbox(mailbox);
@@ -574,7 +558,7 @@ public abstract class StoreMessageManage
                 firstUnseen = null;
                 break;
             case FIRST_UNSEEN:
-                firstUnseen = getFirstUnseen(mailboxSession);
+                firstUnseen = getMessageMapper().findFirstUnseenMessageUid(mailbox);
                 unseenCount = 0;
                 break;
             default:

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java?rev=984718&r1=984717&r2=984718&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java
(original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MessageMapper.java
Thu Aug 12 10:44:45 2010
@@ -99,17 +99,14 @@ public interface MessageMapper<Id> exten
     public abstract void delete(Mailbox<Id> mailbox, MailboxMembership<Id> message)
throws StorageException;
 
     /**
-     * Return a List of {@link MailboxMembership} which are unseen. 
-     * The list must be ordered by the {@link Document} uid.
-     * If a limit was given the list will maximal be the size of the limit. Id a 
-     * limit smaller then 1 is given the List must contain all messages
+     * Return the uid of the first unseen message. If non can be found null will get returned
+     * 
      * 
      * @param mailbox
-     * @param limit
-     * @return list
+     * @return uid or null
      * @throws StorageException
      */
-    public abstract List<MailboxMembership<Id>> findUnseenMessagesInMailbox(Mailbox<Id>
mailbox, int limit) throws StorageException;
+    public abstract Long findFirstUnseenMessageUid(Mailbox<Id> mailbox) throws StorageException;
 
     /**
      * Return a List of {@link MailboxMembership} which are recent.



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


Mime
View raw message