james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [08/10] james-project git commit: MAILBOX-270: JPA should support limitation also
Date Thu, 10 Nov 2016 07:34:36 GMT
MAILBOX-270: JPA should support limitation also


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

Branch: refs/heads/master
Commit: d455ab4b99e3c0d0154c06fd760d633f692a8090
Parents: 68fe347
Author: Quynh Nguyen <qnguyen@linagora.com>
Authored: Tue Nov 8 15:10:17 2016 +0700
Committer: Quynh Nguyen <qnguyen@linagora.com>
Committed: Wed Nov 9 11:56:48 2016 +0700

----------------------------------------------------------------------
 .../mailbox/jpa/mail/JPAAnnotationMapper.java   | 24 ++++++++++++++++++--
 .../jpa/mail/model/JPAMailboxAnnotation.java    |  3 ++-
 .../jpa/mail/TransactionalAnnotationMapper.java | 10 ++++++++
 .../mailbox/store/StoreMailboxManager.java      |  2 +-
 4 files changed, 35 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/d455ab4b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAAnnotationMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAAnnotationMapper.java
b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAAnnotationMapper.java
index 0704c9f..3478af0 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAAnnotationMapper.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAAnnotationMapper.java
@@ -26,6 +26,8 @@ import javax.persistence.EntityManagerFactory;
 import javax.persistence.NoResultException;
 import javax.persistence.PersistenceException;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Throwables;
 import org.apache.james.mailbox.jpa.JPAId;
 import org.apache.james.mailbox.jpa.JPATransactionalMapper;
 import org.apache.james.mailbox.jpa.mail.model.JPAMailboxAnnotation;
@@ -162,13 +164,12 @@ public class JPAAnnotationMapper extends JPATransactionalMapper implements
Annot
         } catch (NoResultException e) {
             LOGGER.debug("Mailbox annotation not found for ID {} and key {}", mailboxId.serialize(),
key.asString());
         } catch (PersistenceException pe) {
-            pe.printStackTrace();
+            throw Throwables.propagate(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(
@@ -181,4 +182,23 @@ public class JPAAnnotationMapper extends JPATransactionalMapper implements
Annot
                 .setValue(mailboxAnnotation.getValue().orNull());
         }
     }
+
+    @Override
+    public boolean exist(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) {
+        JPAId jpaId = (JPAId) mailboxId;
+        Optional<JPAMailboxAnnotation> row = Optional.fromNullable(getEntityManager().find(JPAMailboxAnnotation.class,
+            new JPAMailboxAnnotation.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 Throwables.propagate(pe);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d455ab4b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotation.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotation.java
b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotation.java
index 5836f24..2fdec88 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotation.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/JPAMailboxAnnotation.java
@@ -35,6 +35,7 @@ import com.google.common.base.Objects;
 @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(JPAMailboxAnnotation.JPAMailboxAnnotationId.class)
 public class JPAMailboxAnnotation {
@@ -87,7 +88,7 @@ public class JPAMailboxAnnotation {
     private String key;
 
     @Basic()
-    @Column(name = VALUE, length = 200)
+    @Column(name = VALUE)
     private String value;
 
     public JPAMailboxAnnotation() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/d455ab4b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalAnnotationMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalAnnotationMapper.java
b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalAnnotationMapper.java
index 06cc7cb..0cc48b0 100644
--- a/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalAnnotationMapper.java
+++ b/mailbox/jpa/src/test/java/org/apache/james/mailbox/jpa/mail/TransactionalAnnotationMapper.java
@@ -95,4 +95,14 @@ public class TransactionalAnnotationMapper implements AnnotationMapper
{
             Throwables.propagate(e);
         }
     }
+
+    @Override
+    public boolean exist(MailboxId mailboxId, MailboxAnnotation mailboxAnnotation) {
+        return wrapped.exist(mailboxId, mailboxAnnotation);
+    }
+
+    @Override
+    public int countAnnotations(MailboxId mailboxId) {
+        return wrapped.countAnnotations(mailboxId);
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/d455ab4b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
index c866188..141ed34 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java
@@ -837,7 +837,7 @@ public class StoreMailboxManager implements MailboxManager {
                 for (MailboxAnnotation annotation : mailboxAnnotations) {
                     if (annotation.isNil()) {
                         annotationMapper.deleteAnnotation(mailboxId, annotation.getKey());
-                    } else {
+                    } else if (canInsertOrUpdate(mailboxId, annotation, annotationMapper))
{
                         annotationMapper.insertAnnotation(mailboxId, annotation);
                     }
                 }


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


Mime
View raw message