You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2018/03/23 09:26:55 UTC
[1/9] james-project git commit: JAMES-2352 Add missing persistence
information for Domain quota over Guice
Repository: james-project
Updated Branches:
refs/heads/master e8c47ab1a -> 336d1f94b
JAMES-2352 Add missing persistence information for Domain quota over Guice
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5ab99229
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5ab99229
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5ab99229
Branch: refs/heads/master
Commit: 5ab992298814161bd7c090f5d861254adbd25e5d
Parents: e8c47ab
Author: benwa <bt...@linagora.com>
Authored: Wed Mar 21 09:48:47 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Mar 23 16:24:52 2018 +0700
----------------------------------------------------------------------
.../guice/jpa-guice/src/main/resources/META-INF/persistence.xml | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/5ab99229/server/container/guice/jpa-guice/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/main/resources/META-INF/persistence.xml b/server/container/guice/jpa-guice/src/main/resources/META-INF/persistence.xml
index 180c26a..cd761a3 100644
--- a/server/container/guice/jpa-guice/src/main/resources/META-INF/persistence.xml
+++ b/server/container/guice/jpa-guice/src/main/resources/META-INF/persistence.xml
@@ -39,6 +39,8 @@
<class>org.apache.james.mailbox.jpa.quota.model.MaxGlobalStorage</class>
<class>org.apache.james.mailbox.jpa.quota.model.MaxUserMessageCount</class>
<class>org.apache.james.mailbox.jpa.quota.model.MaxUserStorage</class>
+ <class>org.apache.james.mailbox.jpa.quota.model.MaxDomainStorage</class>
+ <class>org.apache.james.mailbox.jpa.quota.model.MaxDomainMessageCount</class>
<class>org.apache.james.mailbox.jpa.quota.model.JpaCurrentQuota</class>
<properties>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[8/9] james-project git commit: JAMES-2352 Add a JPA integration test
about quota
Posted by bt...@apache.org.
JAMES-2352 Add a JPA integration test about quota
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/e35540d1
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/e35540d1
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/e35540d1
Branch: refs/heads/master
Commit: e35540d10d2ced70a8d8c59f2fe25495df0060bf
Parents: 20bc8a7
Author: benwa <bt...@linagora.com>
Authored: Wed Mar 21 09:48:36 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Mar 23 16:25:48 2018 +0700
----------------------------------------------------------------------
.../apache/james/AbstractJamesServerTest.java | 2 +-
server/container/guice/jpa-guice/pom.xml | 5 ++
.../org/apache/james/JPAJamesServerTest.java | 51 +++++++++++++++++++-
.../apache/james/utils/IMAPMessageReader.java | 5 ++
4 files changed, 61 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/e35540d1/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java
index 0e21021..b2dd541 100644
--- a/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java
+++ b/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java
@@ -40,7 +40,7 @@ public abstract class AbstractJamesServerTest {
private static final int SMTP_PORT = 1025;
private static final int LMTP_PORT = 1024;
- private GuiceJamesServer server;
+ protected GuiceJamesServer server;
private SocketChannel socketChannel;
@Before
http://git-wip-us.apache.org/repos/asf/james-project/blob/e35540d1/server/container/guice/jpa-guice/pom.xml
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/pom.xml b/server/container/guice/jpa-guice/pom.xml
index 1df58c1..82fbebf 100644
--- a/server/container/guice/jpa-guice/pom.xml
+++ b/server/container/guice/jpa-guice/pom.xml
@@ -128,6 +128,11 @@
<artifactId>james-server-jpa-common-guice</artifactId>
</dependency>
<dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>james-server-testing</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/e35540d1/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
index 00f1507..53318ca 100644
--- a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
+++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java
@@ -19,14 +19,43 @@
package org.apache.james;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.quota.QuotaSize;
+import org.apache.james.mailbox.store.mail.model.SerializableQuotaValue;
+import org.apache.james.modules.QuotaProbesImpl;
import org.apache.james.modules.TestFilesystemModule;
+import org.apache.james.utils.DataProbeImpl;
+import org.apache.james.utils.IMAPMessageReader;
+import org.apache.james.utils.SMTPMessageSender;
import org.junit.Rule;
+import org.junit.Test;
import org.junit.rules.TemporaryFolder;
+import com.google.common.base.Strings;
+import com.jayway.awaitility.Awaitility;
+import com.jayway.awaitility.Duration;
+import com.jayway.awaitility.core.ConditionFactory;
+
public class JPAJamesServerTest extends AbstractJamesServerTest {
+ private static final ConditionFactory AWAIT = Awaitility.await()
+ .atMost(Duration.ONE_MINUTE)
+ .with()
+ .pollInterval(Duration.FIVE_HUNDRED_MILLISECONDS);
+ private static final String DOMAIN = "james.local";
+ private static final String USER = "toto@" + DOMAIN;
+ private static final String PASSWORD = "123456";
+ private static final String LOCALHOST = "127.0.0.1";
+ private static final int SMTP_PORT = 1025;
+ private static final int IMAP_PORT = 1143;
+
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @Rule
+ public IMAPMessageReader imapMessageReader = new IMAPMessageReader();
+ @Rule
+ public SMTPMessageSender smtpMessageSender = new SMTPMessageSender(DOMAIN);
@Override
protected GuiceJamesServer createJamesServer() {
@@ -39,6 +68,26 @@ public class JPAJamesServerTest extends AbstractJamesServerTest {
@Override
protected void clean() {
}
-
+
+ @Test
+ public void jpaGuiceServerShouldUpdateQuota() throws Exception {
+ DataProbeImpl dataProbe = server.getProbe(DataProbeImpl.class);
+ dataProbe.addDomain(DOMAIN);
+ dataProbe.addUser(USER, PASSWORD);
+ server.getProbe(QuotaProbesImpl.class).setGlobalMaxStorage(new SerializableQuotaValue<>(QuotaSize.size(50 * 1024)));
+
+ // ~ 12 KB email
+ smtpMessageSender.connect(LOCALHOST, SMTP_PORT)
+ .sendMessageWithHeaders(USER, USER, "header: toto\\r\\n\\r\\n" + Strings.repeat("0123456789\n", 1024))
+ .awaitSent(AWAIT);
+
+ assertThat(
+ imapMessageReader.connect(LOCALHOST, IMAP_PORT)
+ .login(USER, PASSWORD)
+ .getQuotaRoot(IMAPMessageReader.INBOX))
+ .isEqualTo("* QUOTAROOT \"INBOX\" #private&toto@james.local\r\n" +
+ "* QUOTA #private&toto@james.local (STORAGE 12 50)\r\n" +
+ "AAAB OK GETQUOTAROOT completed.\r\n");
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/e35540d1/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
----------------------------------------------------------------------
diff --git a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
index 258157c..5912cf3 100644
--- a/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
+++ b/server/testing/src/main/java/org/apache/james/utils/IMAPMessageReader.java
@@ -176,4 +176,9 @@ public class IMAPMessageReader extends ExternalResource implements Closeable {
public void expunge() throws IOException {
imapClient.expunge();
}
+
+ public String getQuotaRoot(String mailbox) throws IOException {
+ imapClient.sendCommand("GETQUOTAROOT " + mailbox);
+ return imapClient.getReplyString();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[4/9] james-project git commit: MAILBOX-325 Logging failed
transactions
Posted by bt...@apache.org.
MAILBOX-325 Logging failed transactions
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/336d1f94
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/336d1f94
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/336d1f94
Branch: refs/heads/master
Commit: 336d1f94bac006cfe871fcec2c9094e2141bee44
Parents: 157d070
Author: benwa <bt...@linagora.com>
Authored: Thu Mar 22 09:47:52 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Mar 23 16:25:48 2018 +0700
----------------------------------------------------------------------
backends-common/jpa/pom.xml | 4 ++++
.../java/org/apache/james/backends/jpa/TransactionRunner.java | 6 ++++++
2 files changed, 10 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/336d1f94/backends-common/jpa/pom.xml
----------------------------------------------------------------------
diff --git a/backends-common/jpa/pom.xml b/backends-common/jpa/pom.xml
index dbab212..6587c5d 100644
--- a/backends-common/jpa/pom.xml
+++ b/backends-common/jpa/pom.xml
@@ -29,5 +29,9 @@
<artifactId>openjpa</artifactId>
<version>2.4.2</version>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
</dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/james-project/blob/336d1f94/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
----------------------------------------------------------------------
diff --git a/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java b/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
index 71299c4..0b3c914 100644
--- a/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
+++ b/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
@@ -26,8 +26,13 @@ import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
public class TransactionRunner {
+ private static final Logger LOGGER = LoggerFactory.getLogger(TransactionRunner.class);
+
private final EntityManagerFactory entityManagerFactory;
public TransactionRunner(EntityManagerFactory entityManagerFactory) {
@@ -42,6 +47,7 @@ public class TransactionRunner {
runnable.accept(entityManager);
transaction.commit();
} catch (PersistenceException e) {
+ LOGGER.warn("Could not execute transaction", e);
if (transaction.isActive()) {
transaction.rollback();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[7/9] james-project git commit: JAMES-2360 Solve some intelliJ
warnings
Posted by bt...@apache.org.
JAMES-2360 Solve some intelliJ warnings
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/157d0707
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/157d0707
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/157d0707
Branch: refs/heads/master
Commit: 157d07075792188baec3c350cca2a8c8702d6487
Parents: 47e7365
Author: benwa <bt...@linagora.com>
Authored: Wed Mar 21 13:26:34 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Mar 23 16:25:48 2018 +0700
----------------------------------------------------------------------
.../java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/157d0707/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java
index fd34a55..26682bc 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/JPAMailboxFixture.java
@@ -40,7 +40,7 @@ import com.google.common.collect.ImmutableList;
public interface JPAMailboxFixture {
- List<Class<?>> MAILBOX_PERSISTANCE_CLASSES = ImmutableList.<Class<?>>of(
+ List<Class<?>> MAILBOX_PERSISTANCE_CLASSES = ImmutableList.of(
JPAMailbox.class,
AbstractJPAMailboxMessage.class,
JPAMailboxMessage.class,
@@ -50,7 +50,7 @@ public interface JPAMailboxFixture {
JPASubscription.class
);
- List<Class<?>> QUOTA_PERSISTANCE_CLASSES = ImmutableList.<Class<?>>of(
+ List<Class<?>> QUOTA_PERSISTANCE_CLASSES = ImmutableList.of(
MaxGlobalMessageCount.class,
MaxGlobalStorage.class,
MaxDomainStorage.class,
@@ -60,7 +60,7 @@ public interface JPAMailboxFixture {
JpaCurrentQuota.class
);
- List<String> MAILBOX_TABLE_NAMES = ImmutableList.<String>of(
+ List<String> MAILBOX_TABLE_NAMES = ImmutableList.of(
"JAMES_MAIL_USERFLAG",
"JAMES_MAIL_PROPERTY",
"JAMES_MAILBOX_ANNOTATION",
@@ -68,7 +68,7 @@ public interface JPAMailboxFixture {
"JAMES_MAIL",
"JAMES_SUBSCRIPTION");
- List<String> QUOTA_TABLES_NAMES = ImmutableList.<String>of(
+ List<String> QUOTA_TABLES_NAMES = ImmutableList.of(
"JAMES_MAX_GLOBAL_MESSAGE_COUNT",
"JAMES_MAX_GLOBAL_STORAGE",
"JAMES_MAX_USER_MESSAGE_COUNT",
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[9/9] james-project git commit: JAMES-2360 Avoid
ComposedMessageId::toString call to throw when using JPA
Posted by bt...@apache.org.
JAMES-2360 Avoid ComposedMessageId::toString call to throw when using JPA
This error was for instance thrown due to logging at the end of LocalDelivery
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/12c50052
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/12c50052
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/12c50052
Branch: refs/heads/master
Commit: 12c500521ea0a3106c494d90252ec6c215b8f316
Parents: e35540d
Author: benwa <bt...@linagora.com>
Authored: Wed Mar 21 10:01:13 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Mar 23 16:25:48 2018 +0700
----------------------------------------------------------------------
.../store/mail/model/DefaultMessageId.java | 5 +++
.../store/mail/model/DefaultMessageIdTest.java | 39 ++++++++++++++++++++
2 files changed, 44 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/12c50052/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java
index 38a7ce0..51fff2d 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DefaultMessageId.java
@@ -35,4 +35,9 @@ public class DefaultMessageId implements MessageId {
public final int hashCode() {
throw new IllegalStateException("Capabilities should prevent calling this method");
}
+
+ @Override
+ public String toString() {
+ return "DefaultMessageId{}";
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/12c50052/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java
new file mode 100644
index 0000000..3ae48e9
--- /dev/null
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/DefaultMessageIdTest.java
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.store.mail.model;
+
+import org.apache.james.mailbox.MessageUid;
+import org.apache.james.mailbox.model.ComposedMessageId;
+import org.apache.james.mailbox.model.TestId;
+import org.junit.Test;
+
+public class DefaultMessageIdTest {
+
+ @Test
+ public void composedMessageIdToStringCallShouldNotThrowWhenUsingDefaultMessageId() {
+ ComposedMessageId composedMessageId = new ComposedMessageId(
+ TestId.of(52),
+ new DefaultMessageId(),
+ MessageUid.of(23));
+
+ composedMessageId.toString();
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[2/9] james-project git commit: JAMES-2360 Correctly initialize JPA
quota system
Posted by bt...@apache.org.
JAMES-2360 Correctly initialize JPA quota system
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/35642ad9
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/35642ad9
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/35642ad9
Branch: refs/heads/master
Commit: 35642ad9be51442104eb06602b789a8c2001d533
Parents: f186549
Author: benwa <bt...@linagora.com>
Authored: Wed Mar 21 09:49:14 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Mar 23 16:24:53 2018 +0700
----------------------------------------------------------------------
.../org/apache/james/modules/mailbox/JPAMailboxModule.java | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/35642ad9/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java
index c7c57fb..896a1a9 100644
--- a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java
+++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java
@@ -46,6 +46,8 @@ import org.apache.james.mailbox.jpa.mail.JPAUidProvider;
import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.quota.QuotaManager;
+import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.Authenticator;
import org.apache.james.mailbox.store.Authorizator;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
@@ -55,6 +57,7 @@ import org.apache.james.mailbox.store.mail.MessageMapperFactory;
import org.apache.james.mailbox.store.mail.ModSeqProvider;
import org.apache.james.mailbox.store.mail.UidProvider;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
+import org.apache.james.mailbox.store.quota.ListeningCurrentQuotaUpdater;
import org.apache.james.modules.Names;
import org.apache.james.utils.MailboxManagerDefinition;
import org.apache.james.utils.PropertiesProvider;
@@ -107,7 +110,11 @@ public class JPAMailboxModule extends AbstractModule {
@Provides
@Named(Names.MAILBOXMANAGER_NAME)
@Singleton
- public MailboxManager provideMailboxManager(OpenJPAMailboxManager jpaMailboxManager) throws MailboxException {
+ public MailboxManager provideMailboxManager(OpenJPAMailboxManager jpaMailboxManager, ListeningCurrentQuotaUpdater quotaUpdater,
+ QuotaManager quotaManager, QuotaRootResolver quotaRootResolver) throws MailboxException {
+ jpaMailboxManager.setQuotaRootResolver(quotaRootResolver);
+ jpaMailboxManager.setQuotaManager(quotaManager);
+ jpaMailboxManager.setQuotaUpdater(quotaUpdater);
jpaMailboxManager.init();
return jpaMailboxManager;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[6/9] james-project git commit: JAMES-2360 Solve a JPA warning
Posted by bt...@apache.org.
JAMES-2360 Solve a JPA warning
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/47e73655
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/47e73655
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/47e73655
Branch: refs/heads/master
Commit: 47e7365538363df81642777c718ed7593398a3b9
Parents: 12c5005
Author: benwa <bt...@linagora.com>
Authored: Wed Mar 21 13:26:15 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Mar 23 16:25:48 2018 +0700
----------------------------------------------------------------------
.../james/mailbox/jpa/mail/model/JPAMailboxAnnotationId.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/47e73655/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotationId.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotationId.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotationId.java
index 6bbdbd2..1fcc712 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotationId.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotationId.java
@@ -19,12 +19,14 @@
package org.apache.james.mailbox.jpa.mail.model;
+import java.io.Serializable;
+
import javax.persistence.Embeddable;
import com.google.common.base.Objects;
@Embeddable
-public final class JPAMailboxAnnotationId {
+public final class JPAMailboxAnnotationId implements Serializable {
private long mailboxId;
private String key;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[3/9] james-project git commit: JAMES-2352 Add missing persistence
information for Domain quota over Spring
Posted by bt...@apache.org.
JAMES-2352 Add missing persistence information for Domain quota over Spring
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f1865497
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f1865497
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f1865497
Branch: refs/heads/master
Commit: f1865497e21ef5eb2899589d8b8c7cc971044615
Parents: 5ab9922
Author: benwa <bt...@linagora.com>
Authored: Wed Mar 21 09:52:25 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Mar 23 16:24:53 2018 +0700
----------------------------------------------------------------------
server/app/src/main/resources/META-INF/persistence.xml | 2 ++
1 file changed, 2 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1865497/server/app/src/main/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/server/app/src/main/resources/META-INF/persistence.xml b/server/app/src/main/resources/META-INF/persistence.xml
index 5dc253d..34eae79 100644
--- a/server/app/src/main/resources/META-INF/persistence.xml
+++ b/server/app/src/main/resources/META-INF/persistence.xml
@@ -39,6 +39,8 @@
<class>org.apache.james.mailbox.jpa.quota.model.MaxGlobalStorage</class>
<class>org.apache.james.mailbox.jpa.quota.model.MaxUserMessageCount</class>
<class>org.apache.james.mailbox.jpa.quota.model.MaxUserStorage</class>
+ <class>org.apache.james.mailbox.jpa.quota.model.MaxDomainStorage</class>
+ <class>org.apache.james.mailbox.jpa.quota.model.MaxDomainMessageCount</class>
<class>org.apache.james.mailbox.jpa.quota.model.JpaCurrentQuota</class>
<properties>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[5/9] james-project git commit: MAILBOX-325 Fix Current quota
implementation problems
Posted by bt...@apache.org.
MAILBOX-325 Fix Current quota implementation problems
- Use a per request entity manager (common JPA practice in James)
- Transact these quota operations
- Slightly enhance code quality
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/20bc8a7b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/20bc8a7b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/20bc8a7b
Branch: refs/heads/master
Commit: 20bc8a7ba684074bcf0df4069da06a7b5f47a445
Parents: 35642ad
Author: benwa <bt...@linagora.com>
Authored: Wed Mar 21 09:51:54 2018 +0700
Committer: benwa <bt...@linagora.com>
Committed: Fri Mar 23 16:25:48 2018 +0700
----------------------------------------------------------------------
.../james/backends/jpa/TransactionRunner.java | 53 +++++++++++++
.../jpa/quota/JPAPerUserMaxQuotaDAO.java | 79 ++++++++++++--------
.../jpa/quota/JpaCurrentQuotaManager.java | 62 ++++++++-------
.../jpa/quota/model/JpaCurrentQuota.java | 20 ++++-
4 files changed, 150 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/20bc8a7b/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
----------------------------------------------------------------------
diff --git a/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java b/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
new file mode 100644
index 0000000..71299c4
--- /dev/null
+++ b/backends-common/jpa/src/main/java/org/apache/james/backends/jpa/TransactionRunner.java
@@ -0,0 +1,53 @@
+/****************************************************************
+ * 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.backends.jpa;
+
+import java.util.function.Consumer;
+
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.EntityTransaction;
+import javax.persistence.PersistenceException;
+
+public class TransactionRunner {
+
+ private final EntityManagerFactory entityManagerFactory;
+
+ public TransactionRunner(EntityManagerFactory entityManagerFactory) {
+ this.entityManagerFactory = entityManagerFactory;
+ }
+
+ public void run(Consumer<EntityManager> runnable) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ EntityTransaction transaction = entityManager.getTransaction();
+ try {
+ transaction.begin();
+ runnable.accept(entityManager);
+ transaction.commit();
+ } catch (PersistenceException e) {
+ if (transaction.isActive()) {
+ transaction.rollback();
+ }
+ } finally {
+ entityManager.close();
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/20bc8a7b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaDAO.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaDAO.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaDAO.java
index 79b0932..27dfec9 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaDAO.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JPAPerUserMaxQuotaDAO.java
@@ -26,6 +26,7 @@ import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
+import org.apache.james.backends.jpa.TransactionRunner;
import org.apache.james.mailbox.jpa.quota.model.MaxDomainMessageCount;
import org.apache.james.mailbox.jpa.quota.model.MaxDomainStorage;
import org.apache.james.mailbox.jpa.quota.model.MaxGlobalMessageCount;
@@ -40,21 +41,24 @@ import org.apache.james.mailbox.quota.QuotaValue;
public class JPAPerUserMaxQuotaDAO {
private static final long INFINITE = -1;
- private final EntityManager entityManager;
+ private final EntityManagerFactory entityManagerFactory;
+ private final TransactionRunner transactionRunner;
@Inject
public JPAPerUserMaxQuotaDAO(EntityManagerFactory entityManagerFactory) {
- entityManager = entityManagerFactory.createEntityManager();
+ this.entityManagerFactory = entityManagerFactory;
+ this.transactionRunner = new TransactionRunner(entityManagerFactory);
}
public void setMaxStorage(QuotaRoot quotaRoot, Optional<QuotaSize> maxStorageQuota) {
- entityManager.getTransaction().begin();
- MaxUserStorage storedValue = getMaxUserStorageEntity(quotaRoot, maxStorageQuota);
- entityManager.persist(storedValue);
- entityManager.getTransaction().commit();
+ transactionRunner.run(
+ entityManager -> {
+ MaxUserStorage storedValue = getMaxUserStorageEntity(entityManager, quotaRoot, maxStorageQuota);
+ entityManager.persist(storedValue);
+ });
}
- private MaxUserStorage getMaxUserStorageEntity(QuotaRoot quotaRoot, Optional<QuotaSize> maxStorageQuota) {
+ private MaxUserStorage getMaxUserStorageEntity(EntityManager entityManager, QuotaRoot quotaRoot, Optional<QuotaSize> maxStorageQuota) {
MaxUserStorage storedValue = entityManager.find(MaxUserStorage.class, quotaRoot.getValue());
Long value = quotaValueToLong(maxStorageQuota);
if (storedValue == null) {
@@ -65,13 +69,14 @@ public class JPAPerUserMaxQuotaDAO {
}
public void setMaxMessage(QuotaRoot quotaRoot, Optional<QuotaCount> maxMessageCount) {
- entityManager.getTransaction().begin();
- MaxUserMessageCount storedValue = getMaxUserMessageEntity(quotaRoot, maxMessageCount);
- entityManager.persist(storedValue);
- entityManager.getTransaction().commit();
+ transactionRunner.run(
+ entityManager -> {
+ MaxUserMessageCount storedValue = getMaxUserMessageEntity(entityManager, quotaRoot, maxMessageCount);
+ entityManager.persist(storedValue);
+ });
}
- private MaxUserMessageCount getMaxUserMessageEntity(QuotaRoot quotaRoot, Optional<QuotaCount> maxMessageQuota) {
+ private MaxUserMessageCount getMaxUserMessageEntity(EntityManager entityManager, QuotaRoot quotaRoot, Optional<QuotaCount> maxMessageQuota) {
MaxUserMessageCount storedValue = entityManager.find(MaxUserMessageCount.class, quotaRoot.getValue());
Long value = quotaValueToLong(maxMessageQuota);
if (storedValue == null) {
@@ -82,21 +87,23 @@ public class JPAPerUserMaxQuotaDAO {
}
public void setDomainMaxMessage(String domain, Optional<QuotaCount> count) {
- entityManager.getTransaction().begin();
- MaxDomainMessageCount storedValue = getMaxDomainMessageEntity(domain, count);
- entityManager.persist(storedValue);
- entityManager.getTransaction().commit();
+ transactionRunner.run(
+ entityManager -> {
+ MaxDomainMessageCount storedValue = getMaxDomainMessageEntity(entityManager, domain, count);
+ entityManager.persist(storedValue);
+ });
}
public void setDomainMaxStorage(String domain, Optional<QuotaSize> size) {
- entityManager.getTransaction().begin();
- MaxDomainStorage storedValue = getMaxDomainStorageEntity(domain, size);
- entityManager.persist(storedValue);
- entityManager.getTransaction().commit();
+ transactionRunner.run(
+ entityManager -> {
+ MaxDomainStorage storedValue = getMaxDomainStorageEntity(entityManager, domain, size);
+ entityManager.persist(storedValue);
+ });
}
- private MaxDomainMessageCount getMaxDomainMessageEntity(String domain, Optional<QuotaCount> maxMessageQuota) {
+ private MaxDomainMessageCount getMaxDomainMessageEntity(EntityManager entityManager, String domain, Optional<QuotaCount> maxMessageQuota) {
MaxDomainMessageCount storedValue = entityManager.find(MaxDomainMessageCount.class, domain);
Long value = quotaValueToLong(maxMessageQuota);
if (storedValue == null) {
@@ -106,7 +113,7 @@ public class JPAPerUserMaxQuotaDAO {
return storedValue;
}
- private MaxDomainStorage getMaxDomainStorageEntity(String domain, Optional<QuotaSize> maxStorageQuota) {
+ private MaxDomainStorage getMaxDomainStorageEntity(EntityManager entityManager, String domain, Optional<QuotaSize> maxStorageQuota) {
MaxDomainStorage storedValue = entityManager.find(MaxDomainStorage.class, domain);
Long value = quotaValueToLong(maxStorageQuota);
if (storedValue == null) {
@@ -118,13 +125,14 @@ public class JPAPerUserMaxQuotaDAO {
public void setGlobalMaxStorage(Optional<QuotaSize> globalMaxStorage) {
- entityManager.getTransaction().begin();
- MaxGlobalStorage globalMaxStorageEntity = getGlobalMaxStorageEntity(globalMaxStorage);
- entityManager.persist(globalMaxStorageEntity);
- entityManager.getTransaction().commit();
+ transactionRunner.run(
+ entityManager -> {
+ MaxGlobalStorage globalMaxStorageEntity = getGlobalMaxStorageEntity(entityManager, globalMaxStorage);
+ entityManager.persist(globalMaxStorageEntity);
+ });
}
- private MaxGlobalStorage getGlobalMaxStorageEntity(Optional<QuotaSize> maxSizeQuota) {
+ private MaxGlobalStorage getGlobalMaxStorageEntity(EntityManager entityManager, Optional<QuotaSize> maxSizeQuota) {
MaxGlobalStorage storedValue = entityManager.find(MaxGlobalStorage.class, MaxGlobalStorage.DEFAULT_KEY);
Long value = quotaValueToLong(maxSizeQuota);
if (storedValue == null) {
@@ -135,13 +143,14 @@ public class JPAPerUserMaxQuotaDAO {
}
public void setGlobalMaxMessage(Optional<QuotaCount> globalMaxMessageCount) {
- entityManager.getTransaction().begin();
- MaxGlobalMessageCount globalMaxMessageEntity = getGlobalMaxMessageEntity(globalMaxMessageCount);
- entityManager.persist(globalMaxMessageEntity);
- entityManager.getTransaction().commit();
+ transactionRunner.run(
+ entityManager -> {
+ MaxGlobalMessageCount globalMaxMessageEntity = getGlobalMaxMessageEntity(entityManager, globalMaxMessageCount);
+ entityManager.persist(globalMaxMessageEntity);
+ });
}
- private MaxGlobalMessageCount getGlobalMaxMessageEntity(Optional<QuotaCount> maxMessageQuota) {
+ private MaxGlobalMessageCount getGlobalMaxMessageEntity(EntityManager entityManager, Optional<QuotaCount> maxMessageQuota) {
MaxGlobalMessageCount storedValue = entityManager.find(MaxGlobalMessageCount.class, MaxGlobalMessageCount.DEFAULT_KEY);
Long value = quotaValueToLong(maxMessageQuota);
if (storedValue == null) {
@@ -152,6 +161,7 @@ public class JPAPerUserMaxQuotaDAO {
}
public Optional<QuotaSize> getGlobalMaxStorage() {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
MaxGlobalStorage storedValue = entityManager.find(MaxGlobalStorage.class, MaxGlobalStorage.DEFAULT_KEY);
if (storedValue == null) {
return Optional.empty();
@@ -160,6 +170,7 @@ public class JPAPerUserMaxQuotaDAO {
}
public Optional<QuotaCount> getGlobalMaxMessage() {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
MaxGlobalMessageCount storedValue = entityManager.find(MaxGlobalMessageCount.class, MaxGlobalMessageCount.DEFAULT_KEY);
if (storedValue == null) {
return Optional.empty();
@@ -168,6 +179,7 @@ public class JPAPerUserMaxQuotaDAO {
}
public Optional<QuotaSize> getMaxStorage(QuotaRoot quotaRoot) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
MaxUserStorage storedValue = entityManager.find(MaxUserStorage.class, quotaRoot.getValue());
if (storedValue == null) {
return Optional.empty();
@@ -176,6 +188,7 @@ public class JPAPerUserMaxQuotaDAO {
}
public Optional<QuotaCount> getMaxMessage(QuotaRoot quotaRoot) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
MaxUserMessageCount storedValue = entityManager.find(MaxUserMessageCount.class, quotaRoot.getValue());
if (storedValue == null) {
return Optional.empty();
@@ -184,6 +197,7 @@ public class JPAPerUserMaxQuotaDAO {
}
public Optional<QuotaCount> getDomainMaxMessage(String domain) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
MaxDomainMessageCount storedValue = entityManager.find(MaxDomainMessageCount.class, domain);
if (storedValue == null) {
return Optional.empty();
@@ -192,6 +206,7 @@ public class JPAPerUserMaxQuotaDAO {
}
public Optional<QuotaSize> getDomainMaxStorage(String domain) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
MaxDomainStorage storedValue = entityManager.find(MaxDomainStorage.class, domain);
if (storedValue == null) {
return Optional.empty();
http://git-wip-us.apache.org/repos/asf/james-project/blob/20bc8a7b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JpaCurrentQuotaManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JpaCurrentQuotaManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JpaCurrentQuotaManager.java
index 5a19da5..a8f2c54 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JpaCurrentQuotaManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/JpaCurrentQuotaManager.java
@@ -20,10 +20,12 @@
package org.apache.james.mailbox.jpa.quota;
import java.util.Optional;
+
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
+import org.apache.james.backends.jpa.TransactionRunner;
import org.apache.james.mailbox.MailboxListener;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.jpa.quota.model.JpaCurrentQuota;
@@ -39,11 +41,13 @@ public class JpaCurrentQuotaManager implements StoreCurrentQuotaManager {
public static final long NO_MESSAGES = 0L;
public static final long NO_STORED_BYTES = 0L;
- private final EntityManager entityManager;
+ private final EntityManagerFactory entityManagerFactory;
+ private final TransactionRunner transactionRunner;
@Inject
public JpaCurrentQuotaManager(EntityManagerFactory entityManagerFactory) {
- this.entityManager = entityManagerFactory.createEntityManager();
+ this.entityManagerFactory = entityManagerFactory;
+ this.transactionRunner = new TransactionRunner(entityManagerFactory);
}
@Override
@@ -52,36 +56,35 @@ public class JpaCurrentQuotaManager implements StoreCurrentQuotaManager {
}
@Override
- public QuotaCount getCurrentMessageCount(QuotaRoot quotaRoot) throws MailboxException {
- JpaCurrentQuota userQuota = retrieveUserQuota(quotaRoot);
-
- if (userQuota == null) {
- return QuotaCount.count(NO_STORED_BYTES);
- }
- return QuotaCount.count(userQuota.getMessageCount());
+ public QuotaCount getCurrentMessageCount(QuotaRoot quotaRoot) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ return Optional.ofNullable(retrieveUserQuota(entityManager, quotaRoot))
+ .map(JpaCurrentQuota::getMessageCount)
+ .orElse(QuotaCount.count(NO_STORED_BYTES));
}
@Override
- public QuotaSize getCurrentStorage(QuotaRoot quotaRoot) throws MailboxException {
- JpaCurrentQuota userQuota = retrieveUserQuota(quotaRoot);
-
- if (userQuota == null) {
- return QuotaSize.size(NO_STORED_BYTES);
- }
- return QuotaSize.size(userQuota.getSize());
+ public QuotaSize getCurrentStorage(QuotaRoot quotaRoot) {
+ EntityManager entityManager = entityManagerFactory.createEntityManager();
+ return Optional.ofNullable(retrieveUserQuota(entityManager, quotaRoot))
+ .map(JpaCurrentQuota::getSize)
+ .orElse(QuotaSize.size(NO_STORED_BYTES));
}
@Override
- public void increase(QuotaRoot quotaRoot, long count, long size) throws MailboxException {
+ public void increase(QuotaRoot quotaRoot, long count, long size) {
Preconditions.checkArgument(count > 0, "Counts should be positive");
Preconditions.checkArgument(size > 0, "Size should be positive");
- JpaCurrentQuota jpaCurrentQuota = Optional.ofNullable(retrieveUserQuota(quotaRoot))
- .orElse(new JpaCurrentQuota(quotaRoot.getValue(), NO_MESSAGES, NO_STORED_BYTES));
+ transactionRunner.run(
+ entityManager -> {
+ 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() + count,
- jpaCurrentQuota.getSize() + size));
+ entityManager.merge(new JpaCurrentQuota(quotaRoot.getValue(),
+ jpaCurrentQuota.getMessageCount().asLong() + count,
+ jpaCurrentQuota.getSize().asLong() + size));
+ });
}
@Override
@@ -89,15 +92,18 @@ public class JpaCurrentQuotaManager implements StoreCurrentQuotaManager {
Preconditions.checkArgument(count > 0, "Counts should be positive");
Preconditions.checkArgument(size > 0, "Counts should be positive");
- JpaCurrentQuota jpaCurrentQuota = Optional.ofNullable(retrieveUserQuota(quotaRoot))
- .orElse(new JpaCurrentQuota(quotaRoot.getValue(), NO_MESSAGES, NO_STORED_BYTES));
+ transactionRunner.run(
+ entityManager -> {
+ 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() - count,
- jpaCurrentQuota.getSize() - size));
+ entityManager.merge(new JpaCurrentQuota(quotaRoot.getValue(),
+ jpaCurrentQuota.getMessageCount().asLong() - count,
+ jpaCurrentQuota.getSize().asLong() - size));
+ });
}
- private JpaCurrentQuota retrieveUserQuota(QuotaRoot quotaRoot) throws MailboxException {
+ private JpaCurrentQuota retrieveUserQuota(EntityManager entityManager, QuotaRoot quotaRoot) {
return entityManager.find(JpaCurrentQuota.class, quotaRoot.getValue());
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/20bc8a7b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/model/JpaCurrentQuota.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/model/JpaCurrentQuota.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/model/JpaCurrentQuota.java
index 260db9b..0b0a201 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/model/JpaCurrentQuota.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/quota/model/JpaCurrentQuota.java
@@ -24,6 +24,9 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
+import org.apache.james.mailbox.quota.QuotaCount;
+import org.apache.james.mailbox.quota.QuotaSize;
+
@Entity(name = "CurrentQuota")
@Table(name = "JAMES_QUOTA_CURRENTQUOTA")
public class JpaCurrentQuota {
@@ -47,11 +50,20 @@ public class JpaCurrentQuota {
this.size = size;
}
- public long getMessageCount() {
- return messageCount;
+ public QuotaCount getMessageCount() {
+ return QuotaCount.count(messageCount);
+ }
+
+ public QuotaSize getSize() {
+ return QuotaSize.size(size);
}
- public long getSize() {
- return size;
+ @Override
+ public String toString() {
+ return "JpaCurrentQuota{" +
+ "quotaRoot='" + quotaRoot + '\'' +
+ ", messageCount=" + messageCount +
+ ", size=" + size +
+ '}';
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org