james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [1/6] james-project git commit: MAILBOX-279: Enable MESSAGE for JPAMappersTest
Date Mon, 09 Jan 2017 09:13:29 GMT
Repository: james-project
Updated Branches:
  refs/heads/master 84c66946d -> 97de26382


MAILBOX-279: Enable MESSAGE for JPAMappersTest


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

Branch: refs/heads/master
Commit: fc42d06656ca68a060334bc31c89c1ce986b7258
Parents: a377d43
Author: Quynh Nguyen <qnguyen@linagora.com>
Authored: Wed Dec 7 14:15:47 2016 +0700
Committer: Quynh Nguyen <qnguyen@linagora.com>
Committed: Mon Jan 9 15:11:51 2017 +0700

----------------------------------------------------------------------
 .../mailbox/jpa/mail/JPAMapperProvider.java     |  14 +-
 .../jpa/mail/TransactionalMessageMapper.java    | 157 +++++++++++++++++++
 2 files changed, 169 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/fc42d066/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java
index 54fb56b..37887a9 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/JPAMapperProvider.java
@@ -37,8 +37,10 @@ import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag;
 import org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage;
 import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage;
 import org.apache.james.mailbox.jpa.user.model.JPASubscription;
+import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.store.JVMMailboxPathLocker;
 import org.apache.james.mailbox.store.mail.AnnotationMapper;
 import org.apache.james.mailbox.store.mail.AttachmentMapper;
 import org.apache.james.mailbox.store.mail.MailboxMapper;
@@ -60,7 +62,15 @@ public class JPAMapperProvider implements MapperProvider {
 
     @Override
     public MessageMapper createMessageMapper() throws MailboxException {
-        throw new NotImplementedException();
+        EntityManagerFactory entityManagerFactory = createEntityManagerFactory();
+        JVMMailboxPathLocker locker = new JVMMailboxPathLocker();
+
+        JPAMessageMapper messageMapper = new JPAMessageMapper(new MockMailboxSession("benwa"),

+            new JPAUidProvider(locker, entityManagerFactory), 
+            new JPAModSeqProvider(locker, entityManagerFactory), 
+            entityManagerFactory);
+
+        return new TransactionalMessageMapper((JPAMessageMapper)messageMapper);
     }
 
     @Override
@@ -127,7 +137,7 @@ public class JPAMapperProvider implements MapperProvider {
 
     @Override
     public List<Capabilities> getNotImplemented() {
-        return ImmutableList.of(Capabilities.MESSAGE, Capabilities.ATTACHMENT, Capabilities.MOVE,
Capabilities.UNIQUE_MESSAGE_ID);
+        return ImmutableList.of(Capabilities.ATTACHMENT, Capabilities.MOVE, Capabilities.UNIQUE_MESSAGE_ID);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/fc42d066/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
new file mode 100644
index 0000000..4f105d9
--- /dev/null
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalMessageMapper.java
@@ -0,0 +1,157 @@
+/****************************************************************
+ * 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.jpa.mail;
+
+import java.util.Iterator;
+import java.util.List;
+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.MessageMetaData;
+import org.apache.james.mailbox.model.MessageRange;
+import org.apache.james.mailbox.model.UpdatedFlags;
+import org.apache.james.mailbox.store.FlagsUpdateCalculator;
+import org.apache.james.mailbox.store.mail.MessageMapper;
+import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Throwables;
+
+public class TransactionalMessageMapper implements MessageMapper {
+    private final JPAMessageMapper wrapped;
+
+    public TransactionalMessageMapper(JPAMessageMapper wrapped) {
+        this.wrapped = wrapped;
+    }
+    @Override
+    public void endRequest() {
+        throw new NotImplementedException();
+    }
+
+    @Override
+    public <T> T execute(Transaction<T> transaction) throws MailboxException
{
+        throw new NotImplementedException();
+    }
+
+    @Override
+    public Iterator<MailboxMessage> findInMailbox(Mailbox mailbox, MessageRange set,
FetchType type, int limit)
+            throws MailboxException {
+        return wrapped.findInMailbox(mailbox, set, type, limit);
+    }
+
+    @Override
+    public Map<MessageUid, MessageMetaData> expungeMarkedForDeletionInMailbox(final
Mailbox mailbox, final MessageRange set)
+            throws MailboxException {
+        Map<MessageUid, MessageMetaData> data = wrapped.execute(new Transaction<Map<MessageUid,
MessageMetaData>>() {
+            @Override
+            public Map<MessageUid, MessageMetaData> run() throws MailboxException {
+                return wrapped.expungeMarkedForDeletionInMailbox(mailbox, set);
+            }
+        });
+        return data;
+    }
+
+    @Override
+    public long countMessagesInMailbox(Mailbox mailbox) throws MailboxException {
+        return wrapped.countMessagesInMailbox(mailbox);
+    }
+
+    @Override
+    public long countUnseenMessagesInMailbox(Mailbox mailbox) throws MailboxException {
+        return wrapped.countUnseenMessagesInMailbox(mailbox);
+    }
+
+    @Override
+    public void delete(final Mailbox mailbox, final MailboxMessage message) throws MailboxException
{
+        try {
+            wrapped.execute(new VoidTransaction() {
+                @Override
+                public void runVoid() throws MailboxException {
+                    wrapped.delete(mailbox, message);
+                }
+            });
+        } catch (MailboxException e) {
+            Throwables.propagate(e);
+        }
+    }
+
+    @Override
+    public MessageUid findFirstUnseenMessageUid(Mailbox mailbox) throws MailboxException
{
+        return wrapped.findFirstUnseenMessageUid(mailbox);
+    }
+
+    @Override
+    public List<MessageUid> findRecentMessageUidsInMailbox(Mailbox mailbox) throws
MailboxException {
+        return wrapped.findRecentMessageUidsInMailbox(mailbox);
+    }
+
+    @Override
+    public MessageMetaData add(final Mailbox mailbox, final MailboxMessage message) throws
MailboxException {
+        MessageMetaData data = wrapped.execute(new Transaction<MessageMetaData>() {
+            @Override
+            public MessageMetaData run() throws MailboxException {
+                return wrapped.add(mailbox, message);
+            }
+        });
+        return data;
+    }
+
+    @Override
+    public Iterator<UpdatedFlags> updateFlags(final Mailbox mailbox, final FlagsUpdateCalculator
flagsUpdateCalculator,
+            final MessageRange set) throws MailboxException {
+        Iterator<UpdatedFlags> data = wrapped.execute(new Transaction<Iterator<UpdatedFlags>>()
{
+            @Override
+            public Iterator<UpdatedFlags> run() throws MailboxException {
+                return wrapped.updateFlags(mailbox, flagsUpdateCalculator, set);
+            }
+        });
+        return data;
+    }
+
+    @Override
+    public MessageMetaData copy(final Mailbox mailbox, final MailboxMessage original) throws
MailboxException {
+        MessageMetaData data = wrapped.execute(new Transaction<MessageMetaData>() {
+            @Override
+            public MessageMetaData run() throws MailboxException {
+                return wrapped.copy(mailbox, original);
+            }
+        });
+        return data;
+    }
+
+    @Override
+    public MessageMetaData move(Mailbox mailbox, MailboxMessage original) throws MailboxException
{
+        return wrapped.move(mailbox, original);
+    }
+
+    @Override
+    public Optional<MessageUid> getLastUid(Mailbox mailbox) throws MailboxException
{
+        return wrapped.getLastUid(mailbox);
+    }
+
+    @Override
+    public long getHighestModSeq(Mailbox mailbox) throws MailboxException {
+        return wrapped.getHighestModSeq(mailbox);
+    }
+
+}


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