james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [01/13] james-project git commit: JAMES-1874 No need of two reads for COUNT and UNSEEN
Date Mon, 20 Feb 2017 09:08:45 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 773210833 -> 2dd366d2a


JAMES-1874 No need of two reads for COUNT and UNSEEN


Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/052a3447
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/052a3447
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/052a3447

Branch: refs/heads/master
Commit: 052a3447f170f35df181661e9b26a35a2cea0859
Parents: 7732108
Author: Benoit Tellier <btellier@linagora.com>
Authored: Mon Feb 13 08:58:55 2017 +0700
Committer: Benoit Tellier <btellier@linagora.com>
Committed: Mon Feb 20 16:05:33 2017 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MessageManager.java    |  5 +-
 .../james/mailbox/model/MailboxCounters.java    | 84 ++++++++++++++++++++
 .../mailbox/model/MailboxCountersTest.java      | 33 ++++++++
 .../mailbox/caching/CachingMessageMapper.java   |  9 +++
 .../mail/CassandraMailboxCounterDAO.java        | 11 +++
 .../cassandra/mail/CassandraMessageMapper.java  | 12 +++
 .../mail/CassandraMailboxCounterDAOTest.java    | 48 +++++++++++
 .../mailbox/hbase/mail/HBaseMessageMapper.java  |  9 +++
 .../mailbox/jpa/mail/JPAMessageMapper.java      |  9 +++
 .../jpa/mail/TransactionalMessageMapper.java    |  9 +++
 .../mailbox/store/StoreMessageManager.java      |  7 +-
 .../store/mail/AbstractMessageMapper.java       |  9 +++
 .../james/mailbox/store/mail/MessageMapper.java |  2 +
 .../StoreMailboxMessageResultIteratorTest.java  |  9 +++
 .../base/MailboxEventAnalyserTest.java          | 13 +--
 .../apache/james/jmap/model/MailboxFactory.java |  7 +-
 16 files changed, 264 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
index 3f87ed4..972b33c 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.exception.UnsupportedCriteriaException;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageRange;
@@ -39,6 +40,8 @@ import org.apache.james.mailbox.model.MessageResult.FetchGroup;
 import org.apache.james.mailbox.model.MessageResultIterator;
 import org.apache.james.mailbox.model.SearchQuery;
 
+import com.google.common.base.Objects;
+
 /**
  * Interface which represent a Mailbox
  * 
@@ -60,7 +63,7 @@ public interface MessageManager {
     /**
      * Return the count of unseen messages in the mailbox
      */
-    long getUnseenMessageCount(MailboxSession mailboxSession) throws MailboxException;
+    MailboxCounters getMailboxCounters(MailboxSession mailboxSession) throws MailboxException;
 
     /**
      * Return if the Mailbox is writable

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxCounters.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxCounters.java
b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxCounters.java
new file mode 100644
index 0000000..d86e14a
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MailboxCounters.java
@@ -0,0 +1,84 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+
+public class MailboxCounters {
+
+    public static class Builder {
+        private Optional<Long> count = Optional.absent();
+        private Optional<Long> unseen = Optional.absent();
+
+        public Builder count(long count) {
+            this.count = Optional.of(count);
+            return this;
+        }
+
+        public Builder unseen(long unseen) {
+            this.unseen = Optional.of(unseen);
+            return this;
+        }
+
+        public MailboxCounters build() {
+            Preconditions.checkState(count.isPresent(), "count is compulsory");
+            Preconditions.checkState(unseen.isPresent(), "unseen is compulsory");
+            return new MailboxCounters(count.get(), unseen.get());
+        }
+    }
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    private final long count;
+    private final long unseen;
+
+    private MailboxCounters(long count, long unseen) {
+        this.count = count;
+        this.unseen = unseen;
+    }
+
+    public long getCount() {
+        return count;
+    }
+
+    public long getUnseen() {
+        return unseen;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof MailboxCounters) {
+            MailboxCounters that = (MailboxCounters) o;
+
+            return Objects.equal(this.count, that.count)
+                && Objects.equal(this.unseen, that.unseen);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hashCode(count, unseen);
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java
b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java
new file mode 100644
index 0000000..e43f2ce
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MailboxCountersTest.java
@@ -0,0 +1,33 @@
+/*
+ *   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.mailbox.model;
+
+import org.junit.Test;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class MailboxCountersTest {
+
+    @Test
+    public void mailboxCountersShouldRespectBeanContract() {
+        EqualsVerifier.forClass(MailboxCounters.class).verify();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
b/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
index a482a66..bc4443b 100644
--- a/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
+++ b/mailbox/caching/src/main/java/org/apache/james/mailbox/caching/CachingMessageMapper.java
@@ -5,6 +5,7 @@ import java.util.Map;
 
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.UpdatedFlags;
@@ -68,6 +69,14 @@ public class CachingMessageMapper implements MessageMapper {
     }
 
     @Override
+    public MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException {
+        return MailboxCounters.builder()
+            .count(countMessagesInMailbox(mailbox))
+            .unseen(countUnseenMessagesInMailbox(mailbox))
+            .build();
+    }
+
+    @Override
     public void delete(Mailbox mailbox, MailboxMessage message)
             throws MailboxException {
         invalidateMetadata(mailbox);

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
index 7f3c35a..2c00017 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAO.java
@@ -35,6 +35,7 @@ import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor;
 import org.apache.james.mailbox.cassandra.CassandraId;
 import org.apache.james.mailbox.cassandra.table.CassandraMailboxCountersTable;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 
 import com.datastax.driver.core.BoundStatement;
@@ -75,6 +76,16 @@ public class CassandraMailboxCounterDAO {
                 .where(eq(CassandraMailboxCountersTable.MAILBOX_ID, bindMarker(CassandraMailboxCountersTable.MAILBOX_ID))));
     }
 
+    public CompletableFuture<Optional<MailboxCounters>> retrieveMailboxCounters(Mailbox
mailbox) throws MailboxException {
+        CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
+
+        return cassandraAsyncExecutor.executeSingleRow(bindWithMailbox(mailboxId, readStatement))
+            .thenApply(optional -> optional.map(row ->  MailboxCounters.builder()
+                .count(row.getLong(CassandraMailboxCountersTable.COUNT))
+                .unseen(row.getLong(CassandraMailboxCountersTable.UNSEEN))
+                .build()));
+    }
+
     public CompletableFuture<Optional<Long>> countMessagesInMailbox(Mailbox mailbox)
throws MailboxException {
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index ff0d084..c36d9a0 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -42,6 +42,7 @@ import org.apache.james.mailbox.cassandra.mail.utils.MessageDeletedDuringFlagsUp
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
@@ -65,6 +66,10 @@ import com.google.common.collect.ImmutableList;
 
 public class CassandraMessageMapper implements MessageMapper {
     private static final Logger LOGGER = LoggerFactory.getLogger(CassandraMessageMapper.class);
+    public static final MailboxCounters INITIAL_COUNTERS =  MailboxCounters.builder()
+        .count(0L)
+        .unseen(0L)
+        .build();
 
     private final ModSeqProvider modSeqProvider;
     private final MailboxSession mailboxSession;
@@ -110,6 +115,13 @@ public class CassandraMessageMapper implements MessageMapper {
     }
 
     @Override
+    public MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException {
+        return mailboxCounterDAO.retrieveMailboxCounters(mailbox)
+            .join()
+            .orElse(INITIAL_COUNTERS);
+    }
+
+    @Override
     public void delete(Mailbox mailbox, MailboxMessage message) {
         CassandraId mailboxId = (CassandraId) mailbox.getMailboxId();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
index 013f20c..58e0c10 100644
--- a/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
+++ b/mailbox/cassandra/src/test/java/org/apache/james/mailbox/cassandra/mail/CassandraMailboxCounterDAOTest.java
@@ -21,9 +21,12 @@ package org.apache.james.mailbox.cassandra.mail;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.util.Optional;
+
 import org.apache.james.backends.cassandra.CassandraCluster;
 import org.apache.james.mailbox.cassandra.CassandraId;
 import org.apache.james.mailbox.cassandra.modules.CassandraMailboxCounterModule;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.junit.After;
@@ -64,6 +67,11 @@ public class CassandraMailboxCounterDAOTest {
     }
 
     @Test
+    public void retrieveMailboxCounterShouldReturnEmptyByDefault() throws Exception {
+        assertThat(testee.retrieveMailboxCounters(mailbox).join().isPresent()).isFalse();
+    }
+
+    @Test
     public void incrementCountShouldAddOneWhenAbsent() throws Exception {
         testee.incrementCount(MAILBOX_ID).join();
 
@@ -79,6 +87,46 @@ public class CassandraMailboxCounterDAOTest {
     }
 
     @Test
+    public void incrementUnseenShouldAddOneWhenAbsentOnMailboxCounters() throws Exception
{
+        testee.incrementUnseen(MAILBOX_ID).join();
+
+        Optional<MailboxCounters> mailboxCounters = testee.retrieveMailboxCounters(mailbox).join();
+        assertThat(mailboxCounters.isPresent()).isTrue();
+        assertThat(mailboxCounters.get())
+            .isEqualTo(MailboxCounters.builder()
+                .count(0L)
+                .unseen(1L)
+                .build());
+    }
+
+    @Test
+    public void incrementCountShouldAddOneWhenAbsentOnMailboxCounters() throws Exception
{
+        testee.incrementCount(MAILBOX_ID).join();
+
+        Optional<MailboxCounters> mailboxCounters = testee.retrieveMailboxCounters(mailbox).join();
+        assertThat(mailboxCounters.isPresent()).isTrue();
+        assertThat(mailboxCounters.get())
+            .isEqualTo(MailboxCounters.builder()
+                .count(1L)
+                .unseen(0L)
+                .build());
+    }
+
+    @Test
+    public void retrieveMailboxCounterShouldWorkWhenFullRow() throws Exception {
+        testee.incrementCount(MAILBOX_ID).join();
+        testee.incrementUnseen(MAILBOX_ID).join();
+
+        Optional<MailboxCounters> mailboxCounters = testee.retrieveMailboxCounters(mailbox).join();
+        assertThat(mailboxCounters.isPresent()).isTrue();
+        assertThat(mailboxCounters.get())
+            .isEqualTo(MailboxCounters.builder()
+                .count(1L)
+                .unseen(1L)
+                .build());
+    }
+
+    @Test
     public void decrementCountShouldRemoveOne() throws Exception {
         testee.incrementCount(MAILBOX_ID).join();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
index 411b15d..5d52cee 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMessageMapper.java
@@ -68,6 +68,7 @@ import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.hbase.HBaseId;
 import org.apache.james.mailbox.hbase.io.ChunkOutputStream;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MessageId.Factory;
 import org.apache.james.mailbox.model.MessageMetaData;
@@ -112,6 +113,14 @@ public class HBaseMessageMapper extends NonTransactionalMapper implements
Messag
     }
 
     @Override
+    public MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException {
+        return MailboxCounters.builder()
+            .count(countMessagesInMailbox(mailbox))
+            .unseen(countUnseenMessagesInMailbox(mailbox))
+            .build();
+    }
+
+    @Override
     public void endRequest() {
     }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
index ac581a0..532a8be 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java
@@ -38,6 +38,7 @@ import org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage
 import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAEncryptedMailboxMessage;
 import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage;
 import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAStreamingMailboxMessage;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageRange.Type;
@@ -68,6 +69,14 @@ public class JPAMessageMapper extends JPATransactionalMapper implements
MessageM
         this.messageMetadataMapper = new MessageUtils(mailboxSession, uidProvider, modSeqProvider);
     }
 
+    @Override
+    public MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException {
+        return MailboxCounters.builder()
+            .count(countMessagesInMailbox(mailbox))
+            .unseen(countUnseenMessagesInMailbox(mailbox))
+            .build();
+    }
+
     /**
      * @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox,
      *      org.apache.james.mailbox.model.MessageRange,

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
index 1e0715a..ce61d43 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.UpdatedFlags;
@@ -49,6 +50,14 @@ public class TransactionalMessageMapper implements MessageMapper {
     }
 
     @Override
+    public MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException {
+        return MailboxCounters.builder()
+            .count(countMessagesInMailbox(mailbox))
+            .unseen(countUnseenMessagesInMailbox(mailbox))
+            .build();
+    }
+
+    @Override
     public <T> T execute(Transaction<T> transaction) throws MailboxException
{
         throw new NotImplementedException();
     }

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 60c7d19..d48ce5d 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -54,6 +54,7 @@ import org.apache.james.mailbox.model.Attachment;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxACL;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageAttachment;
@@ -232,10 +233,10 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
         return new Flags(MINIMAL_PERMANET_FLAGS);
     }
 
+
     @Override
-    public long getUnseenMessageCount(MailboxSession mailboxSession) throws MailboxException
{
-        return mapperFactory.createMessageMapper(mailboxSession)
-            .countUnseenMessagesInMailbox(mailbox);
+    public MailboxCounters getMailboxCounters(MailboxSession mailboxSession) throws MailboxException
{
+        return mapperFactory.createMessageMapper(mailboxSession).getMailboxCounters(mailbox);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
index de82a8d..17aa4a8 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java
@@ -27,6 +27,7 @@ import javax.mail.Flags;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.UpdatedFlags;
@@ -62,6 +63,14 @@ public abstract class AbstractMessageMapper extends TransactionalMapper
implemen
     public Optional<MessageUid> getLastUid(Mailbox mailbox) throws MailboxException
{
         return uidProvider.lastUid(mailboxSession, mailbox);
     }
+
+    @Override
+    public MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException {
+        return MailboxCounters.builder()
+            .count(countMessagesInMailbox(mailbox))
+            .unseen(countUnseenMessagesInMailbox(mailbox))
+            .build();
+    }
     
     @Override
     public Iterator<UpdatedFlags> updateFlags(Mailbox mailbox, FlagsUpdateCalculator
flagsUpdateCalculator, MessageRange set) throws MailboxException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
index f4486c5..0d1b9f3 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java
@@ -24,6 +24,7 @@ import java.util.Map;
 
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.UpdatedFlags;
@@ -83,6 +84,7 @@ public interface MessageMapper extends Mapper {
     long countUnseenMessagesInMailbox(Mailbox mailbox)
             throws MailboxException;
 
+    MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException;
 
     /**
      * Delete the given {@link MailboxMessage}

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
index 96ba573..3fdbbe4 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/StoreMailboxMessageResultIteratorTest.java
@@ -34,6 +34,7 @@ import javax.mail.util.SharedByteArrayInputStream;
 
 import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MessageMetaData;
 import org.apache.james.mailbox.model.MessageRange;
 import org.apache.james.mailbox.model.MessageResult;
@@ -86,6 +87,14 @@ public class StoreMailboxMessageResultIteratorTest {
         }
 
         @Override
+        public MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException
{
+            return MailboxCounters.builder()
+                .count(countMessagesInMailbox(mailbox))
+                .unseen(countUnseenMessagesInMailbox(mailbox))
+                .build();
+        }
+
+        @Override
         public Iterator<MailboxMessage> findInMailbox(Mailbox mailbox, MessageRange
set,
                                                               org.apache.james.mailbox.store.mail.MessageMapper.FetchType
type, int limit)
                 throws MailboxException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index e6dbed2..74a5b27 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -58,6 +58,7 @@ import org.apache.james.mailbox.model.MailboxACL.MailboxACLRight;
 import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
 import org.apache.james.mailbox.model.MailboxAnnotation;
 import org.apache.james.mailbox.model.MailboxAnnotationKey;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -174,15 +175,15 @@ public class MailboxEventAnalyserTest {
         public MessageManager getMailbox(MailboxPath mailboxPath, MailboxSession session)
throws MailboxException {
             return new MessageManager() {
 
-                @Override
-                public long getUnseenMessageCount(MailboxSession mailboxSession) throws MailboxException
{
-                    return 0;
-                }
-
                 public long getMessageCount(MailboxSession mailboxSession) throws MailboxException
{
                     return 1;
                 }
-                
+
+                @Override
+                public MailboxCounters getMailboxCounters(MailboxSession mailboxSession)
throws MailboxException {
+                    throw new UnsupportedOperationException("Not implemented");
+                }
+
                 public boolean isWriteable(MailboxSession session) {
                     return false;
                 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/052a3447/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
index 352eafc..701d2fc 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MailboxFactory.java
@@ -30,7 +30,9 @@ import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.MailboxCounters;
 import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -70,13 +72,14 @@ public class MailboxFactory {
     private Optional<Mailbox> fromMessageManager(MessageManager messageManager, MailboxSession
mailboxSession) throws MailboxException {
         MailboxPath mailboxPath = messageManager.getMailboxPath();
         Optional<Role> role = Role.from(mailboxPath.getName());
+        MailboxCounters mailboxCounters = messageManager.getMailboxCounters(mailboxSession);
         return Optional.ofNullable(Mailbox.builder()
                 .id(messageManager.getId())
                 .name(getName(mailboxPath, mailboxSession))
                 .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession).orElse(null))
                 .role(role)
-                .unreadMessages(messageManager.getUnseenMessageCount(mailboxSession))
-                .totalMessages(messageManager.getMessageCount(mailboxSession))
+                .unreadMessages(mailboxCounters.getUnseen())
+                .totalMessages(mailboxCounters.getCount())
                 .sortOrder(SortOrder.getSortOrder(role))
                 .build());
     }


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