You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2023/12/04 10:11:16 UTC
(james-project) branch postgresql updated: JAMES-2586 Guide binding Postgres Message/Mailbox mapper
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch postgresql
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/postgresql by this push:
new c79a72a398 JAMES-2586 Guide binding Postgres Message/Mailbox mapper
c79a72a398 is described below
commit c79a72a3989ef4e5a184d04ea2c498d367906a11
Author: Tung Tran <vt...@linagora.com>
AuthorDate: Thu Nov 30 15:55:10 2023 +0700
JAMES-2586 Guide binding Postgres Message/Mailbox mapper
---
mailbox/postgres/pom.xml | 5 +
.../org/apache/james/mailbox/postgres/JPAId.java | 84 ---
.../mailbox/postgres/JPATransactionalMapper.java | 96 ----
.../mailbox/postgres/PostgresMailboxIdFaker.java | 43 --
.../PostgresMailboxSessionMapperFactory.java | 86 ++-
.../PostgresMailboxSessionMapperFactoryTODO.java | 118 -----
.../mailbox/postgres/mail/JPAAnnotationMapper.java | 168 ------
.../mailbox/postgres/mail/JPAAttachmentMapper.java | 118 -----
.../mailbox/postgres/mail/JPAMailboxMapper.java | 240 ---------
.../mailbox/postgres/mail/JPAMessageMapper.java | 510 ------------------
.../mailbox/postgres/mail/JPAModSeqProvider.java | 105 ----
.../mailbox/postgres/mail/JPAUidProvider.java | 99 ----
.../PostgresMailboxManager.java} | 41 +-
.../PostgresMessageManager.java} | 28 +-
.../postgres/mail/dao/PostgresMailboxDAO.java | 16 +-
.../mailbox/postgres/mail/model/JPAAttachment.java | 193 -------
.../mailbox/postgres/mail/model/JPAMailbox.java | 205 --------
.../postgres/mail/model/JPAMailboxAnnotation.java | 99 ----
.../mail/model/JPAMailboxAnnotationId.java | 62 ---
.../mailbox/postgres/mail/model/JPAProperty.java | 129 -----
.../mailbox/postgres/mail/model/JPAUserFlag.java | 120 -----
.../model/openjpa/AbstractJPAMailboxMessage.java | 579 ---------------------
.../mail/model/openjpa/JPAMailboxMessage.java | 126 -----
.../postgres/openjpa/OpenJPAMessageFactory.java | 56 --
.../postgres/quota/JpaCurrentQuotaManager.java | 131 -----
.../quota/PostgresCurrentQuotaManager.java | 4 +
.../postgres/quota/model/JpaCurrentQuota.java | 69 ---
.../james/mailbox/postgres/JPAMailboxFixture.java | 33 +-
...er.java => PostgresMailboxManagerProvider.java} | 46 +-
....java => PostgresMailboxManagerStressTest.java} | 21 +-
...erTest.java => PostgresMailboxManagerTest.java} | 44 +-
.../postgres/PostgresSubscriptionManagerTest.java | 30 +-
.../postgres/mail/JPAAttachmentMapperTest.java | 102 ----
.../mailbox/postgres/mail/JPAMapperProvider.java | 122 -----
.../postgres/mail/JpaAnnotationMapperTest.java | 52 --
.../postgres/mail/JpaMailboxMapperTest.java | 90 ----
.../mail/TransactionalAnnotationMapper.java | 87 ----
.../mail/TransactionalAttachmentMapper.java | 79 ---
.../postgres/mail/TransactionalMailboxMapper.java | 99 ----
.../postgres/mail/TransactionalMessageMapper.java | 147 ------
.../mail/model/openjpa/JPAMailboxMessageTest.java | 57 --
...PostgresRecomputeCurrentQuotasServiceTest.java} | 72 +--
.../postgres/src/test/resources/persistence.xml | 10 -
.../postgres/host/PostgresHostSystem.java | 12 +-
.../org/apache/james/PostgresJamesServerMain.java | 2 -
.../src/main/resources/META-INF/persistence.xml | 10 -
server/container/guice/mailbox-postgres/pom.xml | 4 +
.../james/modules/mailbox/JPAMailboxModule.java | 152 ------
.../modules/mailbox/PostgresMailboxModule.java | 115 ++++
...paQuotaModule.java => PostgresQuotaModule.java} | 8 +-
50 files changed, 289 insertions(+), 4635 deletions(-)
diff --git a/mailbox/postgres/pom.xml b/mailbox/postgres/pom.xml
index 04887957b3..edc6bfac4b 100644
--- a/mailbox/postgres/pom.xml
+++ b/mailbox/postgres/pom.xml
@@ -123,6 +123,11 @@
<artifactId>james-server-data-jpa</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>james-server-data-postgres</artifactId>
+ <scope>test</scope>
+ </dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-guice-common</artifactId>
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/JPAId.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/JPAId.java
deleted file mode 100644
index 16e20f0cff..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/JPAId.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/****************************************************************
- * 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.postgres;
-
-import java.io.Serializable;
-
-import org.apache.james.mailbox.model.MailboxId;
-
-public class JPAId implements MailboxId, Serializable {
-
- public static class Factory implements MailboxId.Factory {
- @Override
- public JPAId fromString(String serialized) {
- return of(Long.parseLong(serialized));
- }
- }
-
- public static JPAId of(long value) {
- return new JPAId(value);
- }
-
- private final long value;
-
- public JPAId(long value) {
- this.value = value;
- }
-
- @Override
- public String serialize() {
- return String.valueOf(value);
- }
-
- @Override
- public String toString() {
- return String.valueOf(value);
- }
-
- public long getRawId() {
- return value;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + (int) (value ^ (value >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- JPAId other = (JPAId) obj;
- if (value != other.value) {
- return false;
- }
- return true;
- }
-
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/JPATransactionalMapper.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/JPATransactionalMapper.java
deleted file mode 100644
index d39b31b742..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/JPATransactionalMapper.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/****************************************************************
- * 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.postgres;
-
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.EntityTransaction;
-import javax.persistence.PersistenceException;
-
-import org.apache.james.backends.jpa.EntityManagerUtils;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.transaction.TransactionalMapper;
-
-/**
- * JPA implementation of TransactionMapper. This class is not thread-safe!
- *
- */
-public abstract class JPATransactionalMapper extends TransactionalMapper {
-
- protected EntityManagerFactory entityManagerFactory;
- protected EntityManager entityManager;
-
- public JPATransactionalMapper(EntityManagerFactory entityManagerFactory) {
- this.entityManagerFactory = entityManagerFactory;
- }
-
- /**
- * Return the currently used {@link EntityManager} or a new one if none exists.
- *
- * @return entitymanger
- */
- public EntityManager getEntityManager() {
- if (entityManager != null) {
- return entityManager;
- }
- entityManager = entityManagerFactory.createEntityManager();
- return entityManager;
- }
-
- @Override
- protected void begin() throws MailboxException {
- try {
- getEntityManager().getTransaction().begin();
- } catch (PersistenceException e) {
- throw new MailboxException("Begin of transaction failed", e);
- }
- }
-
- /**
- * Commit the Transaction and close the EntityManager
- */
- @Override
- protected void commit() throws MailboxException {
- try {
- getEntityManager().getTransaction().commit();
- } catch (PersistenceException e) {
- throw new MailboxException("Commit of transaction failed",e);
- }
- }
-
- @Override
- protected void rollback() throws MailboxException {
- EntityTransaction transaction = entityManager.getTransaction();
- // check if we have a transaction to rollback
- if (transaction.isActive()) {
- getEntityManager().getTransaction().rollback();
- }
- }
-
- /**
- * Close open {@link EntityManager}
- */
- @Override
- public void endRequest() {
- EntityManagerUtils.safelyClose(entityManager);
- entityManager = null;
- }
-
-
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxIdFaker.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxIdFaker.java
deleted file mode 100644
index 23751b5001..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxIdFaker.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/****************************************************************
- * 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.postgres;
-
-import java.util.UUID;
-
-import org.apache.james.mailbox.model.MailboxId;
-
-// TODO remove: this is trick convert JPAId to PostgresMailboxId when implementing PostgresUidProvider.
-// it should be removed when all JPA dependencies are removed
-@Deprecated
-public class PostgresMailboxIdFaker {
- public static PostgresMailboxId getMailboxId(MailboxId mailboxId) {
- if (mailboxId instanceof JPAId) {
- long longValue = ((JPAId) mailboxId).getRawId();
- return PostgresMailboxId.of(longToUUID(longValue));
- }
- return (PostgresMailboxId) mailboxId;
- }
-
- public static UUID longToUUID(Long longValue) {
- long mostSigBits = longValue << 32;
- long leastSigBits = 0;
- return new UUID(mostSigBits, leastSigBits);
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java
index 34f5aa17b6..0fbd9e657b 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactory.java
@@ -18,21 +18,22 @@
****************************************************************/
package org.apache.james.mailbox.postgres;
+import java.time.Clock;
+
import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
import org.apache.commons.lang3.NotImplementedException;
-import org.apache.james.backends.jpa.EntityManagerUtils;
-import org.apache.james.backends.jpa.JPAConfiguration;
import org.apache.james.backends.postgres.utils.PostgresExecutor;
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BlobStore;
import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.postgres.mail.JPAAnnotationMapper;
-import org.apache.james.mailbox.postgres.mail.JPAAttachmentMapper;
-import org.apache.james.mailbox.postgres.mail.JPAMailboxMapper;
-import org.apache.james.mailbox.postgres.mail.JPAMessageMapper;
-import org.apache.james.mailbox.postgres.mail.JPAModSeqProvider;
-import org.apache.james.mailbox.postgres.mail.JPAUidProvider;
+import org.apache.james.mailbox.postgres.mail.PostgresAnnotationMapper;
+import org.apache.james.mailbox.postgres.mail.PostgresMailboxMapper;
+import org.apache.james.mailbox.postgres.mail.PostgresMessageMapper;
+import org.apache.james.mailbox.postgres.mail.PostgresModSeqProvider;
+import org.apache.james.mailbox.postgres.mail.PostgresUidProvider;
+import org.apache.james.mailbox.postgres.mail.dao.PostgresMailboxAnnotationDAO;
+import org.apache.james.mailbox.postgres.mail.dao.PostgresMailboxDAO;
import org.apache.james.mailbox.postgres.user.PostgresSubscriptionDAO;
import org.apache.james.mailbox.postgres.user.PostgresSubscriptionMapper;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
@@ -42,45 +43,41 @@ import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
import org.apache.james.mailbox.store.mail.MailboxMapper;
import org.apache.james.mailbox.store.mail.MessageIdMapper;
import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.ModSeqProvider;
-import org.apache.james.mailbox.store.mail.UidProvider;
import org.apache.james.mailbox.store.user.SubscriptionMapper;
-/**
- * JPA implementation of {@link MailboxSessionMapperFactory}
- *
- */
-public class PostgresMailboxSessionMapperFactory extends MailboxSessionMapperFactory implements AttachmentMapperFactory {
- private final EntityManagerFactory entityManagerFactory;
- private final JPAUidProvider uidProvider;
- private final JPAModSeqProvider modSeqProvider;
- private final AttachmentMapper attachmentMapper;
- private final JPAConfiguration jpaConfiguration;
+public class PostgresMailboxSessionMapperFactory extends MailboxSessionMapperFactory implements AttachmentMapperFactory {
private final PostgresExecutor.Factory executorFactory;
+ private final BlobStore blobStore;
+ private final BlobId.Factory blobIdFactory;
+ private final Clock clock;
@Inject
- public PostgresMailboxSessionMapperFactory(EntityManagerFactory entityManagerFactory, JPAUidProvider uidProvider,
- JPAModSeqProvider modSeqProvider, JPAConfiguration jpaConfiguration,
- PostgresExecutor.Factory executorFactory) {
- this.entityManagerFactory = entityManagerFactory;
- this.uidProvider = uidProvider;
- this.modSeqProvider = modSeqProvider;
- EntityManagerUtils.safelyClose(createEntityManager());
- this.attachmentMapper = new JPAAttachmentMapper(entityManagerFactory);
- this.jpaConfiguration = jpaConfiguration;
+ public PostgresMailboxSessionMapperFactory(PostgresExecutor.Factory executorFactory,
+ Clock clock,
+ BlobStore blobStore,
+ BlobId.Factory blobIdFactory) {
this.executorFactory = executorFactory;
+ this.blobStore = blobStore;
+ this.blobIdFactory = blobIdFactory;
+ this.clock = clock;
}
@Override
public MailboxMapper createMailboxMapper(MailboxSession session) {
- return new JPAMailboxMapper(entityManagerFactory);
+ PostgresMailboxDAO mailboxDAO = new PostgresMailboxDAO(executorFactory.create(session.getUser().getDomainPart()));
+ return new PostgresMailboxMapper(mailboxDAO);
}
@Override
public MessageMapper createMessageMapper(MailboxSession session) {
- return new JPAMessageMapper(uidProvider, modSeqProvider, entityManagerFactory, jpaConfiguration);
+ return new PostgresMessageMapper(executorFactory.create(session.getUser().getDomainPart()),
+ getModSeqProvider(session),
+ getUidProvider(session),
+ blobStore,
+ clock,
+ blobIdFactory);
}
@Override
@@ -93,38 +90,29 @@ public class PostgresMailboxSessionMapperFactory extends MailboxSessionMapperFac
return new PostgresSubscriptionMapper(new PostgresSubscriptionDAO(executorFactory.create(session.getUser().getDomainPart())));
}
- /**
- * Return a new {@link EntityManager} instance
- *
- * @return manager
- */
- private EntityManager createEntityManager() {
- return entityManagerFactory.createEntityManager();
- }
-
@Override
public AnnotationMapper createAnnotationMapper(MailboxSession session) {
- return new JPAAnnotationMapper(entityManagerFactory);
+ return new PostgresAnnotationMapper(new PostgresMailboxAnnotationDAO(executorFactory.create(session.getUser().getDomainPart())));
}
@Override
- public UidProvider getUidProvider(MailboxSession session) {
- return uidProvider;
+ public PostgresUidProvider getUidProvider(MailboxSession session) {
+ return new PostgresUidProvider.Factory(executorFactory).create(session);
}
@Override
- public ModSeqProvider getModSeqProvider(MailboxSession session) {
- return modSeqProvider;
+ public PostgresModSeqProvider getModSeqProvider(MailboxSession session) {
+ return new PostgresModSeqProvider.Factory(executorFactory).create(session);
}
@Override
public AttachmentMapper createAttachmentMapper(MailboxSession session) {
- return new JPAAttachmentMapper(entityManagerFactory);
+ throw new NotImplementedException("not implemented");
}
@Override
public AttachmentMapper getAttachmentMapper(MailboxSession session) {
- return attachmentMapper;
+ throw new NotImplementedException("not implemented");
}
}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactoryTODO.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactoryTODO.java
deleted file mode 100644
index e5ba0f38d1..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/PostgresMailboxSessionMapperFactoryTODO.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/****************************************************************
- * 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.postgres;
-
-import java.time.Clock;
-
-import javax.inject.Inject;
-
-import org.apache.commons.lang3.NotImplementedException;
-import org.apache.james.backends.postgres.utils.PostgresExecutor;
-import org.apache.james.blob.api.BlobId;
-import org.apache.james.blob.api.BlobStore;
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.postgres.mail.PostgresAnnotationMapper;
-import org.apache.james.mailbox.postgres.mail.PostgresMailboxMapper;
-import org.apache.james.mailbox.postgres.mail.PostgresMessageMapper;
-import org.apache.james.mailbox.postgres.mail.PostgresModSeqProvider;
-import org.apache.james.mailbox.postgres.mail.PostgresUidProvider;
-import org.apache.james.mailbox.postgres.mail.dao.PostgresMailboxAnnotationDAO;
-import org.apache.james.mailbox.postgres.mail.dao.PostgresMailboxDAO;
-import org.apache.james.mailbox.postgres.user.PostgresSubscriptionDAO;
-import org.apache.james.mailbox.postgres.user.PostgresSubscriptionMapper;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.AnnotationMapper;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
-import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
-import org.apache.james.mailbox.store.mail.MailboxMapper;
-import org.apache.james.mailbox.store.mail.MessageIdMapper;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.user.SubscriptionMapper;
-
-
-public class PostgresMailboxSessionMapperFactoryTODO extends MailboxSessionMapperFactory implements AttachmentMapperFactory {
-
- private final PostgresExecutor.Factory executorFactory;
- private final BlobStore blobStore;
- private final BlobId.Factory blobIdFactory;
- private final Clock clock;
-
- @Inject
- public PostgresMailboxSessionMapperFactoryTODO(PostgresExecutor.Factory executorFactory,
- Clock clock,
- BlobStore blobStore,
- BlobId.Factory blobIdFactory) {
- this.executorFactory = executorFactory;
- this.blobStore = blobStore;
- this.blobIdFactory = blobIdFactory;
- this.clock = clock;
- }
-
- @Override
- public MailboxMapper createMailboxMapper(MailboxSession session) {
- PostgresMailboxDAO mailboxDAO = new PostgresMailboxDAO(executorFactory.create(session.getUser().getDomainPart()));
- return new PostgresMailboxMapper(mailboxDAO);
- }
-
- @Override
- public MessageMapper createMessageMapper(MailboxSession session) {
- return new PostgresMessageMapper(executorFactory.create(session.getUser().getDomainPart()),
- getModSeqProvider(session),
- getUidProvider(session),
- blobStore,
- clock,
- blobIdFactory);
- }
-
- @Override
- public MessageIdMapper createMessageIdMapper(MailboxSession session) {
- throw new NotImplementedException("not implemented");
- }
-
- @Override
- public SubscriptionMapper createSubscriptionMapper(MailboxSession session) {
- return new PostgresSubscriptionMapper(new PostgresSubscriptionDAO(executorFactory.create(session.getUser().getDomainPart())));
- }
-
- @Override
- public AnnotationMapper createAnnotationMapper(MailboxSession session) {
- return new PostgresAnnotationMapper(new PostgresMailboxAnnotationDAO(executorFactory.create(session.getUser().getDomainPart())));
- }
-
- @Override
- public PostgresUidProvider getUidProvider(MailboxSession session) {
- return new PostgresUidProvider.Factory(executorFactory).create(session);
- }
-
- @Override
- public PostgresModSeqProvider getModSeqProvider(MailboxSession session) {
- return new PostgresModSeqProvider.Factory(executorFactory).create(session);
- }
-
- @Override
- public AttachmentMapper createAttachmentMapper(MailboxSession session) {
- throw new NotImplementedException("not implemented");
- }
-
- @Override
- public AttachmentMapper getAttachmentMapper(MailboxSession session) {
- throw new NotImplementedException("not implemented");
- }
-
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAAnnotationMapper.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAAnnotationMapper.java
deleted file mode 100644
index 7009fb95cc..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAAnnotationMapper.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.function.Predicate;
-
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.NoResultException;
-import javax.persistence.PersistenceException;
-
-import org.apache.james.mailbox.model.MailboxAnnotation;
-import org.apache.james.mailbox.model.MailboxAnnotationKey;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.postgres.JPATransactionalMapper;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailboxAnnotation;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailboxAnnotationId;
-import org.apache.james.mailbox.store.mail.AnnotationMapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
-public class JPAAnnotationMapper extends JPATransactionalMapper implements AnnotationMapper {
-
- private static final Logger LOGGER = LoggerFactory.getLogger(JPAAnnotationMapper.class);
-
- public static final Function<JPAMailboxAnnotation, MailboxAnnotation> READ_ROW =
- input -> MailboxAnnotation.newInstance(new MailboxAnnotationKey(input.getKey()), input.getValue());
-
- public JPAAnnotationMapper(EntityManagerFactory entityManagerFactory) {
- super(entityManagerFactory);
- }
-
- @Override
- public List<MailboxAnnotation> getAllAnnotations(MailboxId mailboxId) {
- JPAId jpaId = (JPAId) mailboxId;
- return getEntityManager().createNamedQuery("retrieveAllAnnotations", JPAMailboxAnnotation.class)
- .setParameter("idParam", jpaId.getRawId())
- .getResultList()
- .stream()
- .map(READ_ROW)
- .collect(ImmutableList.toImmutableList());
- }
-
- @Override
- public List<MailboxAnnotation> getAnnotationsByKeys(MailboxId mailboxId, Set<MailboxAnnotationKey> keys) {
- try {
- final JPAId jpaId = (JPAId) mailboxId;
- return keys.stream()
- .map(input -> READ_ROW.apply(
- getEntityManager()
- .createNamedQuery("retrieveByKey", JPAMailboxAnnotation.class)
- .setParameter("idParam", jpaId.getRawId())
- .setParameter("keyParam", input.asString())
- .getSingleResult()))
- .collect(ImmutableList.toImmutableList());
- } catch (NoResultException e) {
- return ImmutableList.of();
- }
- }
-
- @Override
- public List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxId mailboxId, Set<MailboxAnnotationKey> keys) {
- return getFilteredLikes((JPAId) mailboxId,
- keys,
- key ->
- annotation ->
- key.isParentOrIsEqual(annotation.getKey()));
- }
-
- @Override
- public List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxId mailboxId, Set<MailboxAnnotationKey> keys) {
- return getFilteredLikes((JPAId) mailboxId,
- keys,
- key ->
- annotation -> key.isAncestorOrIsEqual(annotation.getKey()));
- }
-
- private List<MailboxAnnotation> getFilteredLikes(final JPAId jpaId, Set<MailboxAnnotationKey> keys, final Function<MailboxAnnotationKey, Predicate<MailboxAnnotation>> predicateFunction) {
- try {
- return keys.stream()
- .flatMap(key -> getEntityManager()
- .createNamedQuery("retrieveByKeyLike", JPAMailboxAnnotation.class)
- .setParameter("idParam", jpaId.getRawId())
- .setParameter("keyParam", key.asString() + '%')
- .getResultList()
- .stream()
- .map(READ_ROW)
- .filter(predicateFunction.apply(key)))
- .collect(ImmutableList.toImmutableList());
- } catch (NoResultException e) {
- return ImmutableList.of();
- }
- }
-
- @Override
- public void deleteAnnotation(MailboxId mailboxId, MailboxAnnotationKey key) {
- try {
- JPAId jpaId = (JPAId) mailboxId;
- JPAMailboxAnnotation jpaMailboxAnnotation = getEntityManager()
- .find(JPAMailboxAnnotation.class, new JPAMailboxAnnotationId(jpaId.getRawId(), key.asString()));
- getEntityManager().remove(jpaMailboxAnnotation);
- } catch (NoResultException e) {
- LOGGER.debug("Mailbox annotation not found for ID {} and key {}", mailboxId.serialize(), key.asString());
- } catch (PersistenceException pe) {
- throw new RuntimeException(pe);
- }
- }
-
- @Override
- public void insertAnnotation(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) {
- Preconditions.checkArgument(!mailboxAnnotation.isNil());
- JPAId jpaId = (JPAId) mailboxId;
- if (getAnnotationsByKeys(mailboxId, ImmutableSet.of(mailboxAnnotation.getKey())).isEmpty()) {
- getEntityManager().persist(
- new JPAMailboxAnnotation(jpaId.getRawId(),
- mailboxAnnotation.getKey().asString(),
- mailboxAnnotation.getValue().orElse(null)));
- } else {
- getEntityManager().find(JPAMailboxAnnotation.class,
- new JPAMailboxAnnotationId(jpaId.getRawId(), mailboxAnnotation.getKey().asString()))
- .setValue(mailboxAnnotation.getValue().orElse(null));
- }
- }
-
- @Override
- public boolean exist(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) {
- JPAId jpaId = (JPAId) mailboxId;
- Optional<JPAMailboxAnnotation> row = Optional.ofNullable(getEntityManager().find(JPAMailboxAnnotation.class,
- new JPAMailboxAnnotationId(jpaId.getRawId(), mailboxAnnotation.getKey().asString())));
- return row.isPresent();
- }
-
- @Override
- public int countAnnotations(MailboxId mailboxId) {
- try {
- JPAId jpaId = (JPAId) mailboxId;
- return ((Long)getEntityManager().createNamedQuery("countAnnotationsInMailbox")
- .setParameter("idParam", jpaId.getRawId()).getSingleResult()).intValue();
- } catch (PersistenceException pe) {
- throw new RuntimeException(pe);
- }
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAAttachmentMapper.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAAttachmentMapper.java
deleted file mode 100644
index dc91260fc3..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAAttachmentMapper.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/***************************************************************
- * 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.postgres.mail;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.List;
-
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.NoResultException;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.james.mailbox.exception.AttachmentNotFoundException;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.AttachmentId;
-import org.apache.james.mailbox.model.AttachmentMetadata;
-import org.apache.james.mailbox.model.MessageAttachmentMetadata;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.ParsedAttachment;
-import org.apache.james.mailbox.postgres.JPATransactionalMapper;
-import org.apache.james.mailbox.postgres.mail.model.JPAAttachment;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
-
-import com.github.fge.lambdas.Throwing;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-
-public class JPAAttachmentMapper extends JPATransactionalMapper implements AttachmentMapper {
-
- private static final String ID_PARAM = "idParam";
-
- public JPAAttachmentMapper(EntityManagerFactory entityManagerFactory) {
- super(entityManagerFactory);
- }
-
- @Override
- public InputStream loadAttachmentContent(AttachmentId attachmentId) {
- Preconditions.checkArgument(attachmentId != null);
- return getEntityManager().createNamedQuery("findAttachmentById", JPAAttachment.class)
- .setParameter(ID_PARAM, attachmentId.getId())
- .getSingleResult().getContent();
- }
-
- @Override
- public AttachmentMetadata getAttachment(AttachmentId attachmentId) throws AttachmentNotFoundException {
- Preconditions.checkArgument(attachmentId != null);
- AttachmentMetadata attachmentMetadata = getAttachmentMetadata(attachmentId);
- if (attachmentMetadata == null) {
- throw new AttachmentNotFoundException(attachmentId.getId());
- }
- return attachmentMetadata;
- }
-
- @Override
- public List<AttachmentMetadata> getAttachments(Collection<AttachmentId> attachmentIds) {
- Preconditions.checkArgument(attachmentIds != null);
- ImmutableList.Builder<AttachmentMetadata> builder = ImmutableList.builder();
- for (AttachmentId attachmentId : attachmentIds) {
- AttachmentMetadata attachmentMetadata = getAttachmentMetadata(attachmentId);
- if (attachmentMetadata != null) {
- builder.add(attachmentMetadata);
- }
- }
- return builder.build();
- }
-
- @Override
- public List<MessageAttachmentMetadata> storeAttachments(Collection<ParsedAttachment> parsedAttachments, MessageId ownerMessageId) {
- Preconditions.checkArgument(parsedAttachments != null);
- Preconditions.checkArgument(ownerMessageId != null);
- return parsedAttachments.stream()
- .map(Throwing.<ParsedAttachment, MessageAttachmentMetadata>function(
- typedContent -> storeAttachmentForMessage(ownerMessageId, typedContent))
- .sneakyThrow())
- .collect(ImmutableList.toImmutableList());
- }
-
- private AttachmentMetadata getAttachmentMetadata(AttachmentId attachmentId) {
- try {
- return getEntityManager().createNamedQuery("findAttachmentById", JPAAttachment.class)
- .setParameter(ID_PARAM, attachmentId.getId())
- .getSingleResult()
- .toAttachmentMetadata();
- } catch (NoResultException e) {
- return null;
- }
- }
-
- private MessageAttachmentMetadata storeAttachmentForMessage(MessageId ownerMessageId, ParsedAttachment parsedAttachment) throws MailboxException {
- try {
- byte[] bytes = IOUtils.toByteArray(parsedAttachment.getContent().openStream());
- JPAAttachment persistedAttachment = new JPAAttachment(parsedAttachment.asMessageAttachment(AttachmentId.random(), ownerMessageId), bytes);
- getEntityManager().persist(persistedAttachment);
- AttachmentId attachmentId = AttachmentId.from(persistedAttachment.getAttachmentId());
- return parsedAttachment.asMessageAttachment(attachmentId, bytes.length, ownerMessageId);
- } catch (IOException e) {
- throw new MailboxException("Failed to store attachment for message " + ownerMessageId, e);
- }
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAMailboxMapper.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAMailboxMapper.java
deleted file mode 100644
index 810f2388b8..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAMailboxMapper.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import java.util.NoSuchElementException;
-
-import javax.persistence.EntityExistsException;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.NoResultException;
-import javax.persistence.PersistenceException;
-import javax.persistence.RollbackException;
-import javax.persistence.TypedQuery;
-
-import org.apache.james.core.Username;
-import org.apache.james.mailbox.acl.ACLDiff;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.exception.MailboxExistsException;
-import org.apache.james.mailbox.exception.MailboxNotFoundException;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxACL.Right;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.UidValidity;
-import org.apache.james.mailbox.model.search.MailboxQuery;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.postgres.JPATransactionalMapper;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailbox;
-import org.apache.james.mailbox.store.MailboxExpressionBackwardCompatibility;
-import org.apache.james.mailbox.store.mail.MailboxMapper;
-
-import com.google.common.base.Preconditions;
-
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
-
-/**
- * Data access management for mailbox.
- */
-public class JPAMailboxMapper extends JPATransactionalMapper implements MailboxMapper {
-
- private static final char SQL_WILDCARD_CHAR = '%';
- private String lastMailboxName;
-
- public JPAMailboxMapper(EntityManagerFactory entityManagerFactory) {
- super(entityManagerFactory);
- }
-
- /**
- * Commit the transaction. If the commit fails due a conflict in a unique key constraint a {@link MailboxExistsException}
- * will get thrown
- */
- @Override
- protected void commit() throws MailboxException {
- try {
- getEntityManager().getTransaction().commit();
- } catch (PersistenceException e) {
- if (e instanceof EntityExistsException) {
- throw new MailboxExistsException(lastMailboxName);
- }
- if (e instanceof RollbackException) {
- Throwable t = e.getCause();
- if (t instanceof EntityExistsException) {
- throw new MailboxExistsException(lastMailboxName);
- }
- }
- throw new MailboxException("Commit of transaction failed", e);
- }
- }
-
- @Override
- public Mono<Mailbox> create(MailboxPath mailboxPath, UidValidity uidValidity) {
- return assertPathIsNotAlreadyUsedByAnotherMailbox(mailboxPath)
- .then(Mono.fromCallable(() -> {
- this.lastMailboxName = mailboxPath.getName();
- JPAMailbox persistedMailbox = new JPAMailbox(mailboxPath, uidValidity);
- getEntityManager().persist(persistedMailbox);
-
- return new Mailbox(mailboxPath, uidValidity, persistedMailbox.getMailboxId());
- }).subscribeOn(Schedulers.boundedElastic()))
- .onErrorMap(PersistenceException.class, e -> new MailboxException("Save of mailbox " + mailboxPath.getName() + " failed", e));
- }
-
- @Override
- public Mono<MailboxId> rename(Mailbox mailbox) {
- Preconditions.checkNotNull(mailbox.getMailboxId(), "A mailbox we want to rename should have a defined mailboxId");
-
- return assertPathIsNotAlreadyUsedByAnotherMailbox(mailbox.generateAssociatedPath())
- .then(Mono.fromCallable(() -> {
- this.lastMailboxName = mailbox.getName();
- JPAMailbox persistedMailbox = jpaMailbox(mailbox);
-
- getEntityManager().persist(persistedMailbox);
- return (MailboxId) persistedMailbox.getMailboxId();
- }).subscribeOn(Schedulers.boundedElastic()))
- .onErrorMap(PersistenceException.class, e -> new MailboxException("Save of mailbox " + mailbox.getName() + " failed", e));
- }
-
- private JPAMailbox jpaMailbox(Mailbox mailbox) throws MailboxException {
- JPAMailbox result = loadJpaMailbox(mailbox.getMailboxId());
- result.setNamespace(mailbox.getNamespace());
- result.setUser(mailbox.getUser().asString());
- result.setName(mailbox.getName());
- return result;
- }
-
- private Mono<Void> assertPathIsNotAlreadyUsedByAnotherMailbox(MailboxPath mailboxPath) {
- return findMailboxByPath(mailboxPath)
- .flatMap(ignored -> Mono.error(new MailboxExistsException(mailboxPath.getName())));
- }
-
- @Override
- public Mono<Mailbox> findMailboxByPath(MailboxPath mailboxPath) {
- return Mono.fromCallable(() -> getEntityManager().createNamedQuery("findMailboxByNameWithUser", JPAMailbox.class)
- .setParameter("nameParam", mailboxPath.getName())
- .setParameter("namespaceParam", mailboxPath.getNamespace())
- .setParameter("userParam", mailboxPath.getUser().asString())
- .getSingleResult()
- .toMailbox())
- .onErrorResume(NoResultException.class, e -> Mono.empty())
- .onErrorResume(NoSuchElementException.class, e -> Mono.empty())
- .onErrorResume(PersistenceException.class, e -> Mono.error(new MailboxException("Exception upon JPA execution", e)))
- .subscribeOn(Schedulers.boundedElastic());
- }
-
- @Override
- public Mono<Mailbox> findMailboxById(MailboxId id) {
- return Mono.fromCallable(() -> loadJpaMailbox(id).toMailbox())
- .subscribeOn(Schedulers.boundedElastic())
- .onErrorMap(PersistenceException.class, e -> new MailboxException("Search of mailbox " + id.serialize() + " failed", e));
- }
-
- private JPAMailbox loadJpaMailbox(MailboxId id) throws MailboxNotFoundException {
- JPAId mailboxId = (JPAId)id;
- try {
- return getEntityManager().createNamedQuery("findMailboxById", JPAMailbox.class)
- .setParameter("idParam", mailboxId.getRawId())
- .getSingleResult();
- } catch (NoResultException e) {
- throw new MailboxNotFoundException(mailboxId);
- }
- }
-
- @Override
- public Mono<Void> delete(Mailbox mailbox) {
- return Mono.fromRunnable(() -> {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- getEntityManager().createNamedQuery("deleteMessages").setParameter("idParam", mailboxId.getRawId()).executeUpdate();
- JPAMailbox jpaMailbox = getEntityManager().find(JPAMailbox.class, mailboxId.getRawId());
- getEntityManager().remove(jpaMailbox);
- })
- .subscribeOn(Schedulers.boundedElastic())
- .onErrorMap(PersistenceException.class, e -> new MailboxException("Delete of mailbox " + mailbox + " failed", e))
- .then();
- }
-
- @Override
- public Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query) {
- String pathLike = MailboxExpressionBackwardCompatibility.getPathLike(query);
- return Mono.fromCallable(() -> findMailboxWithPathLikeTypedQuery(query.getFixedNamespace(), query.getFixedUser(), pathLike))
- .subscribeOn(Schedulers.boundedElastic())
- .flatMapIterable(TypedQuery::getResultList)
- .map(JPAMailbox::toMailbox)
- .filter(query::matches)
- .onErrorMap(PersistenceException.class, e -> new MailboxException("Search of mailbox " + query + " failed", e));
- }
-
- private TypedQuery<JPAMailbox> findMailboxWithPathLikeTypedQuery(String namespace, Username username, String pathLike) {
- return getEntityManager().createNamedQuery("findMailboxWithNameLikeWithUser", JPAMailbox.class)
- .setParameter("nameParam", pathLike)
- .setParameter("namespaceParam", namespace)
- .setParameter("userParam", username.asString());
- }
-
- @Override
- public Mono<Boolean> hasChildren(Mailbox mailbox, char delimiter) {
- final String name = mailbox.getName() + delimiter + SQL_WILDCARD_CHAR;
-
- return Mono.defer(() -> Mono.justOrEmpty((Long) getEntityManager()
- .createNamedQuery("countMailboxesWithNameLikeWithUser")
- .setParameter("nameParam", name)
- .setParameter("namespaceParam", mailbox.getNamespace())
- .setParameter("userParam", mailbox.getUser().asString())
- .getSingleResult()))
- .subscribeOn(Schedulers.boundedElastic())
- .filter(numberOfChildMailboxes -> numberOfChildMailboxes > 0)
- .hasElement();
- }
-
- @Override
- public Flux<Mailbox> list() {
- return Mono.fromCallable(() -> getEntityManager().createNamedQuery("listMailboxes", JPAMailbox.class))
- .subscribeOn(Schedulers.boundedElastic())
- .flatMapIterable(TypedQuery::getResultList)
- .onErrorMap(PersistenceException.class, e -> new MailboxException("Delete of mailboxes failed", e))
- .map(JPAMailbox::toMailbox);
- }
-
- @Override
- public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) {
- return Mono.fromCallable(() -> {
- MailboxACL oldACL = mailbox.getACL();
- MailboxACL newACL = mailbox.getACL().apply(mailboxACLCommand);
- mailbox.setACL(newACL);
- return ACLDiff.computeDiff(oldACL, newACL);
- }).subscribeOn(Schedulers.boundedElastic());
- }
-
- @Override
- public Mono<ACLDiff> setACL(Mailbox mailbox, MailboxACL mailboxACL) {
- return Mono.fromCallable(() -> {
- MailboxACL oldMailboxAcl = mailbox.getACL();
- mailbox.setACL(mailboxACL);
- return ACLDiff.computeDiff(oldMailboxAcl, mailboxACL);
- }).subscribeOn(Schedulers.boundedElastic());
- }
-
- @Override
- public Flux<Mailbox> findNonPersonalMailboxes(Username userName, Right right) {
- return Flux.empty();
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAMessageMapper.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAMessageMapper.java
deleted file mode 100644
index 89c2d3d1d6..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAMessageMapper.java
+++ /dev/null
@@ -1,510 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.stream.Collectors;
-
-import javax.mail.Flags;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceException;
-import javax.persistence.Query;
-
-import org.apache.james.backends.jpa.JPAConfiguration;
-import org.apache.james.mailbox.ApplicableFlagBuilder;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.ModSeq;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MailboxCounters;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MessageAttachmentMetadata;
-import org.apache.james.mailbox.model.MessageMetaData;
-import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.model.MessageRange.Type;
-import org.apache.james.mailbox.model.UpdatedFlags;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.postgres.JPATransactionalMapper;
-import org.apache.james.mailbox.postgres.mail.MessageUtils.MessageChangedFlags;
-import org.apache.james.mailbox.postgres.mail.model.JPAAttachment;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailbox;
-import org.apache.james.mailbox.postgres.mail.model.openjpa.AbstractJPAMailboxMessage;
-import org.apache.james.mailbox.postgres.mail.model.openjpa.JPAMailboxMessage;
-import org.apache.james.mailbox.store.FlagsUpdateCalculator;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.openjpa.persistence.ArgumentException;
-
-import com.github.fge.lambdas.Throwing;
-import com.google.common.collect.ImmutableList;
-
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-import reactor.core.scheduler.Schedulers;
-
-/**
- * JPA implementation of a {@link MessageMapper}. This class is not thread-safe!
- */
-public class JPAMessageMapper extends JPATransactionalMapper implements MessageMapper {
- private static final int UNLIMIT_MAX_SIZE = -1;
- private static final int UNLIMITED = -1;
-
- private final MessageUtils messageMetadataMapper;
- private final JPAUidProvider uidProvider;
- private final JPAModSeqProvider modSeqProvider;
- private final JPAConfiguration jpaConfiguration;
-
- public JPAMessageMapper(JPAUidProvider uidProvider, JPAModSeqProvider modSeqProvider, EntityManagerFactory entityManagerFactory,
- JPAConfiguration jpaConfiguration) {
- super(entityManagerFactory);
- this.messageMetadataMapper = new MessageUtils(uidProvider, modSeqProvider);
- this.uidProvider = uidProvider;
- this.modSeqProvider = modSeqProvider;
- this.jpaConfiguration = jpaConfiguration;
- }
-
- @Override
- public MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException {
- return MailboxCounters.builder()
- .mailboxId(mailbox.getMailboxId())
- .count(countMessagesInMailbox(mailbox))
- .unseen(countUnseenMessagesInMailbox(mailbox))
- .build();
- }
-
- @Override
- public Flux<MessageUid> listAllMessageUids(Mailbox mailbox) {
- return Mono.fromCallable(() -> {
- try {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- Query query = getEntityManager().createNamedQuery("listUidsInMailbox")
- .setParameter("idParam", mailboxId.getRawId());
- return query.getResultStream().map(result -> MessageUid.of((Long) result));
- } catch (PersistenceException e) {
- throw new MailboxException("Search of recent messages failed in mailbox " + mailbox, e);
- }
- }).flatMapMany(Flux::fromStream)
- .subscribeOn(Schedulers.boundedElastic());
- }
-
- @Override
- public Flux<MailboxMessage> findInMailboxReactive(Mailbox mailbox, MessageRange messageRange, FetchType ftype, int limitAsInt) {
- return Flux.defer(Throwing.supplier(() -> Flux.fromIterable(findAsList(mailbox.getMailboxId(), messageRange, limitAsInt))).sneakyThrow())
- .subscribeOn(Schedulers.boundedElastic());
- }
-
- @Override
- public Iterator<MailboxMessage> findInMailbox(Mailbox mailbox, MessageRange set, FetchType fType, int max)
- throws MailboxException {
-
- return findAsList(mailbox.getMailboxId(), set, max).iterator();
- }
-
- private List<MailboxMessage> findAsList(MailboxId mailboxId, MessageRange set, int max) throws MailboxException {
- try {
- MessageUid from = set.getUidFrom();
- MessageUid to = set.getUidTo();
- Type type = set.getType();
- JPAId jpaId = (JPAId) mailboxId;
-
- switch (type) {
- default:
- case ALL:
- return findMessagesInMailbox(jpaId, max);
- case FROM:
- return findMessagesInMailboxAfterUID(jpaId, from, max);
- case ONE:
- return findMessagesInMailboxWithUID(jpaId, from);
- case RANGE:
- return findMessagesInMailboxBetweenUIDs(jpaId, from, to, max);
- }
- } catch (PersistenceException e) {
- throw new MailboxException("Search of MessageRange " + set + " failed in mailbox " + mailboxId.serialize(), e);
- }
- }
-
- @Override
- public long countMessagesInMailbox(Mailbox mailbox) throws MailboxException {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- return countMessagesInMailbox(mailboxId);
- }
-
- private long countMessagesInMailbox(JPAId mailboxId) throws MailboxException {
- try {
- return (Long) getEntityManager().createNamedQuery("countMessagesInMailbox")
- .setParameter("idParam", mailboxId.getRawId()).getSingleResult();
- } catch (PersistenceException e) {
- throw new MailboxException("Count of messages failed in mailbox " + mailboxId, e);
- }
- }
-
- public long countUnseenMessagesInMailbox(Mailbox mailbox) throws MailboxException {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- return countUnseenMessagesInMailbox(mailboxId);
- }
-
- private long countUnseenMessagesInMailbox(JPAId mailboxId) throws MailboxException {
- try {
- return (Long) getEntityManager().createNamedQuery("countUnseenMessagesInMailbox")
- .setParameter("idParam", mailboxId.getRawId()).getSingleResult();
- } catch (PersistenceException e) {
- throw new MailboxException("Count of useen messages failed in mailbox " + mailboxId, e);
- }
- }
-
- @Override
- public void delete(Mailbox mailbox, MailboxMessage message) throws MailboxException {
- try {
- AbstractJPAMailboxMessage jpaMessage = getEntityManager().find(AbstractJPAMailboxMessage.class, buildKey(mailbox, message));
- getEntityManager().remove(jpaMessage);
-
- } catch (PersistenceException e) {
- throw new MailboxException("Delete of message " + message + " failed in mailbox " + mailbox, e);
- }
- }
-
- private AbstractJPAMailboxMessage.MailboxIdUidKey buildKey(Mailbox mailbox, MailboxMessage message) {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- AbstractJPAMailboxMessage.MailboxIdUidKey key = new AbstractJPAMailboxMessage.MailboxIdUidKey();
- key.mailbox = mailboxId.getRawId();
- key.uid = message.getUid().asLong();
- return key;
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public MessageUid findFirstUnseenMessageUid(Mailbox mailbox) throws MailboxException {
- try {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- Query query = getEntityManager().createNamedQuery("findUnseenMessagesInMailboxOrderByUid").setParameter(
- "idParam", mailboxId.getRawId());
- query.setMaxResults(1);
- List<MailboxMessage> result = query.getResultList();
- if (result.isEmpty()) {
- return null;
- } else {
- return result.get(0).getUid();
- }
- } catch (PersistenceException e) {
- throw new MailboxException("Search of first unseen message failed in mailbox " + mailbox, e);
- }
- }
-
- @Override
- @SuppressWarnings("unchecked")
- public List<MessageUid> findRecentMessageUidsInMailbox(Mailbox mailbox) throws MailboxException {
- try {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- Query query = getEntityManager().createNamedQuery("findRecentMessageUidsInMailbox").setParameter("idParam",
- mailboxId.getRawId());
- List<Long> resultList = query.getResultList();
- ImmutableList.Builder<MessageUid> results = ImmutableList.builder();
- for (long result: resultList) {
- results.add(MessageUid.of(result));
- }
- return results.build();
- } catch (PersistenceException e) {
- throw new MailboxException("Search of recent messages failed in mailbox " + mailbox, e);
- }
- }
-
-
-
- @Override
- public List<MessageUid> retrieveMessagesMarkedForDeletion(Mailbox mailbox, MessageRange messageRange) throws MailboxException {
- try {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- List<MailboxMessage> messages = findDeletedMessages(messageRange, mailboxId);
- return getUidList(messages);
- } catch (PersistenceException e) {
- throw new MailboxException("Search of MessageRange " + messageRange + " failed in mailbox " + mailbox, e);
- }
- }
-
- private List<MailboxMessage> findDeletedMessages(MessageRange messageRange, JPAId mailboxId) {
- MessageUid from = messageRange.getUidFrom();
- MessageUid to = messageRange.getUidTo();
-
- switch (messageRange.getType()) {
- case ONE:
- return findDeletedMessagesInMailboxWithUID(mailboxId, from);
- case RANGE:
- return findDeletedMessagesInMailboxBetweenUIDs(mailboxId, from, to);
- case FROM:
- return findDeletedMessagesInMailboxAfterUID(mailboxId, from);
- case ALL:
- return findDeletedMessagesInMailbox(mailboxId);
- default:
- throw new RuntimeException("Cannot find deleted messages, range type " + messageRange.getType() + " doesn't exist");
- }
- }
-
- @Override
- public Map<MessageUid, MessageMetaData> deleteMessages(Mailbox mailbox, List<MessageUid> uids) throws MailboxException {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- Map<MessageUid, MessageMetaData> data = new HashMap<>();
- List<MessageRange> ranges = MessageRange.toRanges(uids);
-
- ranges.forEach(Throwing.<MessageRange>consumer(range -> {
- List<MailboxMessage> messages = findAsList(mailboxId, range, JPAMessageMapper.UNLIMITED);
- data.putAll(createMetaData(messages));
- deleteMessages(range, mailboxId);
- }).sneakyThrow());
-
- return data;
- }
-
- private void deleteMessages(MessageRange messageRange, JPAId mailboxId) {
- MessageUid from = messageRange.getUidFrom();
- MessageUid to = messageRange.getUidTo();
-
- switch (messageRange.getType()) {
- case ONE:
- deleteMessagesInMailboxWithUID(mailboxId, from);
- break;
- case RANGE:
- deleteMessagesInMailboxBetweenUIDs(mailboxId, from, to);
- break;
- case FROM:
- deleteMessagesInMailboxAfterUID(mailboxId, from);
- break;
- case ALL:
- deleteMessagesInMailbox(mailboxId);
- break;
- default:
- throw new RuntimeException("Cannot delete messages, range type " + messageRange.getType() + " doesn't exist");
- }
- }
-
- @Override
- public MessageMetaData move(Mailbox mailbox, MailboxMessage original) throws MailboxException {
- JPAId originalMailboxId = (JPAId) original.getMailboxId();
- JPAMailbox originalMailbox = getEntityManager().find(JPAMailbox.class, originalMailboxId.getRawId());
-
- MessageMetaData messageMetaData = copy(mailbox, original);
- delete(originalMailbox.toMailbox(), original);
-
- return messageMetaData;
- }
-
- @Override
- public MessageMetaData add(Mailbox mailbox, MailboxMessage message) throws MailboxException {
- messageMetadataMapper.enrichMessage(mailbox, message);
-
- return save(mailbox, message);
- }
-
- @Override
- public Iterator<UpdatedFlags> updateFlags(Mailbox mailbox, FlagsUpdateCalculator flagsUpdateCalculator,
- MessageRange set) throws MailboxException {
- Iterator<MailboxMessage> messages = findInMailbox(mailbox, set, FetchType.METADATA, UNLIMIT_MAX_SIZE);
-
- MessageChangedFlags messageChangedFlags = messageMetadataMapper.updateFlags(mailbox, flagsUpdateCalculator, messages);
-
- for (MailboxMessage mailboxMessage : messageChangedFlags.getChangedFlags()) {
- save(mailbox, mailboxMessage);
- }
-
- return messageChangedFlags.getUpdatedFlags();
- }
-
- @Override
- public MessageMetaData copy(Mailbox mailbox, MailboxMessage original) throws MailboxException {
- return copy(mailbox, uidProvider.nextUid(mailbox), modSeqProvider.nextModSeq(mailbox), original);
- }
-
- @Override
- public Optional<MessageUid> getLastUid(Mailbox mailbox) throws MailboxException {
- return uidProvider.lastUid(mailbox, getEntityManager());
- }
-
- @Override
- public ModSeq getHighestModSeq(Mailbox mailbox) throws MailboxException {
- return modSeqProvider.highestModSeq(mailbox.getMailboxId(), getEntityManager());
- }
-
- @Override
- public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
- JPAId jpaId = (JPAId) mailbox.getMailboxId();
- ApplicableFlagBuilder builder = ApplicableFlagBuilder.builder();
- List<String> flags = getEntityManager().createNativeQuery("SELECT DISTINCT USERFLAG_NAME FROM JAMES_MAIL_USERFLAG WHERE MAILBOX_ID=?")
- .setParameter(1, jpaId.getRawId())
- .getResultList();
- flags.forEach(builder::add);
- return builder.build();
- }
-
- private MessageMetaData copy(Mailbox mailbox, MessageUid uid, ModSeq modSeq, MailboxMessage original)
- throws MailboxException {
- MailboxMessage copy;
- JPAMailbox currentMailbox = JPAMailbox.from(mailbox);
-
- copy = new JPAMailboxMessage(currentMailbox, uid, modSeq, original);
- return save(mailbox, copy);
- }
-
- protected MessageMetaData save(Mailbox mailbox, MailboxMessage message) throws MailboxException {
- try {
- // We need to reload a "JPA attached" mailbox, because the provide
- // mailbox is already "JPA detached"
- // If we don't this, we will get an
- // org.apache.openjpa.persistence.ArgumentException.
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- JPAMailbox currentMailbox = getEntityManager().find(JPAMailbox.class, mailboxId.getRawId());
-
- boolean isAttachmentStorage = false;
- if (Objects.nonNull(jpaConfiguration)) {
- isAttachmentStorage = jpaConfiguration.isAttachmentStorageEnabled().orElse(false);
- }
-
- if (message instanceof AbstractJPAMailboxMessage) {
- ((AbstractJPAMailboxMessage) message).setMailbox(currentMailbox);
-
- getEntityManager().persist(message);
- return message.metaData();
- } else {
- JPAMailboxMessage persistData = new JPAMailboxMessage(currentMailbox, message.getUid(), message.getModSeq(), message);
- persistData.setFlags(message.createFlags());
- getEntityManager().persist(persistData);
- return persistData.metaData();
- }
-
- } catch (PersistenceException | ArgumentException e) {
- throw new MailboxException("Save of message " + message + " failed in mailbox " + mailbox, e);
- }
- }
-
- private List<JPAAttachment> getAttachments(MailboxMessage message) {
- return message.getAttachments().stream()
- .map(MessageAttachmentMetadata::getAttachmentId)
- .map(attachmentId -> getEntityManager().createNamedQuery("findAttachmentById", JPAAttachment.class)
- .setParameter("idParam", attachmentId.getId())
- .getSingleResult())
- .collect(Collectors.toList());
- }
-
- @SuppressWarnings("unchecked")
- private List<MailboxMessage> findMessagesInMailboxAfterUID(JPAId mailboxId, MessageUid from, int batchSize) {
- Query query = getEntityManager().createNamedQuery("findMessagesInMailboxAfterUID")
- .setParameter("idParam", mailboxId.getRawId()).setParameter("uidParam", from.asLong());
-
- if (batchSize > 0) {
- query.setMaxResults(batchSize);
- }
-
- return query.getResultList();
- }
-
- @SuppressWarnings("unchecked")
- private List<MailboxMessage> findMessagesInMailboxWithUID(JPAId mailboxId, MessageUid from) {
- return getEntityManager().createNamedQuery("findMessagesInMailboxWithUID")
- .setParameter("idParam", mailboxId.getRawId()).setParameter("uidParam", from.asLong()).setMaxResults(1)
- .getResultList();
- }
-
- @SuppressWarnings("unchecked")
- private List<MailboxMessage> findMessagesInMailboxBetweenUIDs(JPAId mailboxId, MessageUid from, MessageUid to,
- int batchSize) {
- Query query = getEntityManager().createNamedQuery("findMessagesInMailboxBetweenUIDs")
- .setParameter("idParam", mailboxId.getRawId()).setParameter("fromParam", from.asLong())
- .setParameter("toParam", to.asLong());
-
- if (batchSize > 0) {
- query.setMaxResults(batchSize);
- }
-
- return query.getResultList();
- }
-
- @SuppressWarnings("unchecked")
- private List<MailboxMessage> findMessagesInMailbox(JPAId mailboxId, int batchSize) {
- Query query = getEntityManager().createNamedQuery("findMessagesInMailbox").setParameter("idParam",
- mailboxId.getRawId());
- if (batchSize > 0) {
- query.setMaxResults(batchSize);
- }
- return query.getResultList();
- }
-
- private Map<MessageUid, MessageMetaData> createMetaData(List<MailboxMessage> uids) {
- final Map<MessageUid, MessageMetaData> data = new HashMap<>();
- for (MailboxMessage m : uids) {
- data.put(m.getUid(), m.metaData());
- }
- return data;
- }
-
- private List<MessageUid> getUidList(List<MailboxMessage> messages) {
- return messages.stream()
- .map(MailboxMessage::getUid)
- .collect(ImmutableList.toImmutableList());
- }
-
- private int deleteMessagesInMailbox(JPAId mailboxId) {
- return getEntityManager().createNamedQuery("deleteMessagesInMailbox")
- .setParameter("idParam", mailboxId.getRawId()).executeUpdate();
- }
-
- private int deleteMessagesInMailboxAfterUID(JPAId mailboxId, MessageUid from) {
- return getEntityManager().createNamedQuery("deleteMessagesInMailboxAfterUID")
- .setParameter("idParam", mailboxId.getRawId()).setParameter("uidParam", from.asLong()).executeUpdate();
- }
-
- private int deleteMessagesInMailboxWithUID(JPAId mailboxId, MessageUid from) {
- return getEntityManager().createNamedQuery("deleteMessagesInMailboxWithUID")
- .setParameter("idParam", mailboxId.getRawId()).setParameter("uidParam", from.asLong()).executeUpdate();
- }
-
- private int deleteMessagesInMailboxBetweenUIDs(JPAId mailboxId, MessageUid from, MessageUid to) {
- return getEntityManager().createNamedQuery("deleteMessagesInMailboxBetweenUIDs")
- .setParameter("idParam", mailboxId.getRawId()).setParameter("fromParam", from.asLong())
- .setParameter("toParam", to.asLong()).executeUpdate();
- }
-
- @SuppressWarnings("unchecked")
- private List<MailboxMessage> findDeletedMessagesInMailbox(JPAId mailboxId) {
- return getEntityManager().createNamedQuery("findDeletedMessagesInMailbox")
- .setParameter("idParam", mailboxId.getRawId()).getResultList();
- }
-
- @SuppressWarnings("unchecked")
- private List<MailboxMessage> findDeletedMessagesInMailboxAfterUID(JPAId mailboxId, MessageUid from) {
- return getEntityManager().createNamedQuery("findDeletedMessagesInMailboxAfterUID")
- .setParameter("idParam", mailboxId.getRawId()).setParameter("uidParam", from.asLong()).getResultList();
- }
-
- @SuppressWarnings("unchecked")
- private List<MailboxMessage> findDeletedMessagesInMailboxWithUID(JPAId mailboxId, MessageUid from) {
- return getEntityManager().createNamedQuery("findDeletedMessagesInMailboxWithUID")
- .setParameter("idParam", mailboxId.getRawId()).setParameter("uidParam", from.asLong()).setMaxResults(1)
- .getResultList();
- }
-
- @SuppressWarnings("unchecked")
- private List<MailboxMessage> findDeletedMessagesInMailboxBetweenUIDs(JPAId mailboxId, MessageUid from, MessageUid to) {
- return getEntityManager().createNamedQuery("findDeletedMessagesInMailboxBetweenUIDs")
- .setParameter("idParam", mailboxId.getRawId()).setParameter("fromParam", from.asLong())
- .setParameter("toParam", to.asLong()).getResultList();
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAModSeqProvider.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAModSeqProvider.java
deleted file mode 100644
index bfa16f9ad1..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAModSeqProvider.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceException;
-
-import org.apache.james.backends.jpa.EntityManagerUtils;
-import org.apache.james.mailbox.ModSeq;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailbox;
-import org.apache.james.mailbox.store.mail.ModSeqProvider;
-
-public class JPAModSeqProvider implements ModSeqProvider {
-
- private final EntityManagerFactory factory;
-
- @Inject
- public JPAModSeqProvider(EntityManagerFactory factory) {
- this.factory = factory;
- }
-
- @Override
- public ModSeq highestModSeq(Mailbox mailbox) throws MailboxException {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- return highestModSeq(mailboxId);
- }
-
- @Override
- public ModSeq nextModSeq(Mailbox mailbox) throws MailboxException {
- return nextModSeq((JPAId) mailbox.getMailboxId());
- }
-
- @Override
- public ModSeq nextModSeq(MailboxId mailboxId) throws MailboxException {
- return nextModSeq((JPAId) mailboxId);
- }
-
- @Override
- public ModSeq highestModSeq(MailboxId mailboxId) throws MailboxException {
- return highestModSeq((JPAId) mailboxId);
- }
-
- private ModSeq nextModSeq(JPAId mailboxId) throws MailboxException {
- EntityManager manager = null;
- try {
- manager = factory.createEntityManager();
- manager.getTransaction().begin();
- JPAMailbox m = manager.find(JPAMailbox.class, mailboxId.getRawId());
- long modSeq = m.consumeModSeq();
- manager.persist(m);
- manager.getTransaction().commit();
- return ModSeq.of(modSeq);
- } catch (PersistenceException e) {
- if (manager != null && manager.getTransaction().isActive()) {
- manager.getTransaction().rollback();
- }
- throw new MailboxException("Unable to save highest mod-sequence for mailbox " + mailboxId.serialize(), e);
- } finally {
- EntityManagerUtils.safelyClose(manager);
- }
- }
-
- private ModSeq highestModSeq(JPAId mailboxId) throws MailboxException {
- EntityManager manager = factory.createEntityManager();
- try {
- return highestModSeq(mailboxId, manager);
- } finally {
- EntityManagerUtils.safelyClose(manager);
- }
- }
-
- public ModSeq highestModSeq(MailboxId mailboxId, EntityManager manager) throws MailboxException {
- JPAId jpaId = (JPAId) mailboxId;
- try {
- long highest = (Long) manager.createNamedQuery("findHighestModSeq")
- .setParameter("idParam", jpaId.getRawId())
- .getSingleResult();
- return ModSeq.of(highest);
- } catch (PersistenceException e) {
- throw new MailboxException("Unable to get highest mod-sequence for mailbox " + mailboxId.serialize(), e);
- }
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAUidProvider.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAUidProvider.java
deleted file mode 100644
index 2b778d0e41..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/JPAUidProvider.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import java.util.Optional;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.PersistenceException;
-
-import org.apache.james.backends.jpa.EntityManagerUtils;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailbox;
-import org.apache.james.mailbox.store.mail.UidProvider;
-
-public class JPAUidProvider implements UidProvider {
-
- private final EntityManagerFactory factory;
-
- @Inject
- public JPAUidProvider(EntityManagerFactory factory) {
- this.factory = factory;
- }
-
- @Override
- public Optional<MessageUid> lastUid(Mailbox mailbox) throws MailboxException {
- EntityManager manager = factory.createEntityManager();
- try {
- return lastUid(mailbox, manager);
- } finally {
- EntityManagerUtils.safelyClose(manager);
- }
- }
-
- public Optional<MessageUid> lastUid(Mailbox mailbox, EntityManager manager) throws MailboxException {
- try {
- JPAId mailboxId = (JPAId) mailbox.getMailboxId();
- long uid = (Long) manager.createNamedQuery("findLastUid").setParameter("idParam", mailboxId.getRawId()).getSingleResult();
- if (uid == 0) {
- return Optional.empty();
- }
- return Optional.of(MessageUid.of(uid));
- } catch (PersistenceException e) {
- throw new MailboxException("Unable to get last uid for mailbox " + mailbox, e);
- }
- }
-
- @Override
- public MessageUid nextUid(Mailbox mailbox) throws MailboxException {
- return nextUid((JPAId) mailbox.getMailboxId());
- }
-
- @Override
- public MessageUid nextUid(MailboxId mailboxId) throws MailboxException {
- return nextUid((JPAId) mailboxId);
- }
-
- private MessageUid nextUid(JPAId mailboxId) throws MailboxException {
- EntityManager manager = null;
- try {
- manager = factory.createEntityManager();
- manager.getTransaction().begin();
- JPAMailbox m = manager.find(JPAMailbox.class, mailboxId.getRawId());
- long uid = m.consumeUid();
- manager.persist(m);
- manager.getTransaction().commit();
- return MessageUid.of(uid);
- } catch (PersistenceException e) {
- if (manager != null && manager.getTransaction().isActive()) {
- manager.getTransaction().rollback();
- }
- throw new MailboxException("Unable to save next uid for mailbox " + mailboxId.serialize(), e);
- } finally {
- EntityManagerUtils.safelyClose(manager);
- }
- }
-
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/openjpa/OpenJPAMailboxManager.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresMailboxManager.java
similarity index 72%
rename from mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/openjpa/OpenJPAMailboxManager.java
rename to mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresMailboxManager.java
index 1bcd6c14fd..e0197d6777 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/openjpa/OpenJPAMailboxManager.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresMailboxManager.java
@@ -17,7 +17,7 @@
* under the License. *
****************************************************************/
-package org.apache.james.mailbox.postgres.openjpa;
+package org.apache.james.mailbox.postgres.mail;
import java.time.Clock;
import java.util.EnumSet;
@@ -29,9 +29,9 @@ import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.SessionProvider;
import org.apache.james.mailbox.model.Mailbox;
import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
+import org.apache.james.mailbox.postgres.PostgresMailboxSessionMapperFactory;
import org.apache.james.mailbox.store.MailboxManagerConfiguration;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.NoMailboxPathLocker;
import org.apache.james.mailbox.store.PreDeletionHooks;
import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
import org.apache.james.mailbox.store.StoreMailboxManager;
@@ -42,28 +42,27 @@ import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
import org.apache.james.mailbox.store.quota.QuotaComponents;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
-/**
- * OpenJPA implementation of MailboxManager
- */
-public class OpenJPAMailboxManager extends StoreMailboxManager {
- public static final EnumSet<MailboxCapabilities> MAILBOX_CAPABILITIES = EnumSet.of(MailboxCapabilities.UserFlag,
+public class PostgresMailboxManager extends StoreMailboxManager {
+
+ public static final EnumSet<MailboxCapabilities> MAILBOX_CAPABILITIES = EnumSet.of(
+ MailboxCapabilities.UserFlag,
MailboxCapabilities.Namespace,
MailboxCapabilities.Move,
MailboxCapabilities.Annotation);
@Inject
- public OpenJPAMailboxManager(MailboxSessionMapperFactory mapperFactory,
- SessionProvider sessionProvider,
- MessageParser messageParser,
- MessageId.Factory messageIdFactory,
- EventBus eventBus,
- StoreMailboxAnnotationManager annotationManager,
- StoreRightManager storeRightManager,
- QuotaComponents quotaComponents,
- MessageSearchIndex index,
- ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm,
- Clock clock) {
- super(mapperFactory, sessionProvider, new JVMMailboxPathLocker(),
+ public PostgresMailboxManager(PostgresMailboxSessionMapperFactory mapperFactory,
+ SessionProvider sessionProvider,
+ MessageParser messageParser,
+ MessageId.Factory messageIdFactory,
+ EventBus eventBus,
+ StoreMailboxAnnotationManager annotationManager,
+ StoreRightManager storeRightManager,
+ QuotaComponents quotaComponents,
+ MessageSearchIndex index,
+ ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm,
+ Clock clock) {
+ super(mapperFactory, sessionProvider, new NoMailboxPathLocker(),
messageParser, messageIdFactory, annotationManager,
eventBus, storeRightManager, quotaComponents,
index, MailboxManagerConfiguration.DEFAULT, PreDeletionHooks.NO_PRE_DELETION_HOOK, threadIdGuessingAlgorithm, clock);
@@ -71,7 +70,7 @@ public class OpenJPAMailboxManager extends StoreMailboxManager {
@Override
protected StoreMessageManager createMessageManager(Mailbox mailboxRow, MailboxSession session) {
- return new OpenJPAMessageManager(getMapperFactory(),
+ return new PostgresMessageManager(getMapperFactory(),
getMessageSearchIndex(),
getEventBus(),
getLocker(),
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/openjpa/OpenJPAMessageManager.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresMessageManager.java
similarity index 84%
rename from mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/openjpa/OpenJPAMessageManager.java
rename to mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresMessageManager.java
index 81c2d95555..39b584529d 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/openjpa/OpenJPAMessageManager.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/PostgresMessageManager.java
@@ -17,7 +17,7 @@
* under the License. *
****************************************************************/
-package org.apache.james.mailbox.postgres.openjpa;
+package org.apache.james.mailbox.postgres.mail;
import java.time.Clock;
import java.util.EnumSet;
@@ -50,21 +50,19 @@ import com.github.fge.lambdas.Throwing;
import reactor.core.publisher.Mono;
-/**
- * OpenJPA implementation of Mailbox
- */
-public class OpenJPAMessageManager extends StoreMessageManager {
+public class PostgresMessageManager extends StoreMessageManager {
+
private final MailboxSessionMapperFactory mapperFactory;
private final StoreRightManager storeRightManager;
private final Mailbox mailbox;
- public OpenJPAMessageManager(MailboxSessionMapperFactory mapperFactory,
- MessageSearchIndex index, EventBus eventBus,
- MailboxPathLocker locker, Mailbox mailbox,
- QuotaManager quotaManager, QuotaRootResolver quotaRootResolver,
- MessageId.Factory messageIdFactory, BatchSizes batchSizes,
- StoreRightManager storeRightManager, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm,
- Clock clock) {
+ public PostgresMessageManager(MailboxSessionMapperFactory mapperFactory,
+ MessageSearchIndex index, EventBus eventBus,
+ MailboxPathLocker locker, Mailbox mailbox,
+ QuotaManager quotaManager, QuotaRootResolver quotaRootResolver,
+ MessageId.Factory messageIdFactory, BatchSizes batchSizes,
+ StoreRightManager storeRightManager, ThreadIdGuessingAlgorithm threadIdGuessingAlgorithm,
+ Clock clock) {
super(StoreMailboxManager.DEFAULT_NO_MESSAGE_CAPABILITIES, mapperFactory, index, eventBus, locker, mailbox,
quotaManager, quotaRootResolver, batchSizes, storeRightManager, PreDeletionHooks.NO_PRE_DELETION_HOOK,
new MessageStorer.WithoutAttachment(mapperFactory, messageIdFactory, new MessageFactory.StoreMessageFactory(), threadIdGuessingAlgorithm, clock));
@@ -73,12 +71,10 @@ public class OpenJPAMessageManager extends StoreMessageManager {
this.mailbox = mailbox;
}
- /**
- * Support user flags
- */
+
@Override
public Flags getPermanentFlags(MailboxSession session) {
- Flags flags = super.getPermanentFlags(session);
+ Flags flags = super.getPermanentFlags(session);
flags.add(Flags.Flag.USER);
return flags;
}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxDAO.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxDAO.java
index 88ac6baee4..ac5279062e 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxDAO.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxDAO.java
@@ -20,7 +20,6 @@
package org.apache.james.mailbox.postgres.mail.dao;
import static org.apache.james.backends.postgres.utils.PostgresUtils.UNIQUE_CONSTRAINT_VIOLATION_PREDICATE;
-import static org.apache.james.mailbox.postgres.PostgresMailboxIdFaker.getMailboxId;
import static org.apache.james.mailbox.postgres.mail.PostgresMailboxModule.PostgresMailboxTable.MAILBOX_ACL;
import static org.apache.james.mailbox.postgres.mail.PostgresMailboxModule.PostgresMailboxTable.MAILBOX_HIGHEST_MODSEQ;
import static org.apache.james.mailbox.postgres.mail.PostgresMailboxModule.PostgresMailboxTable.MAILBOX_ID;
@@ -36,6 +35,7 @@ import static org.jooq.impl.DSL.count;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
+import java.util.UUID;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -200,6 +200,10 @@ public class PostgresMailboxDAO {
.map(this::asMailbox);
}
+ private UUID asUUID(MailboxId mailboxId) {
+ return ((PostgresMailboxId)mailboxId).asUuid();
+ }
+
private Mailbox asMailbox(Record record) {
Mailbox mailbox = new Mailbox(new MailboxPath(record.get(MAILBOX_NAMESPACE), Username.of(record.get(USER_NAME)), record.get(MAILBOX_NAME)),
UidValidity.of(record.get(MAILBOX_UID_VALIDITY)), PostgresMailboxId.of(record.get(MAILBOX_ID)));
@@ -210,7 +214,7 @@ public class PostgresMailboxDAO {
public Mono<MessageUid> findLastUidByMailboxId(MailboxId mailboxId) {
return postgresExecutor.executeRow(dsl -> Mono.from(dsl.select(MAILBOX_LAST_UID)
.from(TABLE_NAME)
- .where(MAILBOX_ID.eq(getMailboxId(mailboxId).asUuid()))))
+ .where(MAILBOX_ID.eq(asUUID(mailboxId)))))
.flatMap(record -> Mono.justOrEmpty(record.get(MAILBOX_LAST_UID)))
.map(MessageUid::of);
}
@@ -218,7 +222,7 @@ public class PostgresMailboxDAO {
public Mono<MessageUid> incrementAndGetLastUid(MailboxId mailboxId, int count) {
return postgresExecutor.executeRow(dsl -> Mono.from(dsl.update(TABLE_NAME)
.set(MAILBOX_LAST_UID, coalesce(MAILBOX_LAST_UID, 0L).add(count))
- .where(MAILBOX_ID.eq(getMailboxId(mailboxId).asUuid()))
+ .where(MAILBOX_ID.eq(asUUID(mailboxId)))
.returning(MAILBOX_LAST_UID)))
.map(record -> record.get(MAILBOX_LAST_UID))
.map(MessageUid::of);
@@ -228,7 +232,7 @@ public class PostgresMailboxDAO {
public Mono<ModSeq> findHighestModSeqByMailboxId(MailboxId mailboxId) {
return postgresExecutor.executeRow(dsl -> Mono.from(dsl.select(MAILBOX_HIGHEST_MODSEQ)
.from(TABLE_NAME)
- .where(MAILBOX_ID.eq(getMailboxId(mailboxId).asUuid()))))
+ .where(MAILBOX_ID.eq(asUUID(mailboxId)))))
.flatMap(record -> Mono.justOrEmpty(record.get(MAILBOX_HIGHEST_MODSEQ)))
.map(ModSeq::of);
}
@@ -236,7 +240,7 @@ public class PostgresMailboxDAO {
public Mono<ModSeq> incrementAndGetModSeq(MailboxId mailboxId) {
return postgresExecutor.executeRow(dsl -> Mono.from(dsl.update(TABLE_NAME)
.set(MAILBOX_HIGHEST_MODSEQ, coalesce(MAILBOX_HIGHEST_MODSEQ, 0L).add(1))
- .where(MAILBOX_ID.eq(getMailboxId(mailboxId).asUuid()))
+ .where(MAILBOX_ID.eq(asUUID(mailboxId)))
.returning(MAILBOX_HIGHEST_MODSEQ)))
.map(record -> record.get(MAILBOX_HIGHEST_MODSEQ))
.map(ModSeq::of);
@@ -247,7 +251,7 @@ public class PostgresMailboxDAO {
return postgresExecutor.executeRow(dsl -> Mono.from(dsl.update(TABLE_NAME)
.set(MAILBOX_LAST_UID, coalesce(MAILBOX_LAST_UID, 0L).add(increment))
.set(MAILBOX_HIGHEST_MODSEQ, coalesce(MAILBOX_HIGHEST_MODSEQ, 0L).add(increment))
- .where(MAILBOX_ID.eq(getMailboxId(mailboxId).asUuid()))
+ .where(MAILBOX_ID.eq(asUUID(mailboxId)))
.returning(MAILBOX_LAST_UID, MAILBOX_HIGHEST_MODSEQ)))
.map(record -> Pair.of(MessageUid.of(record.get(MAILBOX_LAST_UID)), ModSeq.of(record.get(MAILBOX_HIGHEST_MODSEQ))));
}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAAttachment.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAAttachment.java
deleted file mode 100644
index d45005fce5..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAAttachment.java
+++ /dev/null
@@ -1,193 +0,0 @@
-/***************************************************************
- * 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.postgres.mail.model;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.Objects;
-import java.util.Optional;
-
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Lob;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
-
-import org.apache.james.mailbox.model.AttachmentId;
-import org.apache.james.mailbox.model.AttachmentMetadata;
-import org.apache.james.mailbox.model.Cid;
-import org.apache.james.mailbox.model.MessageAttachmentMetadata;
-import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
-
-@Entity(name = "Attachment")
-@Table(name = "JAMES_ATTACHMENT")
-@NamedQuery(name = "findAttachmentById", query = "SELECT attachment FROM Attachment attachment WHERE attachment.attachmentId = :idParam")
-public class JPAAttachment {
-
- private static final String TOSTRING_SEPARATOR = " ";
- private static final byte[] EMPTY_ARRAY = new byte[]{};
-
- @Id
- @GeneratedValue
- @Column(name = "ATTACHMENT_ID", nullable = false)
- private String attachmentId;
-
- @Basic(optional = false)
- @Column(name = "TYPE", nullable = false)
- private String type;
-
- @Basic(optional = false)
- @Column(name = "SIZE", nullable = false)
- private long size;
-
- @Basic(optional = false, fetch = FetchType.LAZY)
- @Column(name = "CONTENT", length = 1048576000, nullable = false)
- @Lob
- private byte[] content;
-
- @Basic(optional = true)
- @Column(name = "NAME")
- private String name;
-
- @Basic(optional = true)
- @Column(name = "CID")
- private String cid;
-
- @Basic(optional = false)
- @Column(name = "INLINE", nullable = false)
- private boolean isInline;
-
- public JPAAttachment() {
- }
-
- public JPAAttachment(MessageAttachmentMetadata messageAttachmentMetadata, byte[] bytes) {
- setMetadata(messageAttachmentMetadata, bytes);
- }
-
- public JPAAttachment(MessageAttachmentMetadata messageAttachmentMetadata) {
- setMetadata(messageAttachmentMetadata, new byte[0]);
- }
-
- private void setMetadata(MessageAttachmentMetadata messageAttachmentMetadata, byte[] bytes) {
- this.name = messageAttachmentMetadata.getName().orElse(null);
- messageAttachmentMetadata.getCid()
- .ifPresentOrElse(c -> this.cid = c.getValue(), () -> this.cid = "");
- this.type = messageAttachmentMetadata.getAttachment().getType().asString();
- this.size = messageAttachmentMetadata.getAttachment().getSize();
- this.isInline = messageAttachmentMetadata.isInline();
- this.content = bytes;
- }
-
- public AttachmentMetadata toAttachmentMetadata() {
- return AttachmentMetadata.builder()
- .attachmentId(AttachmentId.from(attachmentId))
- .messageId(new DefaultMessageId())
- .type(type)
- .size(size)
- .build();
- }
-
- public MessageAttachmentMetadata toMessageAttachmentMetadata() {
- return MessageAttachmentMetadata.builder()
- .attachment(toAttachmentMetadata())
- .name(Optional.ofNullable(name))
- .cid(Optional.of(Cid.from(cid)))
- .isInline(isInline)
- .build();
- }
-
- public String getAttachmentId() {
- return attachmentId;
- }
-
- public String getType() {
- return type;
- }
-
- public long getSize() {
- return size;
- }
-
- public String getName() {
- return name;
- }
-
- public boolean isInline() {
- return isInline;
- }
-
- public String getCid() {
- return cid;
- }
-
- public InputStream getContent() {
- return new ByteArrayInputStream(Objects.requireNonNullElse(content, EMPTY_ARRAY));
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public void setSize(long size) {
- this.size = size;
- }
-
- public void setContent(byte[] bytes) {
- this.content = bytes;
- }
-
- @Override
- public String toString() {
- return "Attachment ( "
- + "attachmentId = " + this.attachmentId + TOSTRING_SEPARATOR
- + "name = " + this.type + TOSTRING_SEPARATOR
- + "type = " + this.type + TOSTRING_SEPARATOR
- + "size = " + this.size + TOSTRING_SEPARATOR
- + "cid = " + this.cid + TOSTRING_SEPARATOR
- + "isInline = " + this.isInline + TOSTRING_SEPARATOR
- + " )";
- }
-
- @Override
- public final boolean equals(Object o) {
- if (o instanceof JPAAttachment) {
- JPAAttachment that = (JPAAttachment) o;
-
- return Objects.equals(this.size, that.size)
- && Objects.equals(this.attachmentId, that.attachmentId)
- && Objects.equals(this.cid, that.cid)
- && Arrays.equals(this.content, that.content)
- && Objects.equals(this.isInline, that.isInline)
- && Objects.equals(this.name, that.name)
- && Objects.equals(this.type, that.type);
- }
- return false;
- }
-
- @Override
- public final int hashCode() {
- return Objects.hash(attachmentId, type, size, name, cid, isInline);
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAMailbox.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAMailbox.java
deleted file mode 100644
index 9f0050f622..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAMailbox.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/****************************************************************
- * 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.postgres.mail.model;
-
-import java.util.Objects;
-
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
-
-import org.apache.james.core.Username;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.UidValidity;
-import org.apache.james.mailbox.postgres.JPAId;
-
-import com.google.common.annotations.VisibleForTesting;
-
-@Entity(name = "Mailbox")
-@Table(name = "JAMES_MAILBOX")
-@NamedQueries({
- @NamedQuery(name = "findMailboxById",
- query = "SELECT mailbox FROM Mailbox mailbox WHERE mailbox.mailboxId = :idParam"),
- @NamedQuery(name = "findMailboxByName",
- query = "SELECT mailbox FROM Mailbox mailbox WHERE mailbox.name = :nameParam and mailbox.user is NULL and mailbox.namespace= :namespaceParam"),
- @NamedQuery(name = "findMailboxByNameWithUser",
- query = "SELECT mailbox FROM Mailbox mailbox WHERE mailbox.name = :nameParam and mailbox.user= :userParam and mailbox.namespace= :namespaceParam"),
- @NamedQuery(name = "findMailboxWithNameLikeWithUser",
- query = "SELECT mailbox FROM Mailbox mailbox WHERE mailbox.name LIKE :nameParam and mailbox.user= :userParam and mailbox.namespace= :namespaceParam"),
- @NamedQuery(name = "findMailboxWithNameLike",
- query = "SELECT mailbox FROM Mailbox mailbox WHERE mailbox.name LIKE :nameParam and mailbox.user is NULL and mailbox.namespace= :namespaceParam"),
- @NamedQuery(name = "countMailboxesWithNameLikeWithUser",
- query = "SELECT COUNT(mailbox) FROM Mailbox mailbox WHERE mailbox.name LIKE :nameParam and mailbox.user= :userParam and mailbox.namespace= :namespaceParam"),
- @NamedQuery(name = "countMailboxesWithNameLike",
- query = "SELECT COUNT(mailbox) FROM Mailbox mailbox WHERE mailbox.name LIKE :nameParam and mailbox.user is NULL and mailbox.namespace= :namespaceParam"),
- @NamedQuery(name = "listMailboxes",
- query = "SELECT mailbox FROM Mailbox mailbox"),
- @NamedQuery(name = "findHighestModSeq",
- query = "SELECT mailbox.highestModSeq FROM Mailbox mailbox WHERE mailbox.mailboxId = :idParam"),
- @NamedQuery(name = "findLastUid",
- query = "SELECT mailbox.lastUid FROM Mailbox mailbox WHERE mailbox.mailboxId = :idParam")
-})
-public class JPAMailbox {
-
- private static final String TAB = " ";
-
- public static JPAMailbox from(Mailbox mailbox) {
- return new JPAMailbox(mailbox);
- }
-
- /** The value for the mailboxId field */
- @Id
- @GeneratedValue
- @Column(name = "MAILBOX_ID")
- private long mailboxId;
-
- /** The value for the name field */
- @Basic(optional = false)
- @Column(name = "MAILBOX_NAME", nullable = false, length = 200)
- private String name;
-
- /** The value for the uidValidity field */
- @Basic(optional = false)
- @Column(name = "MAILBOX_UID_VALIDITY", nullable = false)
- private long uidValidity;
-
- @Basic(optional = true)
- @Column(name = "USER_NAME", nullable = true, length = 200)
- private String user;
-
- @Basic(optional = false)
- @Column(name = "MAILBOX_NAMESPACE", nullable = false, length = 200)
- private String namespace;
-
- @Basic(optional = false)
- @Column(name = "MAILBOX_LAST_UID", nullable = true)
- private long lastUid;
-
- @Basic(optional = false)
- @Column(name = "MAILBOX_HIGHEST_MODSEQ", nullable = true)
- private long highestModSeq;
-
- /**
- * JPA only
- */
- @Deprecated
- public JPAMailbox() {
- }
-
- public JPAMailbox(MailboxPath path, UidValidity uidValidity) {
- this(path, uidValidity.asLong());
- }
-
- @VisibleForTesting
- public JPAMailbox(MailboxPath path, long uidValidity) {
- this.name = path.getName();
- this.user = path.getUser().asString();
- this.namespace = path.getNamespace();
- this.uidValidity = uidValidity;
- }
-
- public JPAMailbox(Mailbox mailbox) {
- this(mailbox.generateAssociatedPath(), mailbox.getUidValidity());
- }
-
- public JPAId getMailboxId() {
- return JPAId.of(mailboxId);
- }
-
- public long consumeUid() {
- return ++lastUid;
- }
-
- public long consumeModSeq() {
- return ++highestModSeq;
- }
-
- public Mailbox toMailbox() {
- MailboxPath path = new MailboxPath(namespace, Username.of(user), name);
- return new Mailbox(path, sanitizeUidValidity(), new JPAId(mailboxId));
- }
-
- private UidValidity sanitizeUidValidity() {
- if (UidValidity.isValid(uidValidity)) {
- return UidValidity.of(uidValidity);
- }
- UidValidity sanitizedUidValidity = UidValidity.generate();
- // Update storage layer thanks to JPA magics!
- setUidValidity(sanitizedUidValidity.asLong());
- return sanitizedUidValidity;
- }
-
- public void setMailboxId(long mailboxId) {
- this.mailboxId = mailboxId;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getUser() {
- return user;
- }
-
- public void setUser(String user) {
- this.user = user;
- }
-
- public void setNamespace(String namespace) {
- this.namespace = namespace;
- }
-
- public void setUidValidity(long uidValidity) {
- this.uidValidity = uidValidity;
- }
-
- @Override
- public String toString() {
- return "Mailbox ( "
- + "mailboxId = " + this.mailboxId + TAB
- + "name = " + this.name + TAB
- + "uidValidity = " + this.uidValidity + TAB
- + " )";
- }
-
- @Override
- public final boolean equals(Object o) {
- if (o instanceof JPAMailbox) {
- JPAMailbox that = (JPAMailbox) o;
-
- return Objects.equals(this.mailboxId, that.mailboxId);
- }
- return false;
- }
-
- @Override
- public final int hashCode() {
- return Objects.hash(mailboxId);
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAMailboxAnnotation.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAMailboxAnnotation.java
deleted file mode 100644
index d28080212c..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAMailboxAnnotation.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************
- * 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.postgres.mail.model;
-
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.IdClass;
-import javax.persistence.NamedQueries;
-import javax.persistence.NamedQuery;
-import javax.persistence.Table;
-
-import com.google.common.base.Objects;
-
-@Entity(name = "MailboxAnnotation")
-@Table(name = "JAMES_MAILBOX_ANNOTATION")
-@NamedQueries({
- @NamedQuery(name = "retrieveAllAnnotations", query = "SELECT annotation FROM MailboxAnnotation annotation WHERE annotation.mailboxId = :idParam"),
- @NamedQuery(name = "retrieveByKey", query = "SELECT annotation FROM MailboxAnnotation annotation WHERE annotation.mailboxId = :idParam AND annotation.key = :keyParam"),
- @NamedQuery(name = "countAnnotationsInMailbox", query = "SELECT COUNT(annotation) FROM MailboxAnnotation annotation WHERE annotation.mailboxId = :idParam"),
- @NamedQuery(name = "retrieveByKeyLike", query = "SELECT annotation FROM MailboxAnnotation annotation WHERE annotation.mailboxId = :idParam AND annotation.key LIKE :keyParam")})
-@IdClass(JPAMailboxAnnotationId.class)
-public class JPAMailboxAnnotation {
-
- public static final String MAILBOX_ID = "MAILBOX_ID";
- public static final String ANNOTATION_KEY = "ANNOTATION_KEY";
- public static final String VALUE = "VALUE";
-
- @Id
- @Column(name = MAILBOX_ID)
- private long mailboxId;
-
- @Id
- @Column(name = ANNOTATION_KEY, length = 200)
- private String key;
-
- @Basic()
- @Column(name = VALUE)
- private String value;
-
- public JPAMailboxAnnotation() {
- }
-
- public JPAMailboxAnnotation(long mailboxId, String key, String value) {
- this.mailboxId = mailboxId;
- this.key = key;
- this.value = value;
- }
-
- public long getMailboxId() {
- return mailboxId;
- }
-
- public String getKey() {
- return key;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof JPAMailboxAnnotation) {
- JPAMailboxAnnotation that = (JPAMailboxAnnotation) o;
- return Objects.equal(this.mailboxId, that.mailboxId)
- && Objects.equal(this.key, that.key)
- && Objects.equal(this.value, that.value);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(mailboxId, key, value);
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAMailboxAnnotationId.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAMailboxAnnotationId.java
deleted file mode 100644
index 36e5afbb68..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAMailboxAnnotationId.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/****************************************************************
- * 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.postgres.mail.model;
-
-import java.io.Serializable;
-
-import javax.persistence.Embeddable;
-
-import com.google.common.base.Objects;
-
-@Embeddable
-public final class JPAMailboxAnnotationId implements Serializable {
- private long mailboxId;
- private String key;
-
- public JPAMailboxAnnotationId(long mailboxId, String key) {
- this.mailboxId = mailboxId;
- this.key = key;
- }
-
- public JPAMailboxAnnotationId() {
- }
-
- public long getMailboxId() {
- return mailboxId;
- }
-
- public String getKey() {
- return key;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof JPAMailboxAnnotationId) {
- JPAMailboxAnnotationId that = (JPAMailboxAnnotationId) o;
- return Objects.equal(this.mailboxId, that.mailboxId) && Objects.equal(this.key, that.key);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(mailboxId, key);
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAProperty.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAProperty.java
deleted file mode 100644
index 4724aea04d..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAProperty.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/****************************************************************
- * 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.postgres.mail.model;
-
-import java.util.Objects;
-
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-import org.apache.james.mailbox.store.mail.model.Property;
-import org.apache.openjpa.persistence.jdbc.Index;
-
-@Entity(name = "Property")
-@Table(name = "JAMES_MAIL_PROPERTY")
-public class JPAProperty {
-
- /** The system unique key */
- @Id
- @GeneratedValue
- @Column(name = "PROPERTY_ID", nullable = true)
- private long id;
-
- /** Order within the list of properties */
- @Basic(optional = false)
- @Column(name = "PROPERTY_LINE_NUMBER", nullable = false)
- @Index(name = "INDEX_PROPERTY_LINE_NUMBER")
- private int line;
-
- /** Local part of the name of this property */
- @Basic(optional = false)
- @Column(name = "PROPERTY_LOCAL_NAME", nullable = false, length = 500)
- private String localName;
-
- /** Namespace part of the name of this property */
- @Basic(optional = false)
- @Column(name = "PROPERTY_NAME_SPACE", nullable = false, length = 500)
- private String namespace;
-
- /** Value of this property */
- @Basic(optional = false)
- @Column(name = "PROPERTY_VALUE", nullable = false, length = 1024)
- private String value;
-
- /**
- * @deprecated enhancement only
- */
- @Deprecated
- public JPAProperty() {
- }
-
- /**
- * Constructs a property.
- *
- * @param localName
- * not null
- * @param namespace
- * not null
- * @param value
- * not null
- */
- public JPAProperty(String namespace, String localName, String value, int order) {
- super();
- this.localName = localName;
- this.namespace = namespace;
- this.value = value;
- this.line = order;
- }
-
- /**
- * Constructs a property cloned from the given.
- *
- * @param property
- * not null
- */
- public JPAProperty(Property property, int order) {
- this(property.getNamespace(), property.getLocalName(), property.getValue(), order);
- }
-
- public Property toProperty() {
- return new Property(namespace, localName, value);
- }
-
- @Override
- public final boolean equals(Object o) {
- if (o instanceof JPAProperty) {
- JPAProperty that = (JPAProperty) o;
-
- return Objects.equals(this.id, that.id);
- }
- return false;
- }
-
- @Override
- public final int hashCode() {
- return Objects.hash(id);
- }
-
- /**
- * Constructs a <code>String</code> with all attributes in name = value
- * format.
- *
- * @return a <code>String</code> representation of this object.
- */
- public String toString() {
- return "JPAProperty ( " + "id = " + this.id + " " + "localName = " + this.localName + " "
- + "namespace = " + this.namespace + " " + "value = " + this.value + " )";
- }
-
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAUserFlag.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAUserFlag.java
deleted file mode 100644
index 3e1736d79d..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/JPAUserFlag.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/****************************************************************
- * 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.postgres.mail.model;
-
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-@Entity(name = "UserFlag")
-@Table(name = "JAMES_MAIL_USERFLAG")
-public class JPAUserFlag {
-
-
- /** The system unique key */
- @Id
- @GeneratedValue
- @Column(name = "USERFLAG_ID", nullable = true)
- private long id;
-
- /** Local part of the name of this property */
- @Basic(optional = false)
- @Column(name = "USERFLAG_NAME", nullable = false, length = 500)
- private String name;
-
-
- /**
- * @deprecated enhancement only
- */
- @Deprecated
- public JPAUserFlag() {
-
- }
-
- /**
- * Constructs a User Flag.
- * @param name not null
- */
- public JPAUserFlag(String name) {
- super();
- this.name = name;
- }
-
- /**
- * Constructs a User Flag, cloned from the given.
- * @param flag not null
- */
- public JPAUserFlag(JPAUserFlag flag) {
- this(flag.getName());
- }
-
-
-
- /**
- * Gets the name.
- * @return not null
- */
- public String getName() {
- return name;
- }
-
- @Override
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + (int) (id ^ (id >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final JPAUserFlag other = (JPAUserFlag) obj;
- if (id != other.id) {
- return false;
- }
- return true;
- }
-
- /**
- * Constructs a <code>String</code> with all attributes
- * in name = value format.
- *
- * @return a <code>String</code> representation
- * of this object.
- */
- public String toString() {
- return "JPAUserFlag ( "
- + "id = " + this.id + " "
- + "name = " + this.name
- + " )";
- }
-
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/AbstractJPAMailboxMessage.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/AbstractJPAMailboxMessage.java
deleted file mode 100644
index 040bf06476..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/AbstractJPAMailboxMessage.java
+++ /dev/null
@@ -1,579 +0,0 @@
-/****************************************************************
- * 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.postgres.mail.model.openjpa;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.SequenceInputStream;
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.mail.Flags;
-import javax.persistence.Basic;
-import javax.persistence.CascadeType;
-import javax.persistence.Column;
-import javax.persistence.Embeddable;
-import javax.persistence.FetchType;
-import javax.persistence.Id;
-import javax.persistence.IdClass;
-import javax.persistence.ManyToOne;
-import javax.persistence.MappedSuperclass;
-import javax.persistence.NamedQuery;
-import javax.persistence.OneToMany;
-import javax.persistence.OrderBy;
-
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.ModSeq;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.AttachmentId;
-import org.apache.james.mailbox.model.ComposedMessageId;
-import org.apache.james.mailbox.model.ComposedMessageIdWithMetaData;
-import org.apache.james.mailbox.model.MessageAttachmentMetadata;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.ParsedAttachment;
-import org.apache.james.mailbox.model.ThreadId;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailbox;
-import org.apache.james.mailbox.postgres.mail.model.JPAProperty;
-import org.apache.james.mailbox.postgres.mail.model.JPAUserFlag;
-import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
-import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
-import org.apache.james.mailbox.store.mail.model.FlagsFactory;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.Property;
-import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
-import org.apache.james.mailbox.store.mail.model.impl.Properties;
-import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
-import org.apache.openjpa.persistence.jdbc.ElementJoinColumn;
-import org.apache.openjpa.persistence.jdbc.ElementJoinColumns;
-import org.apache.openjpa.persistence.jdbc.Index;
-
-import com.github.fge.lambdas.Throwing;
-import com.google.common.base.Objects;
-import com.google.common.collect.ImmutableList;
-
-/**
- * Abstract base class for JPA based implementations of
- * {@link DelegatingMailboxMessage}
- */
-@IdClass(AbstractJPAMailboxMessage.MailboxIdUidKey.class)
-@NamedQuery(name = "findRecentMessageUidsInMailbox", query = "SELECT message.uid FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.recent = TRUE ORDER BY message.uid ASC")
-@NamedQuery(name = "listUidsInMailbox", query = "SELECT message.uid FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam ORDER BY message.uid ASC")
-@NamedQuery(name = "findUnseenMessagesInMailboxOrderByUid", query = "SELECT message FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.seen = FALSE ORDER BY message.uid ASC")
-@NamedQuery(name = "findMessagesInMailbox", query = "SELECT message FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam ORDER BY message.uid ASC")
-@NamedQuery(name = "findMessagesInMailboxBetweenUIDs", query = "SELECT message FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.uid BETWEEN :fromParam AND :toParam ORDER BY message.uid ASC")
-@NamedQuery(name = "findMessagesInMailboxWithUID", query = "SELECT message FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.uid=:uidParam ORDER BY message.uid ASC")
-@NamedQuery(name = "findMessagesInMailboxAfterUID", query = "SELECT message FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.uid>=:uidParam ORDER BY message.uid ASC")
-@NamedQuery(name = "findDeletedMessagesInMailbox", query = "SELECT message FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.deleted=TRUE ORDER BY message.uid ASC")
-@NamedQuery(name = "findDeletedMessagesInMailboxBetweenUIDs", query = "SELECT message FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.uid BETWEEN :fromParam AND :toParam AND message.deleted=TRUE ORDER BY message.uid ASC")
-@NamedQuery(name = "findDeletedMessagesInMailboxWithUID", query = "SELECT message FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.uid=:uidParam AND message.deleted=TRUE ORDER BY message.uid ASC")
-@NamedQuery(name = "findDeletedMessagesInMailboxAfterUID", query = "SELECT message FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.uid>=:uidParam AND message.deleted=TRUE ORDER BY message.uid ASC")
-
-@NamedQuery(name = "deleteMessagesInMailbox", query = "DELETE FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam")
-@NamedQuery(name = "deleteMessagesInMailboxBetweenUIDs", query = "DELETE FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.uid BETWEEN :fromParam AND :toParam")
-@NamedQuery(name = "deleteMessagesInMailboxWithUID", query = "DELETE FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.uid=:uidParam")
-@NamedQuery(name = "deleteMessagesInMailboxAfterUID", query = "DELETE FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.uid>=:uidParam")
-
-@NamedQuery(name = "countUnseenMessagesInMailbox", query = "SELECT COUNT(message) FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam AND message.seen=FALSE")
-@NamedQuery(name = "countMessagesInMailbox", query = "SELECT COUNT(message) FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam")
-@NamedQuery(name = "deleteMessages", query = "DELETE FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam")
-@NamedQuery(name = "findLastUidInMailbox", query = "SELECT message.uid FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam ORDER BY message.uid DESC")
-@NamedQuery(name = "findHighestModSeqInMailbox", query = "SELECT message.modSeq FROM MailboxMessage message WHERE message.mailbox.mailboxId = :idParam ORDER BY message.modSeq DESC")
-@MappedSuperclass
-public abstract class AbstractJPAMailboxMessage implements MailboxMessage {
- private static final String TOSTRING_SEPARATOR = " ";
-
- /**
- * Identifies composite key
- */
- @Embeddable
- public static class MailboxIdUidKey implements Serializable {
-
- private static final long serialVersionUID = 7847632032426660997L;
-
- public MailboxIdUidKey() {
- }
-
- /**
- * The value for the mailbox field
- */
- public long mailbox;
-
- /**
- * The value for the uid field
- */
- public long uid;
-
- @Override
- public int hashCode() {
- final int PRIME = 31;
- int result = 1;
- result = PRIME * result + (int) (mailbox ^ (mailbox >>> 32));
- result = PRIME * result + (int) (uid ^ (uid >>> 32));
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final MailboxIdUidKey other = (MailboxIdUidKey) obj;
- if (mailbox != other.mailbox) {
- return false;
- }
- return uid == other.uid;
- }
-
- }
-
- /**
- * The value for the mailboxId field
- */
- @Id
- @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE}, fetch = FetchType.EAGER)
- @Column(name = "MAILBOX_ID", nullable = true)
- private JPAMailbox mailbox;
-
- /**
- * The value for the uid field
- */
- @Id
- @Column(name = "MAIL_UID")
- private long uid;
-
- /**
- * The value for the modSeq field
- */
- @Index
- @Column(name = "MAIL_MODSEQ")
- private long modSeq;
-
- /**
- * The value for the internalDate field
- */
- @Basic(optional = false)
- @Column(name = "MAIL_DATE")
- private Date internalDate;
-
- /**
- * The value for the answered field
- */
- @Basic(optional = false)
- @Column(name = "MAIL_IS_ANSWERED", nullable = false)
- private boolean answered = false;
-
- /**
- * The value for the deleted field
- */
- @Basic(optional = false)
- @Column(name = "MAIL_IS_DELETED", nullable = false)
- @Index
- private boolean deleted = false;
-
- /**
- * The value for the draft field
- */
- @Basic(optional = false)
- @Column(name = "MAIL_IS_DRAFT", nullable = false)
- private boolean draft = false;
-
- /**
- * The value for the flagged field
- */
- @Basic(optional = false)
- @Column(name = "MAIL_IS_FLAGGED", nullable = false)
- private boolean flagged = false;
-
- /**
- * The value for the recent field
- */
- @Basic(optional = false)
- @Column(name = "MAIL_IS_RECENT", nullable = false)
- @Index
- private boolean recent = false;
-
- /**
- * The value for the seen field
- */
- @Basic(optional = false)
- @Column(name = "MAIL_IS_SEEN", nullable = false)
- @Index
- private boolean seen = false;
-
- /**
- * The first body octet
- */
- @Basic(optional = false)
- @Column(name = "MAIL_BODY_START_OCTET", nullable = false)
- private int bodyStartOctet;
-
- /**
- * Number of octets in the full document content
- */
- @Basic(optional = false)
- @Column(name = "MAIL_CONTENT_OCTETS_COUNT", nullable = false)
- private long contentOctets;
-
- /**
- * MIME media type
- */
- @Basic(optional = true)
- @Column(name = "MAIL_MIME_TYPE", nullable = true, length = 200)
- private String mediaType;
-
- /**
- * MIME subtype
- */
- @Basic(optional = true)
- @Column(name = "MAIL_MIME_SUBTYPE", nullable = true, length = 200)
- private String subType;
-
- /**
- * THE CRFL count when this document is textual, null otherwise
- */
- @Basic(optional = true)
- @Column(name = "MAIL_TEXTUAL_LINE_COUNT", nullable = true)
- private Long textualLineCount;
-
- /**
- * Metadata for this message
- */
- @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
- @OrderBy("line")
- @ElementJoinColumns({@ElementJoinColumn(name = "MAILBOX_ID", referencedColumnName = "MAILBOX_ID"),
- @ElementJoinColumn(name = "MAIL_UID", referencedColumnName = "MAIL_UID")})
- private List<JPAProperty> properties;
-
- @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, orphanRemoval = true)
- @OrderBy("id")
- @ElementJoinColumns({@ElementJoinColumn(name = "MAILBOX_ID", referencedColumnName = "MAILBOX_ID"),
- @ElementJoinColumn(name = "MAIL_UID", referencedColumnName = "MAIL_UID")})
- private List<JPAUserFlag> userFlags;
-
-
- protected AbstractJPAMailboxMessage() {
- }
-
- protected AbstractJPAMailboxMessage(JPAMailbox mailbox, Date internalDate, Flags flags, long contentOctets,
- int bodyStartOctet, PropertyBuilder propertyBuilder) {
- this.mailbox = mailbox;
- this.internalDate = internalDate;
- userFlags = new ArrayList<>();
-
- setFlags(flags);
- this.contentOctets = contentOctets;
- this.bodyStartOctet = bodyStartOctet;
- Properties properties = propertyBuilder.build();
- this.textualLineCount = properties.getTextualLineCount();
- this.mediaType = properties.getMediaType();
- this.subType = properties.getSubType();
- final List<Property> propertiesAsList = properties.toProperties();
- this.properties = new ArrayList<>(propertiesAsList.size());
- int order = 0;
- for (Property property : propertiesAsList) {
- this.properties.add(new JPAProperty(property, order++));
- }
-
- }
-
- /**
- * Constructs a copy of the given message. All properties are cloned except
- * mailbox and UID.
- *
- * @param mailbox new mailbox
- * @param uid new UID
- * @param modSeq new modSeq
- * @param original message to be copied, not null
- */
- protected AbstractJPAMailboxMessage(JPAMailbox mailbox, MessageUid uid, ModSeq modSeq, MailboxMessage original)
- throws MailboxException {
- super();
- this.mailbox = mailbox;
- this.uid = uid.asLong();
- this.modSeq = modSeq.asLong();
- this.userFlags = new ArrayList<>();
- setFlags(original.createFlags());
-
- // A copy of a message is recent
- // See MAILBOX-85
- this.recent = true;
-
- this.contentOctets = original.getFullContentOctets();
- this.bodyStartOctet = (int) (original.getFullContentOctets() - original.getBodyOctets());
- this.internalDate = original.getInternalDate();
-
- this.textualLineCount = original.getTextualLineCount();
- this.mediaType = original.getMediaType();
- this.subType = original.getSubType();
- final List<Property> properties = original.getProperties().toProperties();
- this.properties = new ArrayList<>(properties.size());
- int order = 0;
- for (Property property : properties) {
- this.properties.add(new JPAProperty(property, order++));
- }
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(getMailboxId().getRawId(), uid);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof AbstractJPAMailboxMessage) {
- AbstractJPAMailboxMessage other = (AbstractJPAMailboxMessage) obj;
- return Objects.equal(getMailboxId(), other.getMailboxId())
- && Objects.equal(uid, other.getUid());
- }
- return false;
- }
-
- @Override
- public ComposedMessageIdWithMetaData getComposedMessageIdWithMetaData() {
- return ComposedMessageIdWithMetaData.builder()
- .modSeq(getModSeq())
- .flags(createFlags())
- .composedMessageId(new ComposedMessageId(mailbox.getMailboxId(), getMessageId(), MessageUid.of(uid)))
- .threadId(getThreadId())
- .build();
- }
-
- @Override
- public ModSeq getModSeq() {
- return ModSeq.of(modSeq);
- }
-
- @Override
- public void setModSeq(ModSeq modSeq) {
- this.modSeq = modSeq.asLong();
- }
-
- @Override
- public String getMediaType() {
- return mediaType;
- }
-
- @Override
- public String getSubType() {
- return subType;
- }
-
- /**
- * Gets a read-only list of meta-data properties. For properties with
- * multiple values, this list will contain several enteries with the same
- * namespace and local name.
- *
- * @return unmodifiable list of meta-data, not null
- */
- @Override
- public Properties getProperties() {
- return new PropertyBuilder(properties.stream()
- .map(JPAProperty::toProperty)
- .collect(ImmutableList.toImmutableList()))
- .build();
- }
-
- @Override
- public Long getTextualLineCount() {
- return textualLineCount;
- }
-
- @Override
- public long getFullContentOctets() {
- return contentOctets;
- }
-
- protected int getBodyStartOctet() {
- return bodyStartOctet;
- }
-
- @Override
- public Date getInternalDate() {
- return internalDate;
- }
-
- @Override
- public JPAId getMailboxId() {
- return getMailbox().getMailboxId();
- }
-
- @Override
- public MessageUid getUid() {
- return MessageUid.of(uid);
- }
-
- @Override
- public boolean isAnswered() {
- return answered;
- }
-
- @Override
- public boolean isDeleted() {
- return deleted;
- }
-
- @Override
- public boolean isDraft() {
- return draft;
- }
-
- @Override
- public boolean isFlagged() {
- return flagged;
- }
-
- @Override
- public boolean isRecent() {
- return recent;
- }
-
- @Override
- public boolean isSeen() {
- return seen;
- }
-
- @Override
- public void setUid(MessageUid uid) {
- this.uid = uid.asLong();
- }
-
- @Override
- public void setSaveDate(Date saveDate) {
-
- }
-
- @Override
- public long getHeaderOctets() {
- return bodyStartOctet;
- }
-
- @Override
- public void setFlags(Flags flags) {
- answered = flags.contains(Flags.Flag.ANSWERED);
- deleted = flags.contains(Flags.Flag.DELETED);
- draft = flags.contains(Flags.Flag.DRAFT);
- flagged = flags.contains(Flags.Flag.FLAGGED);
- recent = flags.contains(Flags.Flag.RECENT);
- seen = flags.contains(Flags.Flag.SEEN);
-
- String[] userflags = flags.getUserFlags();
- userFlags.clear();
- for (String userflag : userflags) {
- userFlags.add(new JPAUserFlag(userflag));
- }
- }
-
- /**
- * Utility getter on Mailbox.
- */
- public JPAMailbox getMailbox() {
- return mailbox;
- }
-
- @Override
- public Flags createFlags() {
- return FlagsFactory.createFlags(this, createUserFlags());
- }
-
- protected String[] createUserFlags() {
- return userFlags.stream()
- .map(JPAUserFlag::getName)
- .toArray(String[]::new);
- }
-
- /**
- * Utility setter on Mailbox.
- */
- public void setMailbox(JPAMailbox mailbox) {
- this.mailbox = mailbox;
- }
-
- @Override
- public InputStream getFullContent() throws IOException {
- return new SequenceInputStream(getHeaderContent(), getBodyContent());
- }
-
- @Override
- public long getBodyOctets() {
- return getFullContentOctets() - getBodyStartOctet();
- }
-
- @Override
- public MessageId getMessageId() {
- return new DefaultMessageId();
- }
-
- @Override
- public ThreadId getThreadId() {
- return new ThreadId(getMessageId());
- }
-
- @Override
- public Optional<Date> getSaveDate() {
- return Optional.empty();
- }
-
- public String toString() {
- return "message("
- + "mailboxId = " + this.getMailboxId() + TOSTRING_SEPARATOR
- + "uid = " + this.uid + TOSTRING_SEPARATOR
- + "internalDate = " + this.internalDate + TOSTRING_SEPARATOR
- + "answered = " + this.answered + TOSTRING_SEPARATOR
- + "deleted = " + this.deleted + TOSTRING_SEPARATOR
- + "draft = " + this.draft + TOSTRING_SEPARATOR
- + "flagged = " + this.flagged + TOSTRING_SEPARATOR
- + "recent = " + this.recent + TOSTRING_SEPARATOR
- + "seen = " + this.seen + TOSTRING_SEPARATOR
- + " )";
- }
-
- @Override
- public List<MessageAttachmentMetadata> getAttachments() {
- try {
- AtomicInteger counter = new AtomicInteger(0);
- MessageParser.ParsingResult parsingResult = new MessageParser().retrieveAttachments(getFullContent());
- ImmutableList<MessageAttachmentMetadata> result = parsingResult
- .getAttachments()
- .stream()
- .map(Throwing.<ParsedAttachment, MessageAttachmentMetadata>function(
- attachmentMetadata -> attachmentMetadata.asMessageAttachment(generateFixedAttachmentId(counter.incrementAndGet()), getMessageId()))
- .sneakyThrow())
- .collect(ImmutableList.toImmutableList());
- parsingResult.dispose();
- return result;
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- private AttachmentId generateFixedAttachmentId(int position) {
- return AttachmentId.from(getMailboxId().serialize() + "-" + getUid().asLong() + "-" + position);
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/JPAMailboxMessage.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/JPAMailboxMessage.java
deleted file mode 100644
index 41fa1949c5..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/model/openjpa/JPAMailboxMessage.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/****************************************************************
- * 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.postgres.mail.model.openjpa;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
-
-import javax.mail.Flags;
-import javax.persistence.Basic;
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.Lob;
-import javax.persistence.Table;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.input.BoundedInputStream;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.ModSeq;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.Content;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
-
-import com.google.common.annotations.VisibleForTesting;
-
-@Entity(name = "MailboxMessage")
-@Table(name = "JAMES_MAIL")
-public class JPAMailboxMessage extends AbstractJPAMailboxMessage {
-
- private static final byte[] EMPTY_ARRAY = new byte[] {};
-
- /** The value for the body field. Lazy loaded */
- /** We use a max length to represent 1gb data. Thats prolly overkill, but who knows */
- @Basic(optional = false, fetch = FetchType.LAZY)
- @Column(name = "MAIL_BYTES", length = 1048576000, nullable = false)
- @Lob private byte[] body;
-
-
- /** The value for the header field. Lazy loaded */
- /** We use a max length to represent 10mb data. Thats prolly overkill, but who knows */
- @Basic(optional = false, fetch = FetchType.LAZY)
- @Column(name = "HEADER_BYTES", length = 10485760, nullable = false)
- @Lob private byte[] header;
-
-
- public JPAMailboxMessage() {
-
- }
-
- @VisibleForTesting
- protected JPAMailboxMessage(byte[] header, byte[] body) {
- this.header = header;
- this.body = body;
- }
-
- public JPAMailboxMessage(JPAMailbox mailbox, Date internalDate, int size, Flags flags, Content content, int bodyStartOctet, PropertyBuilder propertyBuilder) throws MailboxException {
- super(mailbox, internalDate, flags, size, bodyStartOctet, propertyBuilder);
- try {
- int headerEnd = bodyStartOctet;
- if (headerEnd < 0) {
- headerEnd = 0;
- }
- InputStream stream = content.getInputStream();
- this.header = IOUtils.toByteArray(new BoundedInputStream(stream, headerEnd));
- this.body = IOUtils.toByteArray(stream);
-
- } catch (IOException e) {
- throw new MailboxException("Unable to parse message",e);
- }
- }
-
- /**
- * Create a copy of the given message
- */
- public JPAMailboxMessage(JPAMailbox mailbox, MessageUid uid, ModSeq modSeq, MailboxMessage message) throws MailboxException {
- super(mailbox, uid, modSeq, message);
- try {
- this.body = IOUtils.toByteArray(message.getBodyContent());
- this.header = IOUtils.toByteArray(message.getHeaderContent());
- } catch (IOException e) {
- throw new MailboxException("Unable to parse message",e);
- }
- }
-
- @Override
- public InputStream getBodyContent() throws IOException {
- if (body == null) {
- return new ByteArrayInputStream(EMPTY_ARRAY);
- }
- return new ByteArrayInputStream(body);
- }
-
- @Override
- public InputStream getHeaderContent() throws IOException {
- if (header == null) {
- return new ByteArrayInputStream(EMPTY_ARRAY);
- }
- return new ByteArrayInputStream(header);
- }
-
- @Override
- public MailboxMessage copy(Mailbox mailbox) throws MailboxException {
- return new JPAMailboxMessage(JPAMailbox.from(mailbox), getUid(), getModSeq(), this);
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/openjpa/OpenJPAMessageFactory.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/openjpa/OpenJPAMessageFactory.java
deleted file mode 100644
index 56027df0fb..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/openjpa/OpenJPAMessageFactory.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/****************************************************************
- * 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.postgres.openjpa;
-
-import java.util.Date;
-import java.util.List;
-
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.Content;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MessageAttachmentMetadata;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.ThreadId;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailbox;
-import org.apache.james.mailbox.postgres.mail.model.openjpa.AbstractJPAMailboxMessage;
-import org.apache.james.mailbox.postgres.mail.model.openjpa.JPAMailboxMessage;
-import org.apache.james.mailbox.store.MessageFactory;
-import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
-
-public class OpenJPAMessageFactory implements MessageFactory<AbstractJPAMailboxMessage> {
- private final AdvancedFeature feature;
-
- public OpenJPAMessageFactory(AdvancedFeature feature) {
- this.feature = feature;
- }
-
- public enum AdvancedFeature {
- None,
- Streaming,
- Encryption
- }
-
- @Override
- public AbstractJPAMailboxMessage createMessage(MessageId messageId, ThreadId threadId, Mailbox mailbox, Date internalDate, Date saveDate, int size, int bodyStartOctet, Content content, Flags flags, PropertyBuilder propertyBuilder, List<MessageAttachmentMetadata> attachments) throws MailboxException {
- return new JPAMailboxMessage(JPAMailbox.from(mailbox), internalDate, size, flags, content, bodyStartOctet, propertyBuilder);
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/JpaCurrentQuotaManager.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/JpaCurrentQuotaManager.java
deleted file mode 100644
index 626078d185..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/JpaCurrentQuotaManager.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/****************************************************************
- * 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.postgres.quota;
-
-import java.util.Optional;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-
-import org.apache.james.backends.jpa.EntityManagerUtils;
-import org.apache.james.backends.jpa.TransactionRunner;
-import org.apache.james.core.quota.QuotaCountUsage;
-import org.apache.james.core.quota.QuotaSizeUsage;
-import org.apache.james.mailbox.model.CurrentQuotas;
-import org.apache.james.mailbox.model.QuotaOperation;
-import org.apache.james.mailbox.model.QuotaRoot;
-import org.apache.james.mailbox.postgres.quota.model.JpaCurrentQuota;
-import org.apache.james.mailbox.quota.CurrentQuotaManager;
-
-import reactor.core.publisher.Mono;
-
-public class JpaCurrentQuotaManager implements CurrentQuotaManager {
-
- public static final long NO_MESSAGES = 0L;
- public static final long NO_STORED_BYTES = 0L;
-
- private final EntityManagerFactory entityManagerFactory;
- private final TransactionRunner transactionRunner;
-
- @Inject
- public JpaCurrentQuotaManager(EntityManagerFactory entityManagerFactory) {
- this.entityManagerFactory = entityManagerFactory;
- this.transactionRunner = new TransactionRunner(entityManagerFactory);
- }
-
- @Override
- public Mono<QuotaCountUsage> getCurrentMessageCount(QuotaRoot quotaRoot) {
- EntityManager entityManager = entityManagerFactory.createEntityManager();
-
- return Mono.fromCallable(() -> Optional.ofNullable(retrieveUserQuota(entityManager, quotaRoot))
- .map(JpaCurrentQuota::getMessageCount)
- .orElse(QuotaCountUsage.count(NO_STORED_BYTES)))
- .doFinally(any -> EntityManagerUtils.safelyClose(entityManager));
- }
-
- @Override
- public Mono<QuotaSizeUsage> getCurrentStorage(QuotaRoot quotaRoot) {
- EntityManager entityManager = entityManagerFactory.createEntityManager();
-
- return Mono.fromCallable(() -> Optional.ofNullable(retrieveUserQuota(entityManager, quotaRoot))
- .map(JpaCurrentQuota::getSize)
- .orElse(QuotaSizeUsage.size(NO_STORED_BYTES)))
- .doFinally(any -> EntityManagerUtils.safelyClose(entityManager));
- }
-
- public Mono<CurrentQuotas> getCurrentQuotas(QuotaRoot quotaRoot) {
- EntityManager entityManager = entityManagerFactory.createEntityManager();
- return Mono.fromCallable(() -> Optional.ofNullable(retrieveUserQuota(entityManager, quotaRoot))
- .map(jpaCurrentQuota -> new CurrentQuotas(jpaCurrentQuota.getMessageCount(), jpaCurrentQuota.getSize()))
- .orElse(CurrentQuotas.emptyQuotas()))
- .doFinally(any -> EntityManagerUtils.safelyClose(entityManager));
- }
-
- @Override
- public Mono<Void> increase(QuotaOperation quotaOperation) {
- return Mono.fromRunnable(() ->
- transactionRunner.run(
- entityManager -> {
- QuotaRoot quotaRoot = quotaOperation.quotaRoot();
-
- JpaCurrentQuota jpaCurrentQuota = Optional.ofNullable(retrieveUserQuota(entityManager, quotaRoot))
- .orElse(new JpaCurrentQuota(quotaRoot.getValue(), NO_MESSAGES, NO_STORED_BYTES));
-
- entityManager.merge(new JpaCurrentQuota(quotaRoot.getValue(),
- jpaCurrentQuota.getMessageCount().asLong() + quotaOperation.count().asLong(),
- jpaCurrentQuota.getSize().asLong() + quotaOperation.size().asLong()));
- }));
- }
-
- @Override
- public Mono<Void> decrease(QuotaOperation quotaOperation) {
- return Mono.fromRunnable(() ->
- transactionRunner.run(
- entityManager -> {
- QuotaRoot quotaRoot = quotaOperation.quotaRoot();
-
- JpaCurrentQuota jpaCurrentQuota = Optional.ofNullable(retrieveUserQuota(entityManager, quotaRoot))
- .orElse(new JpaCurrentQuota(quotaRoot.getValue(), NO_MESSAGES, NO_STORED_BYTES));
-
- entityManager.merge(new JpaCurrentQuota(quotaRoot.getValue(),
- jpaCurrentQuota.getMessageCount().asLong() - quotaOperation.count().asLong(),
- jpaCurrentQuota.getSize().asLong() - quotaOperation.size().asLong()));
- }));
- }
-
- @Override
- public Mono<Void> setCurrentQuotas(QuotaOperation quotaOperation) {
- return Mono.fromCallable(() -> getCurrentQuotas(quotaOperation.quotaRoot()))
- .flatMap(storedQuotas -> Mono.fromRunnable(() ->
- transactionRunner.run(
- entityManager -> {
- if (!storedQuotas.equals(CurrentQuotas.from(quotaOperation))) {
- entityManager.merge(new JpaCurrentQuota(quotaOperation.quotaRoot().getValue(),
- quotaOperation.count().asLong(),
- quotaOperation.size().asLong()));
- }
- })));
- }
-
- private JpaCurrentQuota retrieveUserQuota(EntityManager entityManager, QuotaRoot quotaRoot) {
- return entityManager.find(JpaCurrentQuota.class, quotaRoot.getValue());
- }
-}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/PostgresCurrentQuotaManager.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/PostgresCurrentQuotaManager.java
index 6e7a2ee33e..9e44f7ab92 100644
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/PostgresCurrentQuotaManager.java
+++ b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/PostgresCurrentQuotaManager.java
@@ -23,6 +23,8 @@ import java.util.List;
import java.util.Optional;
import java.util.function.Predicate;
+import javax.inject.Inject;
+
import org.apache.james.backends.postgres.quota.PostgresQuotaCurrentValueDAO;
import org.apache.james.core.quota.QuotaComponent;
import org.apache.james.core.quota.QuotaCountUsage;
@@ -40,6 +42,8 @@ public class PostgresCurrentQuotaManager implements CurrentQuotaManager {
private final PostgresQuotaCurrentValueDAO currentValueDao;
+ @Inject
+
public PostgresCurrentQuotaManager(PostgresQuotaCurrentValueDAO currentValueDao) {
this.currentValueDao = currentValueDao;
}
diff --git a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/model/JpaCurrentQuota.java b/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/model/JpaCurrentQuota.java
deleted file mode 100644
index d9648610c3..0000000000
--- a/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/quota/model/JpaCurrentQuota.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/****************************************************************
- * 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.postgres.quota.model;
-
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
-
-import org.apache.james.core.quota.QuotaCountUsage;
-import org.apache.james.core.quota.QuotaSizeUsage;
-
-@Entity(name = "CurrentQuota")
-@Table(name = "JAMES_QUOTA_CURRENTQUOTA")
-public class JpaCurrentQuota {
-
- @Id
- @Column(name = "CURRENTQUOTA_QUOTAROOT")
- private String quotaRoot;
-
- @Column(name = "CURRENTQUOTA_MESSAGECOUNT")
- private long messageCount;
-
- @Column(name = "CURRENTQUOTA_SIZE")
- private long size;
-
- public JpaCurrentQuota() {
- }
-
- public JpaCurrentQuota(String quotaRoot, long messageCount, long size) {
- this.quotaRoot = quotaRoot;
- this.messageCount = messageCount;
- this.size = size;
- }
-
- public QuotaCountUsage getMessageCount() {
- return QuotaCountUsage.count(messageCount);
- }
-
- public QuotaSizeUsage getSize() {
- return QuotaSizeUsage.size(size);
- }
-
- @Override
- public String toString() {
- return "JpaCurrentQuota{" +
- "quotaRoot='" + quotaRoot + '\'' +
- ", messageCount=" + messageCount +
- ", size=" + size +
- '}';
- }
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxFixture.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxFixture.java
index c254cc88d8..6c34d837d7 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxFixture.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxFixture.java
@@ -21,14 +21,6 @@ package org.apache.james.mailbox.postgres;
import java.util.List;
-import org.apache.james.mailbox.postgres.mail.model.JPAAttachment;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailbox;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailboxAnnotation;
-import org.apache.james.mailbox.postgres.mail.model.JPAProperty;
-import org.apache.james.mailbox.postgres.mail.model.JPAUserFlag;
-import org.apache.james.mailbox.postgres.mail.model.openjpa.AbstractJPAMailboxMessage;
-import org.apache.james.mailbox.postgres.mail.model.openjpa.JPAMailboxMessage;
-import org.apache.james.mailbox.postgres.quota.model.JpaCurrentQuota;
import org.apache.james.mailbox.postgres.quota.model.MaxDomainMessageCount;
import org.apache.james.mailbox.postgres.quota.model.MaxDomainStorage;
import org.apache.james.mailbox.postgres.quota.model.MaxGlobalMessageCount;
@@ -40,33 +32,13 @@ import com.google.common.collect.ImmutableList;
public interface JPAMailboxFixture {
- List<Class<?>> MAILBOX_PERSISTANCE_CLASSES = ImmutableList.of(
- JPAMailbox.class,
- AbstractJPAMailboxMessage.class,
- JPAMailboxMessage.class,
- JPAProperty.class,
- JPAUserFlag.class,
- JPAMailboxAnnotation.class,
- JPAAttachment.class
- );
-
List<Class<?>> QUOTA_PERSISTANCE_CLASSES = ImmutableList.of(
MaxGlobalMessageCount.class,
MaxGlobalStorage.class,
MaxDomainStorage.class,
MaxDomainMessageCount.class,
MaxUserMessageCount.class,
- MaxUserStorage.class,
- JpaCurrentQuota.class
- );
-
- List<String> MAILBOX_TABLE_NAMES = ImmutableList.of(
- "JAMES_MAIL_USERFLAG",
- "JAMES_MAIL_PROPERTY",
- "JAMES_MAILBOX_ANNOTATION",
- "JAMES_MAILBOX",
- "JAMES_MAIL",
- "JAMES_ATTACHMENT");
+ MaxUserStorage.class);
List<String> QUOTA_TABLES_NAMES = ImmutableList.of(
"JAMES_MAX_GLOBAL_MESSAGE_COUNT",
@@ -74,7 +46,6 @@ public interface JPAMailboxFixture {
"JAMES_MAX_USER_MESSAGE_COUNT",
"JAMES_MAX_USER_STORAGE",
"JAMES_MAX_DOMAIN_MESSAGE_COUNT",
- "JAMES_MAX_DOMAIN_STORAGE",
- "JAMES_QUOTA_CURRENTQUOTA"
+ "JAMES_MAX_DOMAIN_STORAGE"
);
}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerProvider.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresMailboxManagerProvider.java
similarity index 73%
rename from mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerProvider.java
rename to mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresMailboxManagerProvider.java
index d6100b2ade..d7eca629f6 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerProvider.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresMailboxManagerProvider.java
@@ -19,13 +19,14 @@
package org.apache.james.mailbox.postgres;
+import java.time.Clock;
import java.time.Instant;
-import javax.persistence.EntityManagerFactory;
-
-import org.apache.james.backends.jpa.JPAConfiguration;
-import org.apache.james.backends.jpa.JpaTestCluster;
import org.apache.james.backends.postgres.PostgresExtension;
+import org.apache.james.blob.api.BlobId;
+import org.apache.james.blob.api.BucketName;
+import org.apache.james.blob.api.HashBlobId;
+import org.apache.james.blob.memory.MemoryBlobStoreDAO;
import org.apache.james.events.EventBusTestFixture;
import org.apache.james.events.InVMEventBus;
import org.apache.james.events.MemoryEventDeadLetters;
@@ -34,38 +35,28 @@ import org.apache.james.mailbox.Authenticator;
import org.apache.james.mailbox.Authorizator;
import org.apache.james.mailbox.acl.MailboxACLResolver;
import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
-import org.apache.james.mailbox.postgres.mail.JPAModSeqProvider;
-import org.apache.james.mailbox.postgres.mail.JPAUidProvider;
-import org.apache.james.mailbox.postgres.openjpa.OpenJPAMailboxManager;
+import org.apache.james.mailbox.postgres.mail.PostgresMailboxManager;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.SessionProviderImpl;
import org.apache.james.mailbox.store.StoreMailboxAnnotationManager;
import org.apache.james.mailbox.store.StoreRightManager;
import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
import org.apache.james.mailbox.store.mail.NaiveThreadIdGuessingAlgorithm;
-import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
import org.apache.james.mailbox.store.quota.QuotaComponents;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
import org.apache.james.mailbox.store.search.SimpleMessageSearchIndex;
import org.apache.james.metrics.tests.RecordingMetricFactory;
+import org.apache.james.server.blob.deduplication.DeDuplicationBlobStore;
import org.apache.james.utils.UpdatableTickingClock;
-public class JpaMailboxManagerProvider {
+public class PostgresMailboxManagerProvider {
private static final int LIMIT_ANNOTATIONS = 3;
private static final int LIMIT_ANNOTATION_SIZE = 30;
- public static OpenJPAMailboxManager provideMailboxManager(JpaTestCluster jpaTestCluster, PostgresExtension postgresExtension) {
- EntityManagerFactory entityManagerFactory = jpaTestCluster.getEntityManagerFactory();
-
- JPAConfiguration jpaConfiguration = JPAConfiguration.builder()
- .driverName("driverName")
- .driverURL("driverUrl")
- .attachmentStorage(true)
- .build();
-
- PostgresMailboxSessionMapperFactory mf = new PostgresMailboxSessionMapperFactory(entityManagerFactory, new JPAUidProvider(entityManagerFactory),
- new JPAModSeqProvider(entityManagerFactory), jpaConfiguration, postgresExtension.getExecutorFactory());
+ public static PostgresMailboxManager provideMailboxManager(PostgresExtension postgresExtension) {
+ MailboxSessionMapperFactory mf = provideMailboxSessionMapperFactory(postgresExtension);
MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
MessageParser messageParser = new MessageParser();
@@ -81,9 +72,20 @@ public class JpaMailboxManagerProvider {
QuotaComponents quotaComponents = QuotaComponents.disabled(sessionProvider, mf);
MessageSearchIndex index = new SimpleMessageSearchIndex(mf, mf, new DefaultTextExtractor(), new JPAAttachmentContentLoader());
- return new OpenJPAMailboxManager(mf, sessionProvider,
- messageParser, new DefaultMessageId.Factory(),
+ return new PostgresMailboxManager((PostgresMailboxSessionMapperFactory) mf, sessionProvider,
+ messageParser, new PostgresMessageId.Factory(),
eventBus, annotationManager,
storeRightManager, quotaComponents, index, new NaiveThreadIdGuessingAlgorithm(), new UpdatableTickingClock(Instant.now()));
}
+
+ public static MailboxSessionMapperFactory provideMailboxSessionMapperFactory(PostgresExtension postgresExtension) {
+ BlobId.Factory blobIdFactory = new HashBlobId.Factory();
+ DeDuplicationBlobStore blobStore = new DeDuplicationBlobStore(new MemoryBlobStoreDAO(), BucketName.DEFAULT, blobIdFactory);
+
+ return new PostgresMailboxSessionMapperFactory(
+ postgresExtension.getExecutorFactory(),
+ Clock.systemUTC(),
+ blobStore,
+ blobIdFactory);
+ }
}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresMailboxManagerStressTest.java
similarity index 68%
rename from mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
rename to mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresMailboxManagerStressTest.java
index ea1ce952e4..c61c56eb3a 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JpaMailboxManagerStressTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresMailboxManagerStressTest.java
@@ -21,26 +21,23 @@ package org.apache.james.mailbox.postgres;
import java.util.Optional;
-import org.apache.james.backends.jpa.JpaTestCluster;
import org.apache.james.backends.postgres.PostgresExtension;
import org.apache.james.events.EventBus;
import org.apache.james.mailbox.MailboxManagerStressContract;
-import org.apache.james.mailbox.postgres.openjpa.OpenJPAMailboxManager;
-import org.junit.jupiter.api.AfterEach;
+import org.apache.james.mailbox.postgres.mail.PostgresMailboxManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
-class JpaMailboxManagerStressTest implements MailboxManagerStressContract<OpenJPAMailboxManager> {
+class PostgresMailboxManagerStressTest implements MailboxManagerStressContract<PostgresMailboxManager> {
@RegisterExtension
static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresMailboxAggregateModule.MODULE);
- static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
- Optional<OpenJPAMailboxManager> openJPAMailboxManager = Optional.empty();
+ Optional<PostgresMailboxManager> mailboxManager = Optional.empty();
@Override
- public OpenJPAMailboxManager getManager() {
- return openJPAMailboxManager.get();
+ public PostgresMailboxManager getManager() {
+ return mailboxManager.get();
}
@Override
@@ -50,13 +47,9 @@ class JpaMailboxManagerStressTest implements MailboxManagerStressContract<OpenJP
@BeforeEach
void setUp() {
- if (!openJPAMailboxManager.isPresent()) {
- openJPAMailboxManager = Optional.of(JpaMailboxManagerProvider.provideMailboxManager(JPA_TEST_CLUSTER, postgresExtension));
+ if (mailboxManager.isEmpty()) {
+ mailboxManager = Optional.of(PostgresMailboxManagerProvider.provideMailboxManager(postgresExtension));
}
}
- @AfterEach
- void tearDown() {
- JPA_TEST_CLUSTER.clear(JPAMailboxFixture.MAILBOX_TABLE_NAMES);
- }
}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresMailboxManagerTest.java
similarity index 65%
rename from mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
rename to mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresMailboxManagerTest.java
index bc98c13a50..d7fc4f355e 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/JPAMailboxManagerTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresMailboxManagerTest.java
@@ -20,20 +20,17 @@ package org.apache.james.mailbox.postgres;
import java.util.Optional;
-import org.apache.james.backends.jpa.JpaTestCluster;
import org.apache.james.backends.postgres.PostgresExtension;
import org.apache.james.events.EventBus;
import org.apache.james.mailbox.MailboxManagerTest;
import org.apache.james.mailbox.SubscriptionManager;
-import org.apache.james.mailbox.postgres.openjpa.OpenJPAMailboxManager;
+import org.apache.james.mailbox.postgres.mail.PostgresMailboxManager;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Nested;
-import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
-class JPAMailboxManagerTest extends MailboxManagerTest<OpenJPAMailboxManager> {
+class PostgresMailboxManagerTest extends MailboxManagerTest<PostgresMailboxManager> {
@Disabled("JPAMailboxManager is using DefaultMessageId which doesn't support full feature of a messageId, which is an essential" +
" element of the Vault")
@@ -41,18 +38,22 @@ class JPAMailboxManagerTest extends MailboxManagerTest<OpenJPAMailboxManager> {
class HookTests {
}
+ @Disabled("//TODO https://github.com/apache/james-project/pull/1822")
+ @Nested
+ class AnnotationTests {
+ }
+
@RegisterExtension
static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresMailboxAggregateModule.MODULE);
- static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
- Optional<OpenJPAMailboxManager> openJPAMailboxManager = Optional.empty();
-
+ Optional<PostgresMailboxManager> mailboxManager = Optional.empty();
+
@Override
- protected OpenJPAMailboxManager provideMailboxManager() {
- if (!openJPAMailboxManager.isPresent()) {
- openJPAMailboxManager = Optional.of(JpaMailboxManagerProvider.provideMailboxManager(JPA_TEST_CLUSTER, postgresExtension));
+ protected PostgresMailboxManager provideMailboxManager() {
+ if (mailboxManager.isEmpty()) {
+ mailboxManager = Optional.of(PostgresMailboxManagerProvider.provideMailboxManager(postgresExtension));
}
- return openJPAMailboxManager.get();
+ return mailboxManager.get();
}
@Override
@@ -60,26 +61,9 @@ class JPAMailboxManagerTest extends MailboxManagerTest<OpenJPAMailboxManager> {
return new StoreSubscriptionManager(provideMailboxManager().getMapperFactory(), provideMailboxManager().getMapperFactory(), provideMailboxManager().getEventBus());
}
- @AfterEach
- void tearDownJpa() {
- JPA_TEST_CLUSTER.clear(JPAMailboxFixture.MAILBOX_TABLE_NAMES);
- }
-
- @Disabled("MAILBOX-353 Creating concurrently mailboxes with the same parents with JPA")
- @Test
- @Override
- public void creatingConcurrentlyMailboxesWithSameParentShouldNotFail() {
-
- }
-
- @Nested
- @Disabled("JPA does not support saveDate.")
- class SaveDateTests {
-
- }
@Override
- protected EventBus retrieveEventBus(OpenJPAMailboxManager mailboxManager) {
+ protected EventBus retrieveEventBus(PostgresMailboxManager mailboxManager) {
return mailboxManager.getEventBus();
}
}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
index c68ed09b84..356f08ef1c 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/PostgresSubscriptionManagerTest.java
@@ -18,10 +18,6 @@
****************************************************************/
package org.apache.james.mailbox.postgres;
-import javax.persistence.EntityManagerFactory;
-
-import org.apache.james.backends.jpa.JPAConfiguration;
-import org.apache.james.backends.jpa.JpaTestCluster;
import org.apache.james.backends.postgres.PostgresExtension;
import org.apache.james.events.EventBusTestFixture;
import org.apache.james.events.InVMEventBus;
@@ -29,21 +25,16 @@ import org.apache.james.events.MemoryEventDeadLetters;
import org.apache.james.events.delivery.InVmEventDelivery;
import org.apache.james.mailbox.SubscriptionManager;
import org.apache.james.mailbox.SubscriptionManagerContract;
-import org.apache.james.mailbox.postgres.mail.JPAModSeqProvider;
-import org.apache.james.mailbox.postgres.mail.JPAUidProvider;
-import org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
import org.apache.james.metrics.tests.RecordingMetricFactory;
-import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
class PostgresSubscriptionManagerTest implements SubscriptionManagerContract {
@RegisterExtension
- static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
-
- static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
+ static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresMailboxAggregateModule.MODULE);
SubscriptionManager subscriptionManager;
@@ -54,25 +45,10 @@ class PostgresSubscriptionManagerTest implements SubscriptionManagerContract {
@BeforeEach
void setUp() {
- EntityManagerFactory entityManagerFactory = JPA_TEST_CLUSTER.getEntityManagerFactory();
-
- JPAConfiguration jpaConfiguration = JPAConfiguration.builder()
- .driverName("driverName")
- .driverURL("driverUrl")
- .build();
-
- PostgresMailboxSessionMapperFactory mapperFactory = new PostgresMailboxSessionMapperFactory(entityManagerFactory,
- new JPAUidProvider(entityManagerFactory),
- new JPAModSeqProvider(entityManagerFactory),
- jpaConfiguration,
- postgresExtension.getExecutorFactory());
+ MailboxSessionMapperFactory mapperFactory = PostgresMailboxManagerProvider.provideMailboxSessionMapperFactory(postgresExtension);
InVMEventBus eventBus = new InVMEventBus(new InVmEventDelivery(new RecordingMetricFactory()), EventBusTestFixture.RETRY_BACKOFF_CONFIGURATION, new MemoryEventDeadLetters());
subscriptionManager = new StoreSubscriptionManager(mapperFactory, mapperFactory, eventBus);
}
- @AfterEach
- void close() {
- JPA_TEST_CLUSTER.clear(JPAMailboxFixture.MAILBOX_TABLE_NAMES);
- }
}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JPAAttachmentMapperTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JPAAttachmentMapperTest.java
deleted file mode 100644
index e6ffcf1526..0000000000
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JPAAttachmentMapperTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/**************************************************************
- * 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.postgres.mail;
-
-import java.nio.charset.StandardCharsets;
-
-import org.apache.james.backends.jpa.JpaTestCluster;
-import org.apache.james.mailbox.postgres.JPAMailboxFixture;
-import org.apache.james.mailbox.model.AttachmentMetadata;
-import org.apache.james.mailbox.model.ContentType;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.ParsedAttachment;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
-import org.apache.james.mailbox.store.mail.model.AttachmentMapperTest;
-import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.io.ByteSource;
-
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.core.api.AssertionsForClassTypes.tuple;
-
-class JPAAttachmentMapperTest extends AttachmentMapperTest {
-
- private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
-
- @AfterEach
- void cleanUp() {
- JPA_TEST_CLUSTER.clear(JPAMailboxFixture.MAILBOX_TABLE_NAMES);
- }
-
- @Override
- protected AttachmentMapper createAttachmentMapper() {
- return new TransactionalAttachmentMapper(new JPAAttachmentMapper(JPA_TEST_CLUSTER.getEntityManagerFactory()));
- }
-
- @Override
- protected MessageId generateMessageId() {
- return new DefaultMessageId.Factory().generate();
- }
-
- @Test
- @Override
- public void getAttachmentsShouldReturnTheAttachmentsWhenSome() throws Exception {
- //Given
- ContentType content1 = ContentType.of("content");
- byte[] bytes1 = "payload" .getBytes(StandardCharsets.UTF_8);
- ContentType content2 = ContentType.of("content");
- byte[] bytes2 = "payload" .getBytes(StandardCharsets.UTF_8);
-
- MessageId messageId1 = generateMessageId();
- AttachmentMetadata stored1 = attachmentMapper.storeAttachments(ImmutableList.of(ParsedAttachment.builder()
- .contentType(content1)
- .content(ByteSource.wrap(bytes1))
- .noName()
- .noCid()
- .inline(false)), messageId1).get(0)
- .getAttachment();
- AttachmentMetadata stored2 = attachmentMapper.storeAttachments(ImmutableList.of(ParsedAttachment.builder()
- .contentType(content2)
- .content(ByteSource.wrap(bytes2))
- .noName()
- .noCid()
- .inline(false)), messageId1).get(0)
- .getAttachment();
-
- // JPA does not support MessageId
- assertThat(attachmentMapper.getAttachments(ImmutableList.of(stored1.getAttachmentId(), stored2.getAttachmentId())))
- .extracting(
- AttachmentMetadata::getAttachmentId,
- AttachmentMetadata::getSize,
- AttachmentMetadata::getType
- )
- .contains(
- tuple(stored1.getAttachmentId(), stored1.getSize(), stored1.getType()),
- tuple(stored2.getAttachmentId(), stored2.getSize(), stored2.getType())
- );
- }
-
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JPAMapperProvider.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JPAMapperProvider.java
deleted file mode 100644
index 1fab3e4b8b..0000000000
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JPAMapperProvider.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import java.util.List;
-import java.util.concurrent.ThreadLocalRandom;
-
-import javax.persistence.EntityManagerFactory;
-
-import org.apache.commons.lang3.NotImplementedException;
-import org.apache.james.backends.jpa.JPAConfiguration;
-import org.apache.james.backends.jpa.JpaTestCluster;
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.ModSeq;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
-import org.apache.james.mailbox.store.mail.MailboxMapper;
-import org.apache.james.mailbox.store.mail.MessageIdMapper;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
-import org.apache.james.mailbox.store.mail.model.MapperProvider;
-
-import com.google.common.collect.ImmutableList;
-
-public class JPAMapperProvider implements MapperProvider {
-
- private final JpaTestCluster jpaTestCluster;
-
- public JPAMapperProvider(JpaTestCluster jpaTestCluster) {
- this.jpaTestCluster = jpaTestCluster;
- }
-
- @Override
- public MailboxMapper createMailboxMapper() {
- return new TransactionalMailboxMapper(new JPAMailboxMapper(jpaTestCluster.getEntityManagerFactory()));
- }
-
- @Override
- public MessageMapper createMessageMapper() {
- EntityManagerFactory entityManagerFactory = jpaTestCluster.getEntityManagerFactory();
-
- JPAConfiguration jpaConfiguration = JPAConfiguration.builder()
- .driverName("driverName")
- .driverURL("driverUrl")
- .attachmentStorage(true)
- .build();
-
- JPAMessageMapper messageMapper = new JPAMessageMapper(new JPAUidProvider(entityManagerFactory),
- new JPAModSeqProvider(entityManagerFactory),
- entityManagerFactory,
- jpaConfiguration);
-
- return new TransactionalMessageMapper(messageMapper);
- }
-
- @Override
- public AttachmentMapper createAttachmentMapper() throws MailboxException {
- return new TransactionalAttachmentMapper(new JPAAttachmentMapper(jpaTestCluster.getEntityManagerFactory()));
- }
-
- @Override
- public MailboxId generateId() {
- return JPAId.of(Math.abs(ThreadLocalRandom.current().nextInt()));
- }
-
- @Override
- public MessageId generateMessageId() {
- return new DefaultMessageId.Factory().generate();
- }
-
- @Override
- public boolean supportPartialAttachmentFetch() {
- return false;
- }
-
- @Override
- public List<Capabilities> getSupportedCapabilities() {
- return ImmutableList.of(Capabilities.ANNOTATION, Capabilities.MAILBOX, Capabilities.MESSAGE, Capabilities.MOVE, Capabilities.ATTACHMENT);
- }
-
- @Override
- public MessageIdMapper createMessageIdMapper() throws MailboxException {
- throw new NotImplementedException("not implemented");
- }
-
- @Override
- public MessageUid generateMessageUid() {
- throw new NotImplementedException("not implemented");
- }
-
- @Override
- public ModSeq generateModSeq(Mailbox mailbox) throws MailboxException {
- throw new NotImplementedException("not implemented");
- }
-
- @Override
- public ModSeq highestModSeq(Mailbox mailbox) throws MailboxException {
- throw new NotImplementedException("not implemented");
- }
-
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JpaAnnotationMapperTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JpaAnnotationMapperTest.java
deleted file mode 100644
index 667714a800..0000000000
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JpaAnnotationMapperTest.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.james.backends.jpa.JpaTestCluster;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.postgres.JPAMailboxFixture;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.store.mail.AnnotationMapper;
-import org.apache.james.mailbox.store.mail.model.AnnotationMapperTest;
-import org.junit.jupiter.api.AfterEach;
-
-class JpaAnnotationMapperTest extends AnnotationMapperTest {
-
- static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
-
- final AtomicInteger counter = new AtomicInteger();
-
- @AfterEach
- void tearDown() {
- JPA_TEST_CLUSTER.clear(JPAMailboxFixture.MAILBOX_TABLE_NAMES);
- }
-
- @Override
- protected AnnotationMapper createAnnotationMapper() {
- return new TransactionalAnnotationMapper(new JPAAnnotationMapper(JPA_TEST_CLUSTER.getEntityManagerFactory()));
- }
-
- @Override
- protected MailboxId generateMailboxId() {
- return JPAId.of(counter.incrementAndGet());
- }
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JpaMailboxMapperTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JpaMailboxMapperTest.java
deleted file mode 100644
index c48dbe4f42..0000000000
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/JpaMailboxMapperTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.persistence.EntityManager;
-
-import org.apache.james.backends.jpa.JpaTestCluster;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.postgres.JPAMailboxFixture;
-import org.apache.james.mailbox.postgres.mail.model.JPAMailbox;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.store.mail.MailboxMapper;
-import org.apache.james.mailbox.store.mail.model.MailboxMapperTest;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.Test;
-
-class JpaMailboxMapperTest extends MailboxMapperTest {
-
- static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES);
-
- final AtomicInteger counter = new AtomicInteger();
-
- @Override
- protected MailboxMapper createMailboxMapper() {
- return new TransactionalMailboxMapper(new JPAMailboxMapper(JPA_TEST_CLUSTER.getEntityManagerFactory()));
- }
-
- @Override
- protected MailboxId generateId() {
- return JPAId.of(counter.incrementAndGet());
- }
-
- @AfterEach
- void cleanUp() {
- JPA_TEST_CLUSTER.clear(JPAMailboxFixture.MAILBOX_TABLE_NAMES);
- }
-
- @Test
- void invalidUidValidityShouldBeSanitized() throws Exception {
- EntityManager entityManager = JPA_TEST_CLUSTER.getEntityManagerFactory().createEntityManager();
-
- entityManager.getTransaction().begin();
- JPAMailbox jpaMailbox = new JPAMailbox(benwaInboxPath, -1L);// set an invalid uid validity
- jpaMailbox.setUidValidity(-1L);
- entityManager.persist(jpaMailbox);
- entityManager.getTransaction().commit();
-
- Mailbox readMailbox = mailboxMapper.findMailboxByPath(benwaInboxPath).block();
-
- assertThat(readMailbox.getUidValidity().isValid()).isTrue();
- }
-
- @Test
- void uidValiditySanitizingShouldPersistTheSanitizedUidValidity() throws Exception {
- EntityManager entityManager = JPA_TEST_CLUSTER.getEntityManagerFactory().createEntityManager();
-
- entityManager.getTransaction().begin();
- JPAMailbox jpaMailbox = new JPAMailbox(benwaInboxPath, -1L);// set an invalid uid validity
- jpaMailbox.setUidValidity(-1L);
- entityManager.persist(jpaMailbox);
- entityManager.getTransaction().commit();
-
- Mailbox readMailbox1 = mailboxMapper.findMailboxByPath(benwaInboxPath).block();
- Mailbox readMailbox2 = mailboxMapper.findMailboxByPath(benwaInboxPath).block();
-
- assertThat(readMailbox1.getUidValidity()).isEqualTo(readMailbox2.getUidValidity());
- }
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalAnnotationMapper.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalAnnotationMapper.java
deleted file mode 100644
index ff419a36f9..0000000000
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalAnnotationMapper.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import java.util.List;
-import java.util.Set;
-
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.MailboxAnnotation;
-import org.apache.james.mailbox.model.MailboxAnnotationKey;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.postgres.mail.JPAAnnotationMapper;
-import org.apache.james.mailbox.store.mail.AnnotationMapper;
-import org.apache.james.mailbox.store.transaction.Mapper;
-
-public class TransactionalAnnotationMapper implements AnnotationMapper {
- private final JPAAnnotationMapper wrapped;
-
- public TransactionalAnnotationMapper(JPAAnnotationMapper wrapped) {
- this.wrapped = wrapped;
- }
-
- @Override
- public List<MailboxAnnotation> getAllAnnotations(MailboxId mailboxId) {
- return wrapped.getAllAnnotations(mailboxId);
- }
-
- @Override
- public List<MailboxAnnotation> getAnnotationsByKeys(MailboxId mailboxId, Set<MailboxAnnotationKey> keys) {
- return wrapped.getAnnotationsByKeys(mailboxId, keys);
- }
-
- @Override
- public List<MailboxAnnotation> getAnnotationsByKeysWithOneDepth(MailboxId mailboxId, Set<MailboxAnnotationKey> keys) {
- return wrapped.getAnnotationsByKeysWithOneDepth(mailboxId, keys);
- }
-
- @Override
- public List<MailboxAnnotation> getAnnotationsByKeysWithAllDepth(MailboxId mailboxId, Set<MailboxAnnotationKey> keys) {
- return wrapped.getAnnotationsByKeysWithAllDepth(mailboxId, keys);
- }
-
- @Override
- public void deleteAnnotation(final MailboxId mailboxId, final MailboxAnnotationKey key) {
- try {
- wrapped.execute(Mapper.toTransaction(() -> wrapped.deleteAnnotation(mailboxId, key)));
- } catch (MailboxException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void insertAnnotation(final MailboxId mailboxId, final MailboxAnnotation mailboxAnnotation) {
- try {
- wrapped.execute(Mapper.toTransaction(() -> wrapped.insertAnnotation(mailboxId, mailboxAnnotation)));
- } catch (MailboxException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public boolean exist(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) {
- return wrapped.exist(mailboxId, mailboxAnnotation);
- }
-
- @Override
- public int countAnnotations(MailboxId mailboxId) {
- return wrapped.countAnnotations(mailboxId);
- }
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalAttachmentMapper.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalAttachmentMapper.java
deleted file mode 100644
index 6fc5b80542..0000000000
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalAttachmentMapper.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/***************************************************************
- * 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.postgres.mail;
-
-import java.io.InputStream;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.james.mailbox.exception.AttachmentNotFoundException;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.AttachmentId;
-import org.apache.james.mailbox.model.AttachmentMetadata;
-import org.apache.james.mailbox.model.MessageAttachmentMetadata;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.model.ParsedAttachment;
-import org.apache.james.mailbox.postgres.mail.JPAAttachmentMapper;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
-
-import reactor.core.publisher.Mono;
-
-public class TransactionalAttachmentMapper implements AttachmentMapper {
- private final JPAAttachmentMapper attachmentMapper;
-
- public TransactionalAttachmentMapper(JPAAttachmentMapper attachmentMapper) {
- this.attachmentMapper = attachmentMapper;
- }
-
- @Override
- public InputStream loadAttachmentContent(AttachmentId attachmentId) {
- return attachmentMapper.loadAttachmentContent(attachmentId);
- }
-
- @Override
- public Mono<InputStream> loadAttachmentContentReactive(AttachmentId attachmentId) {
- return attachmentMapper.executeReactive(attachmentMapper.loadAttachmentContentReactive(attachmentId));
- }
-
- @Override
- public AttachmentMetadata getAttachment(AttachmentId attachmentId) throws AttachmentNotFoundException {
- return attachmentMapper.getAttachment(attachmentId);
- }
-
- @Override
- public Mono<AttachmentMetadata> getAttachmentReactive(AttachmentId attachmentId) {
- return attachmentMapper.executeReactive(attachmentMapper.getAttachmentReactive(attachmentId));
- }
-
- @Override
- public List<AttachmentMetadata> getAttachments(Collection<AttachmentId> attachmentIds) {
- return attachmentMapper.getAttachments(attachmentIds);
- }
-
- @Override
- public List<MessageAttachmentMetadata> storeAttachments(Collection<ParsedAttachment> attachments, MessageId ownerMessageId) throws MailboxException {
- return attachmentMapper.execute(() -> attachmentMapper.storeAttachments(attachments, ownerMessageId));
- }
-
- @Override
- public Mono<List<MessageAttachmentMetadata>> storeAttachmentsReactive(Collection<ParsedAttachment> attachments, MessageId ownerMessageId) {
- return attachmentMapper.executeReactive(attachmentMapper.storeAttachmentsReactive(attachments, ownerMessageId));
- }
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalMailboxMapper.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalMailboxMapper.java
deleted file mode 100644
index 36608def8d..0000000000
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalMailboxMapper.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import org.apache.james.core.Username;
-import org.apache.james.mailbox.acl.ACLDiff;
-import org.apache.james.mailbox.model.Mailbox;
-import org.apache.james.mailbox.model.MailboxACL;
-import org.apache.james.mailbox.model.MailboxACL.Right;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.UidValidity;
-import org.apache.james.mailbox.model.search.MailboxQuery;
-import org.apache.james.mailbox.postgres.mail.JPAMailboxMapper;
-import org.apache.james.mailbox.store.mail.MailboxMapper;
-
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-public class TransactionalMailboxMapper implements MailboxMapper {
- private final JPAMailboxMapper wrapped;
-
- public TransactionalMailboxMapper(JPAMailboxMapper wrapped) {
- this.wrapped = wrapped;
- }
-
- @Override
- public Mono<Mailbox> create(MailboxPath mailboxPath, UidValidity uidValidity) {
- return wrapped.executeReactive(wrapped.create(mailboxPath, uidValidity));
- }
-
- @Override
- public Mono<MailboxId> rename(Mailbox mailbox) {
- return wrapped.executeReactive(wrapped.rename(mailbox));
- }
-
- @Override
- public Mono<Void> delete(Mailbox mailbox) {
- return wrapped.executeReactive(wrapped.delete(mailbox));
- }
-
- @Override
- public Mono<Mailbox> findMailboxByPath(MailboxPath mailboxPath) {
- return wrapped.findMailboxByPath(mailboxPath);
- }
-
- @Override
- public Mono<Mailbox> findMailboxById(MailboxId mailboxId) {
- return wrapped.findMailboxById(mailboxId);
- }
-
- @Override
- public Flux<Mailbox> findMailboxWithPathLike(MailboxQuery.UserBound query) {
- return wrapped.findMailboxWithPathLike(query);
- }
-
- @Override
- public Mono<Boolean> hasChildren(Mailbox mailbox, char delimiter) {
- return wrapped.hasChildren(mailbox, delimiter);
- }
-
- @Override
- public Mono<ACLDiff> updateACL(Mailbox mailbox, MailboxACL.ACLCommand mailboxACLCommand) {
- return wrapped.updateACL(mailbox, mailboxACLCommand);
- }
-
- @Override
- public Mono<ACLDiff> setACL(Mailbox mailbox, MailboxACL mailboxACL) {
- return wrapped.setACL(mailbox, mailboxACL);
- }
-
- @Override
- public Flux<Mailbox> list() {
- return wrapped.list();
- }
-
- @Override
- public Flux<Mailbox> findNonPersonalMailboxes(Username userName, Right right) {
- return wrapped.findNonPersonalMailboxes(userName, right);
- }
-
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalMessageMapper.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalMessageMapper.java
deleted file mode 100644
index f779af3c30..0000000000
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/TransactionalMessageMapper.java
+++ /dev/null
@@ -1,147 +0,0 @@
-/****************************************************************
- * 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.postgres.mail;
-
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-
-import javax.mail.Flags;
-
-import org.apache.james.mailbox.MessageUid;
-import org.apache.james.mailbox.ModSeq;
-import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.model.Mailbox;
-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;
-import org.apache.james.mailbox.postgres.mail.JPAMessageMapper;
-import org.apache.james.mailbox.store.FlagsUpdateCalculator;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.transaction.Mapper;
-
-import reactor.core.publisher.Flux;
-
-public class TransactionalMessageMapper implements MessageMapper {
- private final JPAMessageMapper messageMapper;
-
- public TransactionalMessageMapper(JPAMessageMapper messageMapper) {
- this.messageMapper = messageMapper;
- }
-
- @Override
- public MailboxCounters getMailboxCounters(Mailbox mailbox) throws MailboxException {
- return MailboxCounters.builder()
- .mailboxId(mailbox.getMailboxId())
- .count(countMessagesInMailbox(mailbox))
- .unseen(countUnseenMessagesInMailbox(mailbox))
- .build();
- }
-
- @Override
- public Flux<MessageUid> listAllMessageUids(Mailbox mailbox) {
- return messageMapper.listAllMessageUids(mailbox);
- }
-
- @Override
- public Iterator<MailboxMessage> findInMailbox(Mailbox mailbox, MessageRange set, FetchType type, int limit)
- throws MailboxException {
- return messageMapper.findInMailbox(mailbox, set, type, limit);
- }
-
- @Override
- public List<MessageUid> retrieveMessagesMarkedForDeletion(Mailbox mailbox, MessageRange messageRange) throws MailboxException {
- return messageMapper.execute(
- () -> messageMapper.retrieveMessagesMarkedForDeletion(mailbox, messageRange));
- }
-
- @Override
- public Map<MessageUid, MessageMetaData> deleteMessages(Mailbox mailbox, List<MessageUid> uids) throws MailboxException {
- return messageMapper.execute(
- () -> messageMapper.deleteMessages(mailbox, uids));
- }
-
- @Override
- public long countMessagesInMailbox(Mailbox mailbox) throws MailboxException {
- return messageMapper.countMessagesInMailbox(mailbox);
- }
-
- private long countUnseenMessagesInMailbox(Mailbox mailbox) throws MailboxException {
- return messageMapper.countUnseenMessagesInMailbox(mailbox);
- }
-
- @Override
- public void delete(final Mailbox mailbox, final MailboxMessage message) throws MailboxException {
- messageMapper.execute(Mapper.toTransaction(() -> messageMapper.delete(mailbox, message)));
- }
-
- @Override
- public MessageUid findFirstUnseenMessageUid(Mailbox mailbox) throws MailboxException {
- return messageMapper.findFirstUnseenMessageUid(mailbox);
- }
-
- @Override
- public List<MessageUid> findRecentMessageUidsInMailbox(Mailbox mailbox) throws MailboxException {
- return messageMapper.findRecentMessageUidsInMailbox(mailbox);
- }
-
- @Override
- public MessageMetaData add(final Mailbox mailbox, final MailboxMessage message) throws MailboxException {
- return messageMapper.execute(
- () -> messageMapper.add(mailbox, message));
- }
-
- @Override
- public Iterator<UpdatedFlags> updateFlags(final Mailbox mailbox, final FlagsUpdateCalculator flagsUpdateCalculator,
- final MessageRange set) throws MailboxException {
- return messageMapper.execute(
- () -> messageMapper.updateFlags(mailbox, flagsUpdateCalculator, set));
- }
-
- @Override
- public MessageMetaData copy(final Mailbox mailbox, final MailboxMessage original) throws MailboxException {
- return messageMapper.execute(
- () -> messageMapper.copy(mailbox, original));
- }
-
- @Override
- public MessageMetaData move(Mailbox mailbox, MailboxMessage original) throws MailboxException {
- return messageMapper.execute(
- () -> messageMapper.move(mailbox, original));
- }
-
- @Override
- public Optional<MessageUid> getLastUid(Mailbox mailbox) throws MailboxException {
- return messageMapper.getLastUid(mailbox);
- }
-
- @Override
- public ModSeq getHighestModSeq(Mailbox mailbox) throws MailboxException {
- return messageMapper.getHighestModSeq(mailbox);
- }
-
- @Override
- public Flags getApplicableFlag(Mailbox mailbox) throws MailboxException {
- return messageMapper.getApplicableFlag(mailbox);
- }
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/model/openjpa/JPAMailboxMessageTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/model/openjpa/JPAMailboxMessageTest.java
deleted file mode 100644
index cc34126ed4..0000000000
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/model/openjpa/JPAMailboxMessageTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/****************************************************************
- * 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.postgres.mail.model.openjpa;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.nio.charset.StandardCharsets;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.james.mailbox.postgres.mail.model.openjpa.JPAMailboxMessage;
-import org.junit.jupiter.api.Test;
-
-class JPAMailboxMessageTest {
-
- private static final byte[] EMPTY = new byte[] {};
- /**
- * Even though there should never be a null body, it does happen. See JAMES-2384
- */
- @Test
- void getFullContentShouldReturnOriginalContentWhenBodyFieldIsNull() throws Exception {
-
- // Prepare the message
- byte[] content = "Subject: the null message".getBytes(StandardCharsets.UTF_8);
- JPAMailboxMessage message = new JPAMailboxMessage(content, null);
-
- // Get and check
- assertThat(IOUtils.toByteArray(message.getFullContent())).containsExactly(content);
-
- }
-
- @Test
- void getAnyMessagePartThatIsNullShouldYieldEmptyArray() throws Exception {
-
- // Prepare the message
- JPAMailboxMessage message = new JPAMailboxMessage(null, null);
- assertThat(IOUtils.toByteArray(message.getHeaderContent())).containsExactly(EMPTY);
- assertThat(IOUtils.toByteArray(message.getBodyContent())).containsExactly(EMPTY);
- assertThat(IOUtils.toByteArray(message.getFullContent())).containsExactly(EMPTY);
- }
-
-}
diff --git a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/PostgresRecomputeCurrentQuotasServiceTest.java
similarity index 62%
rename from mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java
rename to mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/PostgresRecomputeCurrentQuotasServiceTest.java
index 077c249c19..3e95b0eee6 100644
--- a/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/JPARecomputeCurrentQuotasServiceTest.java
+++ b/mailbox/postgres/src/test/java/org/apache/james/mailbox/postgres/mail/task/PostgresRecomputeCurrentQuotasServiceTest.java
@@ -19,56 +19,49 @@
package org.apache.james.mailbox.postgres.mail.task;
-import javax.persistence.EntityManagerFactory;
-
import org.apache.commons.configuration2.BaseHierarchicalConfiguration;
-import org.apache.james.backends.jpa.JPAConfiguration;
import org.apache.james.backends.jpa.JpaTestCluster;
import org.apache.james.backends.postgres.PostgresExtension;
+import org.apache.james.backends.postgres.PostgresModule;
+import org.apache.james.backends.postgres.quota.PostgresQuotaCurrentValueDAO;
+import org.apache.james.backends.postgres.quota.PostgresQuotaModule;
import org.apache.james.domainlist.api.DomainList;
-import org.apache.james.domainlist.jpa.model.JPADomain;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.SessionProvider;
-import org.apache.james.mailbox.postgres.JPAMailboxFixture;
-import org.apache.james.mailbox.postgres.JpaMailboxManagerProvider;
-import org.apache.james.mailbox.postgres.PostgresMailboxSessionMapperFactory;
-import org.apache.james.mailbox.postgres.mail.JPAModSeqProvider;
-import org.apache.james.mailbox.postgres.mail.JPAUidProvider;
-import org.apache.james.mailbox.postgres.quota.JpaCurrentQuotaManager;
-import org.apache.james.mailbox.postgres.user.PostgresSubscriptionModule;
+import org.apache.james.mailbox.postgres.PostgresMailboxAggregateModule;
+import org.apache.james.mailbox.postgres.PostgresMailboxManagerProvider;
+import org.apache.james.mailbox.postgres.quota.PostgresCurrentQuotaManager;
import org.apache.james.mailbox.quota.CurrentQuotaManager;
import org.apache.james.mailbox.quota.UserQuotaRootResolver;
import org.apache.james.mailbox.quota.task.RecomputeCurrentQuotasService;
import org.apache.james.mailbox.quota.task.RecomputeCurrentQuotasServiceContract;
import org.apache.james.mailbox.quota.task.RecomputeMailboxCurrentQuotasService;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.StoreMailboxManager;
import org.apache.james.mailbox.store.quota.CurrentQuotaCalculator;
import org.apache.james.mailbox.store.quota.DefaultUserQuotaRootResolver;
import org.apache.james.user.api.UsersRepository;
-import org.apache.james.user.jpa.JPAUsersRepository;
-import org.apache.james.user.jpa.model.JPAUser;
-import org.junit.jupiter.api.AfterEach;
+import org.apache.james.user.postgres.PostgresUserModule;
+import org.apache.james.user.postgres.PostgresUsersDAO;
+import org.apache.james.user.postgres.PostgresUsersRepository;
+import org.apache.james.user.postgres.PostgresUsersRepositoryConfiguration;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
-class JPARecomputeCurrentQuotasServiceTest implements RecomputeCurrentQuotasServiceContract {
+class PostgresRecomputeCurrentQuotasServiceTest implements RecomputeCurrentQuotasServiceContract {
@RegisterExtension
- static PostgresExtension postgresExtension = PostgresExtension.withoutRowLevelSecurity(PostgresSubscriptionModule.MODULE);
+ static PostgresExtension postgresExtension = PostgresExtension.withRowLevelSecurity(PostgresModule.aggregateModules(
+ PostgresMailboxAggregateModule.MODULE,
+ PostgresQuotaModule.MODULE,
+ PostgresUserModule.MODULE));
static final DomainList NO_DOMAIN_LIST = null;
- static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(ImmutableList.<Class<?>>builder()
- .addAll(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES)
- .addAll(JPAMailboxFixture.QUOTA_PERSISTANCE_CLASSES)
- .add(JPAUser.class)
- .add(JPADomain.class)
- .build());
-
- JPAUsersRepository usersRepository;
+ PostgresUsersRepository usersRepository;
StoreMailboxManager mailboxManager;
SessionProvider sessionProvider;
CurrentQuotaManager currentQuotaManager;
@@ -77,28 +70,19 @@ class JPARecomputeCurrentQuotasServiceTest implements RecomputeCurrentQuotasServ
@BeforeEach
void setUp() throws Exception {
- EntityManagerFactory entityManagerFactory = JPA_TEST_CLUSTER.getEntityManagerFactory();
-
- JPAConfiguration jpaConfiguration = JPAConfiguration.builder()
- .driverName("driverName")
- .driverURL("driverUrl")
- .build();
+ MailboxSessionMapperFactory mapperFactory = PostgresMailboxManagerProvider.provideMailboxSessionMapperFactory(postgresExtension);
- PostgresMailboxSessionMapperFactory mapperFactory = new PostgresMailboxSessionMapperFactory(entityManagerFactory,
- new JPAUidProvider(entityManagerFactory),
- new JPAModSeqProvider(entityManagerFactory),
- jpaConfiguration,
- postgresExtension.getExecutorFactory());
+ PostgresUsersDAO usersDAO = new PostgresUsersDAO(postgresExtension.getPostgresExecutor(),
+ PostgresUsersRepositoryConfiguration.DEFAULT);
- usersRepository = new JPAUsersRepository(NO_DOMAIN_LIST);
- usersRepository.setEntityManagerFactory(JPA_TEST_CLUSTER.getEntityManagerFactory());
+ usersRepository = new PostgresUsersRepository(NO_DOMAIN_LIST, usersDAO);
BaseHierarchicalConfiguration configuration = new BaseHierarchicalConfiguration();
configuration.addProperty("enableVirtualHosting", "false");
usersRepository.configure(configuration);
- mailboxManager = JpaMailboxManagerProvider.provideMailboxManager(JPA_TEST_CLUSTER, postgresExtension);
+ mailboxManager = PostgresMailboxManagerProvider.provideMailboxManager(postgresExtension);
sessionProvider = mailboxManager.getSessionProvider();
- currentQuotaManager = new JpaCurrentQuotaManager(entityManagerFactory);
+ currentQuotaManager = new PostgresCurrentQuotaManager(new PostgresQuotaCurrentValueDAO(postgresExtension.getPostgresExecutor()));
userQuotaRootResolver = new DefaultUserQuotaRootResolver(sessionProvider, mapperFactory);
@@ -113,16 +97,6 @@ class JPARecomputeCurrentQuotasServiceTest implements RecomputeCurrentQuotasServ
RECOMPUTE_JMAP_UPLOAD_CURRENT_QUOTAS_SERVICE));
}
- @AfterEach
- void tearDownJpa() {
- JPA_TEST_CLUSTER.clear(ImmutableList.<String>builder()
- .addAll(JPAMailboxFixture.MAILBOX_TABLE_NAMES)
- .addAll(JPAMailboxFixture.QUOTA_TABLES_NAMES)
- .add("JAMES_USER")
- .add("JAMES_DOMAIN")
- .build());
- }
-
@Override
public UsersRepository usersRepository() {
return usersRepository;
diff --git a/mailbox/postgres/src/test/resources/persistence.xml b/mailbox/postgres/src/test/resources/persistence.xml
index 83201af526..21199cfdd4 100644
--- a/mailbox/postgres/src/test/resources/persistence.xml
+++ b/mailbox/postgres/src/test/resources/persistence.xml
@@ -24,22 +24,12 @@
version="2.0">
<persistence-unit name="James" transaction-type="RESOURCE_LOCAL">
- <class>org.apache.james.mailbox.postgres.mail.model.JPAMailbox</class>
- <class>org.apache.james.mailbox.postgres.mail.model.JPAUserFlag</class>
- <class>org.apache.james.mailbox.postgres.mail.model.openjpa.AbstractJPAMailboxMessage</class>
- <class>org.apache.james.mailbox.postgres.mail.model.openjpa.JPAMailboxMessage</class>
- <class>org.apache.james.mailbox.postgres.mail.model.JPAAttachment</class>
- <class>org.apache.james.mailbox.postgres.mail.model.JPAProperty</class>
<class>org.apache.james.mailbox.postgres.quota.model.MaxDomainMessageCount</class>
<class>org.apache.james.mailbox.postgres.quota.model.MaxDomainStorage</class>
<class>org.apache.james.mailbox.postgres.quota.model.MaxGlobalMessageCount</class>
<class>org.apache.james.mailbox.postgres.quota.model.MaxGlobalStorage</class>
<class>org.apache.james.mailbox.postgres.quota.model.MaxUserMessageCount</class>
<class>org.apache.james.mailbox.postgres.quota.model.MaxUserStorage</class>
- <class>org.apache.james.mailbox.postgres.quota.model.JpaCurrentQuota</class>
- <class>org.apache.james.mailbox.postgres.mail.model.JPAMailboxAnnotation</class>
- <class>org.apache.james.mailbox.postgres.mail.model.JPAMailboxAnnotationId</class>
- <class>org.apache.james.mailbox.postgres.mail.model.openjpa.AbstractJPAMailboxMessage$MailboxIdUidKey</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
<property name="openjpa.jdbc.MappingDefaults" value="ForeignKeyDeleteAction=cascade, JoinForeignKeyDeleteAction=cascade"/>
diff --git a/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystem.java b/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystem.java
index eff72a7c4c..5c5ab7e688 100644
--- a/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystem.java
+++ b/mpt/impl/imap-mailbox/postgres/src/test/java/org/apache/james/mpt/imapmailbox/postgres/host/PostgresHostSystem.java
@@ -47,9 +47,9 @@ import org.apache.james.mailbox.SubscriptionManager;
import org.apache.james.mailbox.acl.MailboxACLResolver;
import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
import org.apache.james.mailbox.postgres.JPAMailboxFixture;
-import org.apache.james.mailbox.postgres.PostgresMailboxSessionMapperFactoryTODO;
+import org.apache.james.mailbox.postgres.PostgresMailboxSessionMapperFactory;
import org.apache.james.mailbox.postgres.PostgresMessageId;
-import org.apache.james.mailbox.postgres.openjpa.OpenJPAMailboxManager;
+import org.apache.james.mailbox.postgres.mail.PostgresMailboxManager;
import org.apache.james.mailbox.postgres.quota.JPAPerUserMaxQuotaDAO;
import org.apache.james.mailbox.postgres.quota.JPAPerUserMaxQuotaManager;
import org.apache.james.mailbox.postgres.quota.PostgresCurrentQuotaManager;
@@ -83,7 +83,6 @@ public class PostgresHostSystem extends JamesImapHostSystem {
private static final JpaTestCluster JPA_TEST_CLUSTER = JpaTestCluster.create(
ImmutableList.<Class<?>>builder()
- .addAll(JPAMailboxFixture.MAILBOX_PERSISTANCE_CLASSES)
.addAll(JPAMailboxFixture.QUOTA_PERSISTANCE_CLASSES)
.build());
@@ -100,7 +99,7 @@ public class PostgresHostSystem extends JamesImapHostSystem {
}
private JPAPerUserMaxQuotaManager maxQuotaManager;
- private OpenJPAMailboxManager mailboxManager;
+ private PostgresMailboxManager mailboxManager;
private final PostgresExtension postgresExtension;
public PostgresHostSystem(PostgresExtension postgresExtension) {
@@ -119,7 +118,7 @@ public class PostgresHostSystem extends JamesImapHostSystem {
BlobId.Factory blobIdFactory = new HashBlobId.Factory();
DeDuplicationBlobStore blobStore = new DeDuplicationBlobStore(new MemoryBlobStoreDAO(), BucketName.DEFAULT, blobIdFactory);
- PostgresMailboxSessionMapperFactoryTODO mapperFactory = new PostgresMailboxSessionMapperFactoryTODO(postgresExtension.getExecutorFactory(), Clock.systemUTC(), blobStore, blobIdFactory);
+ PostgresMailboxSessionMapperFactory mapperFactory = new PostgresMailboxSessionMapperFactory(postgresExtension.getExecutorFactory(), Clock.systemUTC(), blobStore, blobIdFactory);
MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
MessageParser messageParser = new MessageParser();
@@ -138,7 +137,7 @@ public class PostgresHostSystem extends JamesImapHostSystem {
AttachmentContentLoader attachmentContentLoader = null;
MessageSearchIndex index = new SimpleMessageSearchIndex(mapperFactory, mapperFactory, new DefaultTextExtractor(), attachmentContentLoader);
- mailboxManager = new OpenJPAMailboxManager(mapperFactory, sessionProvider, messageParser,
+ mailboxManager = new PostgresMailboxManager(mapperFactory, sessionProvider, messageParser,
new PostgresMessageId.Factory(),
eventBus, annotationManager, storeRightManager, quotaComponents, index, new NaiveThreadIdGuessingAlgorithm(), new UpdatableTickingClock(Instant.now()));
@@ -164,7 +163,6 @@ public class PostgresHostSystem extends JamesImapHostSystem {
@Override
public void afterTest() {
JPA_TEST_CLUSTER.clear(ImmutableList.<String>builder()
- .addAll(JPAMailboxFixture.MAILBOX_TABLE_NAMES)
.addAll(JPAMailboxFixture.QUOTA_TABLES_NAMES)
.build());
}
diff --git a/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesServerMain.java b/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesServerMain.java
index 8ecba40bb7..1191382350 100644
--- a/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesServerMain.java
+++ b/server/apps/postgres-app/src/main/java/org/apache/james/PostgresJamesServerMain.java
@@ -27,7 +27,6 @@ import org.apache.james.modules.data.PostgresDataModule;
import org.apache.james.modules.data.PostgresUsersRepositoryModule;
import org.apache.james.modules.data.SievePostgresRepositoryModules;
import org.apache.james.modules.mailbox.DefaultEventModule;
-import org.apache.james.modules.mailbox.JPAMailboxModule;
import org.apache.james.modules.mailbox.LuceneSearchMailboxModule;
import org.apache.james.modules.mailbox.MemoryDeadLetterModule;
import org.apache.james.modules.mailbox.PostgresMailboxModule;
@@ -82,7 +81,6 @@ public class PostgresJamesServerMain implements JamesServerMain {
new ActiveMQQueueModule(),
new NaiveDelegationStoreModule(),
new DefaultProcessorsConfigurationProviderModule(),
- new JPAMailboxModule(),
new PostgresMailboxModule(),
new PostgresDataModule(),
new MailboxModule(),
diff --git a/server/apps/postgres-app/src/main/resources/META-INF/persistence.xml b/server/apps/postgres-app/src/main/resources/META-INF/persistence.xml
index 165c6456cd..e223792513 100644
--- a/server/apps/postgres-app/src/main/resources/META-INF/persistence.xml
+++ b/server/apps/postgres-app/src/main/resources/META-INF/persistence.xml
@@ -24,12 +24,6 @@
version="2.0">
<persistence-unit name="Global" transaction-type="RESOURCE_LOCAL">
- <class>org.apache.james.mailbox.postgres.mail.model.JPAMailbox</class>
- <class>org.apache.james.mailbox.postgres.mail.model.JPAUserFlag</class>
- <class>org.apache.james.mailbox.postgres.mail.model.openjpa.AbstractJPAMailboxMessage</class>
- <class>org.apache.james.mailbox.postgres.mail.model.openjpa.JPAMailboxMessage</class>
- <class>org.apache.james.mailbox.postgres.mail.model.JPAProperty</class>
-
<class>org.apache.james.mailrepository.jpa.model.JPAUrl</class>
<class>org.apache.james.mailrepository.jpa.model.JPAMail</class>
<class>org.apache.james.rrt.jpa.model.JPARecipientRewrite</class>
@@ -43,10 +37,6 @@
<class>org.apache.james.mailbox.postgres.quota.model.MaxUserStorage</class>
<class>org.apache.james.mailbox.postgres.quota.model.MaxDomainStorage</class>
<class>org.apache.james.mailbox.postgres.quota.model.MaxDomainMessageCount</class>
- <class>org.apache.james.mailbox.postgres.quota.model.JpaCurrentQuota</class>
-
- <class>org.apache.james.mailbox.postgres.mail.model.JPAMailboxAnnotation</class>
- <class>org.apache.james.mailbox.postgres.mail.model.JPAMailboxAnnotationId</class>
<properties>
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
diff --git a/server/container/guice/mailbox-postgres/pom.xml b/server/container/guice/mailbox-postgres/pom.xml
index e07ac357ac..6aa052c041 100644
--- a/server/container/guice/mailbox-postgres/pom.xml
+++ b/server/container/guice/mailbox-postgres/pom.xml
@@ -45,6 +45,10 @@
<groupId>${james.groupId}</groupId>
<artifactId>apache-james-mailbox-quota-search-scanning</artifactId>
</dependency>
+ <dependency>
+ <groupId>${james.groupId}</groupId>
+ <artifactId>blob-memory-guice</artifactId>
+ </dependency>
<dependency>
<groupId>${james.groupId}</groupId>
<artifactId>james-server-data-postgres</artifactId>
diff --git a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java b/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java
deleted file mode 100644
index 8f92d0e27c..0000000000
--- a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/****************************************************************
- * 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.modules.mailbox;
-
-import static org.apache.james.modules.Names.MAILBOXMANAGER_NAME;
-
-import javax.inject.Singleton;
-
-import org.apache.james.adapter.mailbox.ACLUsernameChangeTaskStep;
-import org.apache.james.adapter.mailbox.MailboxUserDeletionTaskStep;
-import org.apache.james.adapter.mailbox.MailboxUsernameChangeTaskStep;
-import org.apache.james.adapter.mailbox.QuotaUsernameChangeTaskStep;
-import org.apache.james.adapter.mailbox.UserRepositoryAuthenticator;
-import org.apache.james.adapter.mailbox.UserRepositoryAuthorizator;
-import org.apache.james.events.EventListener;
-import org.apache.james.mailbox.AttachmentContentLoader;
-import org.apache.james.mailbox.Authenticator;
-import org.apache.james.mailbox.Authorizator;
-import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.MailboxPathLocker;
-import org.apache.james.mailbox.SessionProvider;
-import org.apache.james.mailbox.SubscriptionManager;
-import org.apache.james.mailbox.acl.MailboxACLResolver;
-import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
-import org.apache.james.mailbox.indexer.ReIndexer;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MessageId;
-import org.apache.james.mailbox.postgres.JPAAttachmentContentLoader;
-import org.apache.james.mailbox.postgres.JPAId;
-import org.apache.james.mailbox.postgres.PostgresMailboxSessionMapperFactory;
-import org.apache.james.mailbox.postgres.mail.JPAModSeqProvider;
-import org.apache.james.mailbox.postgres.mail.JPAUidProvider;
-import org.apache.james.mailbox.postgres.openjpa.OpenJPAMailboxManager;
-import org.apache.james.mailbox.store.JVMMailboxPathLocker;
-import org.apache.james.mailbox.store.MailboxManagerConfiguration;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.SessionProviderImpl;
-import org.apache.james.mailbox.store.StoreMailboxManager;
-import org.apache.james.mailbox.store.StoreSubscriptionManager;
-import org.apache.james.mailbox.store.event.MailboxAnnotationListener;
-import org.apache.james.mailbox.store.event.MailboxSubscriptionListener;
-import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
-import org.apache.james.mailbox.store.mail.MessageMapperFactory;
-import org.apache.james.mailbox.store.mail.ModSeqProvider;
-import org.apache.james.mailbox.store.mail.NaiveThreadIdGuessingAlgorithm;
-import org.apache.james.mailbox.store.mail.ThreadIdGuessingAlgorithm;
-import org.apache.james.mailbox.store.mail.UidProvider;
-import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
-import org.apache.james.mailbox.store.user.SubscriptionMapperFactory;
-import org.apache.james.modules.data.JPAEntityManagerModule;
-import org.apache.james.user.api.DeleteUserDataTaskStep;
-import org.apache.james.user.api.UsernameChangeTaskStep;
-import org.apache.james.utils.MailboxManagerDefinition;
-import org.apache.mailbox.tools.indexer.ReIndexerImpl;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.Inject;
-import com.google.inject.Scopes;
-import com.google.inject.multibindings.Multibinder;
-import com.google.inject.name.Names;
-
-public class JPAMailboxModule extends AbstractModule {
-
- @Override
- protected void configure() {
- install(new JpaQuotaModule());
- install(new JPAQuotaSearchModule());
- install(new JPAEntityManagerModule());
-
- bind(PostgresMailboxSessionMapperFactory.class).in(Scopes.SINGLETON);
- bind(OpenJPAMailboxManager.class).in(Scopes.SINGLETON);
- bind(JVMMailboxPathLocker.class).in(Scopes.SINGLETON);
- bind(StoreSubscriptionManager.class).in(Scopes.SINGLETON);
- bind(JPAModSeqProvider.class).in(Scopes.SINGLETON);
- bind(JPAUidProvider.class).in(Scopes.SINGLETON);
- bind(UserRepositoryAuthenticator.class).in(Scopes.SINGLETON);
- bind(UserRepositoryAuthorizator.class).in(Scopes.SINGLETON);
- bind(JPAId.Factory.class).in(Scopes.SINGLETON);
- bind(UnionMailboxACLResolver.class).in(Scopes.SINGLETON);
- bind(DefaultMessageId.Factory.class).in(Scopes.SINGLETON);
- bind(NaiveThreadIdGuessingAlgorithm.class).in(Scopes.SINGLETON);
- bind(ReIndexerImpl.class).in(Scopes.SINGLETON);
- bind(SessionProviderImpl.class).in(Scopes.SINGLETON);
-
- bind(SubscriptionMapperFactory.class).to(PostgresMailboxSessionMapperFactory.class);
- bind(MessageMapperFactory.class).to(PostgresMailboxSessionMapperFactory.class);
- bind(MailboxMapperFactory.class).to(PostgresMailboxSessionMapperFactory.class);
- bind(MailboxSessionMapperFactory.class).to(PostgresMailboxSessionMapperFactory.class);
- bind(MessageId.Factory.class).to(DefaultMessageId.Factory.class);
- bind(ThreadIdGuessingAlgorithm.class).to(NaiveThreadIdGuessingAlgorithm.class);
-
- bind(ModSeqProvider.class).to(JPAModSeqProvider.class);
- bind(UidProvider.class).to(JPAUidProvider.class);
- bind(SubscriptionManager.class).to(StoreSubscriptionManager.class);
- bind(MailboxPathLocker.class).to(JVMMailboxPathLocker.class);
- bind(Authenticator.class).to(UserRepositoryAuthenticator.class);
- bind(MailboxManager.class).to(OpenJPAMailboxManager.class);
- bind(StoreMailboxManager.class).to(OpenJPAMailboxManager.class);
- bind(SessionProvider.class).to(SessionProviderImpl.class);
- bind(Authorizator.class).to(UserRepositoryAuthorizator.class);
- bind(MailboxId.Factory.class).to(JPAId.Factory.class);
- bind(MailboxACLResolver.class).to(UnionMailboxACLResolver.class);
- bind(AttachmentContentLoader.class).to(JPAAttachmentContentLoader.class);
-
- bind(ReIndexer.class).to(ReIndexerImpl.class);
-
- Multibinder.newSetBinder(binder(), MailboxManagerDefinition.class).addBinding().to(JPAMailboxManagerDefinition.class);
-
- Multibinder.newSetBinder(binder(), EventListener.GroupEventListener.class)
- .addBinding()
- .to(MailboxAnnotationListener.class);
-
- Multibinder.newSetBinder(binder(), EventListener.GroupEventListener.class)
- .addBinding()
- .to(MailboxSubscriptionListener.class);
-
- bind(MailboxManager.class).annotatedWith(Names.named(MAILBOXMANAGER_NAME)).to(MailboxManager.class);
- bind(MailboxManagerConfiguration.class).toInstance(MailboxManagerConfiguration.DEFAULT);
-
- Multibinder<UsernameChangeTaskStep> usernameChangeTaskStepMultibinder = Multibinder.newSetBinder(binder(), UsernameChangeTaskStep.class);
- usernameChangeTaskStepMultibinder.addBinding().to(MailboxUsernameChangeTaskStep.class);
- usernameChangeTaskStepMultibinder.addBinding().to(ACLUsernameChangeTaskStep.class);
- usernameChangeTaskStepMultibinder.addBinding().to(QuotaUsernameChangeTaskStep.class);
-
- Multibinder<DeleteUserDataTaskStep> deleteUserDataTaskStepMultibinder = Multibinder.newSetBinder(binder(), DeleteUserDataTaskStep.class);
- deleteUserDataTaskStepMultibinder.addBinding().to(MailboxUserDeletionTaskStep.class);
- }
-
- @Singleton
- private static class JPAMailboxManagerDefinition extends MailboxManagerDefinition {
- @Inject
- private JPAMailboxManagerDefinition(OpenJPAMailboxManager manager) {
- super("jpa-mailboxmanager", manager);
- }
- }
-}
\ No newline at end of file
diff --git a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java b/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
index 4ef3119e07..2d8d79ec7b 100644
--- a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
+++ b/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresMailboxModule.java
@@ -18,21 +18,136 @@
****************************************************************/
package org.apache.james.modules.mailbox;
+import static org.apache.james.modules.Names.MAILBOXMANAGER_NAME;
+
+import javax.inject.Singleton;
+
+import org.apache.james.adapter.mailbox.ACLUsernameChangeTaskStep;
+import org.apache.james.adapter.mailbox.MailboxUserDeletionTaskStep;
+import org.apache.james.adapter.mailbox.MailboxUsernameChangeTaskStep;
+import org.apache.james.adapter.mailbox.QuotaUsernameChangeTaskStep;
+import org.apache.james.adapter.mailbox.UserRepositoryAuthenticator;
+import org.apache.james.adapter.mailbox.UserRepositoryAuthorizator;
import org.apache.james.backends.postgres.PostgresModule;
+import org.apache.james.events.EventListener;
+import org.apache.james.mailbox.AttachmentContentLoader;
+import org.apache.james.mailbox.Authenticator;
+import org.apache.james.mailbox.Authorizator;
+import org.apache.james.mailbox.MailboxManager;
+import org.apache.james.mailbox.MailboxPathLocker;
+import org.apache.james.mailbox.SessionProvider;
+import org.apache.james.mailbox.SubscriptionManager;
+import org.apache.james.mailbox.acl.MailboxACLResolver;
+import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
+import org.apache.james.mailbox.indexer.ReIndexer;
+import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.postgres.JPAAttachmentContentLoader;
import org.apache.james.mailbox.postgres.PostgresMailboxAggregateModule;
+import org.apache.james.mailbox.postgres.PostgresMailboxId;
+import org.apache.james.mailbox.postgres.PostgresMailboxSessionMapperFactory;
+import org.apache.james.mailbox.postgres.PostgresMessageId;
+import org.apache.james.mailbox.postgres.mail.PostgresMailboxManager;
+import org.apache.james.mailbox.store.MailboxManagerConfiguration;
+import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
+import org.apache.james.mailbox.store.NoMailboxPathLocker;
+import org.apache.james.mailbox.store.SessionProviderImpl;
+import org.apache.james.mailbox.store.StoreMailboxManager;
+import org.apache.james.mailbox.store.StoreSubscriptionManager;
+import org.apache.james.mailbox.store.event.MailboxAnnotationListener;
+import org.apache.james.mailbox.store.event.MailboxSubscriptionListener;
+import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
+import org.apache.james.mailbox.store.mail.MessageMapperFactory;
+import org.apache.james.mailbox.store.mail.NaiveThreadIdGuessingAlgorithm;
+import org.apache.james.mailbox.store.mail.ThreadIdGuessingAlgorithm;
+import org.apache.james.mailbox.store.user.SubscriptionMapperFactory;
+import org.apache.james.modules.BlobMemoryModule;
+import org.apache.james.modules.data.JPAEntityManagerModule;
import org.apache.james.modules.data.PostgresCommonModule;
+import org.apache.james.user.api.DeleteUserDataTaskStep;
+import org.apache.james.user.api.UsernameChangeTaskStep;
+import org.apache.james.utils.MailboxManagerDefinition;
+import org.apache.mailbox.tools.indexer.ReIndexerImpl;
import com.google.inject.AbstractModule;
+import com.google.inject.Inject;
+import com.google.inject.Scopes;
import com.google.inject.multibindings.Multibinder;
+import com.google.inject.name.Names;
public class PostgresMailboxModule extends AbstractModule {
@Override
protected void configure() {
install(new PostgresCommonModule());
+ install(new BlobMemoryModule());
Multibinder<PostgresModule> postgresDataDefinitions = Multibinder.newSetBinder(binder(), PostgresModule.class);
postgresDataDefinitions.addBinding().toInstance(PostgresMailboxAggregateModule.MODULE);
+
+ install(new PostgresQuotaModule());
+ install(new JPAQuotaSearchModule());
+ install(new JPAEntityManagerModule());
+
+ bind(PostgresMailboxSessionMapperFactory.class).in(Scopes.SINGLETON);
+ bind(PostgresMailboxManager.class).in(Scopes.SINGLETON);
+ bind(NoMailboxPathLocker.class).in(Scopes.SINGLETON);
+ bind(StoreSubscriptionManager.class).in(Scopes.SINGLETON);
+ bind(UserRepositoryAuthenticator.class).in(Scopes.SINGLETON);
+ bind(UserRepositoryAuthorizator.class).in(Scopes.SINGLETON);
+ bind(UnionMailboxACLResolver.class).in(Scopes.SINGLETON);
+ bind(PostgresMessageId.Factory.class).in(Scopes.SINGLETON);
+ bind(NaiveThreadIdGuessingAlgorithm.class).in(Scopes.SINGLETON);
+ bind(ReIndexerImpl.class).in(Scopes.SINGLETON);
+ bind(SessionProviderImpl.class).in(Scopes.SINGLETON);
+
+ bind(SubscriptionMapperFactory.class).to(PostgresMailboxSessionMapperFactory.class);
+ bind(MessageMapperFactory.class).to(PostgresMailboxSessionMapperFactory.class);
+ bind(MailboxMapperFactory.class).to(PostgresMailboxSessionMapperFactory.class);
+ bind(MailboxSessionMapperFactory.class).to(PostgresMailboxSessionMapperFactory.class);
+ bind(MessageId.Factory.class).to(PostgresMessageId.Factory.class);
+ bind(ThreadIdGuessingAlgorithm.class).to(NaiveThreadIdGuessingAlgorithm.class);
+
+ bind(SubscriptionManager.class).to(StoreSubscriptionManager.class);
+ bind(MailboxPathLocker.class).to(NoMailboxPathLocker.class);
+ bind(Authenticator.class).to(UserRepositoryAuthenticator.class);
+ bind(MailboxManager.class).to(PostgresMailboxManager.class);
+ bind(StoreMailboxManager.class).to(PostgresMailboxManager.class);
+ bind(SessionProvider.class).to(SessionProviderImpl.class);
+ bind(Authorizator.class).to(UserRepositoryAuthorizator.class);
+ bind(MailboxId.Factory.class).to(PostgresMailboxId.Factory.class);
+ bind(MailboxACLResolver.class).to(UnionMailboxACLResolver.class);
+ bind(AttachmentContentLoader.class).to(JPAAttachmentContentLoader.class);
+
+ bind(ReIndexer.class).to(ReIndexerImpl.class);
+
+ Multibinder.newSetBinder(binder(), MailboxManagerDefinition.class).addBinding().to(PostgresMailboxManagerDefinition.class);
+
+ Multibinder.newSetBinder(binder(), EventListener.GroupEventListener.class)
+ .addBinding()
+ .to(MailboxAnnotationListener.class);
+
+ Multibinder.newSetBinder(binder(), EventListener.GroupEventListener.class)
+ .addBinding()
+ .to(MailboxSubscriptionListener.class);
+
+ bind(MailboxManager.class).annotatedWith(Names.named(MAILBOXMANAGER_NAME)).to(MailboxManager.class);
+ bind(MailboxManagerConfiguration.class).toInstance(MailboxManagerConfiguration.DEFAULT);
+
+ Multibinder<UsernameChangeTaskStep> usernameChangeTaskStepMultibinder = Multibinder.newSetBinder(binder(), UsernameChangeTaskStep.class);
+ usernameChangeTaskStepMultibinder.addBinding().to(MailboxUsernameChangeTaskStep.class);
+ usernameChangeTaskStepMultibinder.addBinding().to(ACLUsernameChangeTaskStep.class);
+ usernameChangeTaskStepMultibinder.addBinding().to(QuotaUsernameChangeTaskStep.class);
+
+ Multibinder<DeleteUserDataTaskStep> deleteUserDataTaskStepMultibinder = Multibinder.newSetBinder(binder(), DeleteUserDataTaskStep.class);
+ deleteUserDataTaskStepMultibinder.addBinding().to(MailboxUserDeletionTaskStep.class);
}
+ @Singleton
+ private static class PostgresMailboxManagerDefinition extends MailboxManagerDefinition {
+ @Inject
+ private PostgresMailboxManagerDefinition(PostgresMailboxManager manager) {
+ super("postgres-mailboxmanager", manager);
+ }
+ }
}
\ No newline at end of file
diff --git a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/JpaQuotaModule.java b/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresQuotaModule.java
similarity index 91%
rename from server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/JpaQuotaModule.java
rename to server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresQuotaModule.java
index 49faa41820..8815b27812 100644
--- a/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/JpaQuotaModule.java
+++ b/server/container/guice/mailbox-postgres/src/main/java/org/apache/james/modules/mailbox/PostgresQuotaModule.java
@@ -21,7 +21,7 @@ package org.apache.james.modules.mailbox;
import org.apache.james.events.EventListener;
import org.apache.james.mailbox.postgres.quota.JPAPerUserMaxQuotaManager;
-import org.apache.james.mailbox.postgres.quota.JpaCurrentQuotaManager;
+import org.apache.james.mailbox.postgres.quota.PostgresCurrentQuotaManager;
import org.apache.james.mailbox.quota.CurrentQuotaManager;
import org.apache.james.mailbox.quota.MaxQuotaManager;
import org.apache.james.mailbox.quota.QuotaManager;
@@ -37,21 +37,21 @@ import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
import com.google.inject.multibindings.Multibinder;
-public class JpaQuotaModule extends AbstractModule {
+public class PostgresQuotaModule extends AbstractModule {
@Override
protected void configure() {
bind(DefaultUserQuotaRootResolver.class).in(Scopes.SINGLETON);
bind(JPAPerUserMaxQuotaManager.class).in(Scopes.SINGLETON);
bind(StoreQuotaManager.class).in(Scopes.SINGLETON);
- bind(JpaCurrentQuotaManager.class).in(Scopes.SINGLETON);
+ bind(PostgresCurrentQuotaManager.class).in(Scopes.SINGLETON);
bind(UserQuotaRootResolver.class).to(DefaultUserQuotaRootResolver.class);
bind(QuotaRootResolver.class).to(DefaultUserQuotaRootResolver.class);
bind(QuotaRootDeserializer.class).to(DefaultUserQuotaRootResolver.class);
bind(MaxQuotaManager.class).to(JPAPerUserMaxQuotaManager.class);
bind(QuotaManager.class).to(StoreQuotaManager.class);
- bind(CurrentQuotaManager.class).to(JpaCurrentQuotaManager.class);
+ bind(CurrentQuotaManager.class).to(PostgresCurrentQuotaManager.class);
bind(ListeningCurrentQuotaUpdater.class).in(Scopes.SINGLETON);
bind(QuotaUpdater.class).to(ListeningCurrentQuotaUpdater.class);
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org