james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject svn commit: r762824 - in /james/imap/trunk: jpa/src/main/java/org/apache/james/imap/jpa/mail/ jpa/src/main/java/org/apache/james/imap/jpa/mail/model/ store/src/main/java/org/apache/james/imap/store/ store/src/main/java/org/apache/james/imap/store/mail/
Date Wed, 08 Apr 2009 04:11:17 GMT
Author: rdonkin
Date: Tue Apr  7 16:01:43 2009
New Revision: 762824

URL: http://svn.apache.org/viewvc?rev=762824&view=rev
Log:
Switch to count to improve performance a little IMAP-73 https://issues.apache.org/jira/browse/IMAP-73

Modified:
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java
    james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailbox.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
    james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MailboxMapper.java

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java?rev=762824&r1=762823&r2=762824&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java
(original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java
Tue Apr  7 16:01:43 2009
@@ -36,11 +36,25 @@
  */
 public abstract class JPAMailboxMapper extends Mapper implements MailboxMapper {
 
+    private static final char SQL_WILDCARD_CHAR = '%';
+    
     public JPAMailboxMapper(EntityManager entityManager) {
         super(entityManager);
     }
 
     /**
+     * @see org.apache.james.imap.jpa.mail.MailboxMapper#hasChildren
+     */
+    public boolean hasChildren(String mailboxName, char hierarchyDeliminator) throws StorageException
{
+        
+        final String name = mailboxName + hierarchyDeliminator + SQL_WILDCARD_CHAR; 
+        final Long numberOfChildMailboxes = (Long) entityManager.createNamedQuery("countMailboxesWithNameLike").setParameter("nameParam",
name).getSingleResult();
+        return numberOfChildMailboxes != null && numberOfChildMailboxes > 0;
+    }
+
+
+
+    /**
      * @see org.apache.james.imap.jpa.mail.MailboxMapper#save(org.apache.james.imap.jpa.mail.model.JPAMailbox)
      */
     public void save(Mailbox mailbox) throws StorageException {

Modified: james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailbox.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailbox.java?rev=762824&r1=762823&r2=762824&view=diff
==============================================================================
--- james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailbox.java
(original)
+++ james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/model/JPAMailbox.java
Tue Apr  7 16:01:43 2009
@@ -38,7 +38,9 @@
     @NamedQuery(name="deleteAll",
                 query="DELETE FROM Mailbox mailbox"),
     @NamedQuery(name="findMailboxWithNameLike",
-                query="SELECT mailbox FROM Mailbox mailbox WHERE mailbox.name LIKE :nameParam")
           
+                query="SELECT mailbox FROM Mailbox mailbox WHERE mailbox.name LIKE :nameParam"),
+    @NamedQuery(name="countMailboxesWithNameLike",
+                query="SELECT COUNT(mailbox) FROM Mailbox mailbox WHERE mailbox.name LIKE
:nameParam")     
 })
 public class JPAMailbox implements Mailbox {
     

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java?rev=762824&r1=762823&r2=762824&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
(original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreMailboxManager.java
Tue Apr  7 16:01:43 2009
@@ -260,8 +260,7 @@
      * @throws TorqueException
      */
     private boolean hasChildren(String name, final MailboxMapper mapper) throws StorageException
{
-        final String search = name + HIERARCHY_DELIMITER + SQL_WILDCARD_CHAR;
-        return !mapper.findMailboxWithNameLike(search).isEmpty();
+        return mapper.hasChildren(name, HIERARCHY_DELIMITER);
     }
 
     public boolean mailboxExists(String mailboxName) throws MailboxException {

Modified: james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MailboxMapper.java
URL: http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MailboxMapper.java?rev=762824&r1=762823&r2=762824&view=diff
==============================================================================
--- james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MailboxMapper.java
(original)
+++ james/imap/trunk/store/src/main/java/org/apache/james/imap/store/mail/MailboxMapper.java
Tue Apr  7 16:01:43 2009
@@ -34,6 +34,15 @@
     public abstract Mailbox findMailboxByName(String name)
             throws StorageException, MailboxNotFoundException;
 
+    /**
+     * Does the given mailbox have children?
+     * @param mailboxName not null
+     * @param hierarchyDeliminator character used to separate individual mailboxes in the
hierarchy
+     * @return true when the mailbox has children, false otherwise
+     * @throws StorageException
+     */
+    public abstract boolean hasChildren(String mailboxName, char hierarchyDeliminator) throws
StorageException;
+    
     public abstract void delete(Mailbox mailbox) throws StorageException;
 
     @SuppressWarnings("unchecked")



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