Author: norman
Date: Tue Jun 8 11:04:30 2010
New Revision: 952602
URL: http://svn.apache.org/viewvc?rev=952602&view=rev
Log:
Replace MailboxMapper.existsMailboxStartingWith() with hasChildren()
(IMAP-151). Thx to Tim-Christian Mundt for the patch. I just did some tiny
adjustments to not hardcode the folder delimiter
Modified:
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java
james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/mail/JPAMailboxMapper.java
james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java
james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.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/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java?rev=952602&r1=952601&r2=952602&view=diff
==============================================================================
---
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java
(original)
+++
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/JCRMailboxSessionMapperFactory.java
Tue Jun 8 11:04:30 2010
@@ -28,6 +28,7 @@ import org.apache.james.imap.mailbox.Mai
import org.apache.james.imap.mailbox.MailboxSession;
import org.apache.james.imap.mailbox.SubscriptionException;
import org.apache.james.imap.store.MailboxSessionMapperFactory;
+import org.apache.james.imap.store.StoreConstants;
import org.apache.james.imap.store.mail.MailboxMapper;
import org.apache.james.imap.store.mail.MessageMapper;
import org.apache.james.imap.store.user.SubscriptionMapper;
@@ -37,20 +38,25 @@ import org.apache.james.imap.store.user.
*
*
*/
-public class JCRMailboxSessionMapperFactory extends
MailboxSessionMapperFactory<String> {
+public class JCRMailboxSessionMapperFactory extends
MailboxSessionMapperFactory<String> implements StoreConstants{
- private MailboxSessionJCRRepository repository;
- private Log logger;
- private char delimiter;
- private NodeLocker locker;
+ private final MailboxSessionJCRRepository repository;
+ private final Log logger;
+ private final char delimiter;
+ private final NodeLocker locker;
public JCRMailboxSessionMapperFactory(final MailboxSessionJCRRepository
repository, final NodeLocker locker) {
+ this(repository, locker, DEFAULT_FOLDER_DELIMITER);
+ }
+
+ public JCRMailboxSessionMapperFactory(final MailboxSessionJCRRepository
repository, final NodeLocker locker, final char delimiter) {
this.repository = repository;
this.logger = LogFactory.getLog(JCRSubscriptionManager.class);
- this.delimiter = '.';
+ this.delimiter = delimiter;
this.locker = locker;;
}
+
@Override
public MailboxMapper<String> createMailboxMapper(MailboxSession session)
throws MailboxException {
JCRMailboxMapper mapper = new JCRMailboxMapper(repository, session,
locker, logger, delimiter);
Modified:
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java?rev=952602&r1=952601&r2=952602&view=diff
==============================================================================
---
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
(original)
+++
james/imap/trunk/jcr/src/main/java/org/apache/james/imap/jcr/mail/JCRMailboxMapper.java
Tue Jun 8 11:04:30 2010
@@ -127,30 +127,6 @@ public class JCRMailboxMapper extends Ab
}
/*
- *
- * (non-Javadoc)
- *
- * @see
- * org.apache.james.imap.store.mail.MailboxMapper#existsMailboxStartingWith
- * (java.lang.String)
- */
- public boolean existsMailboxStartingWith(String mailboxName) throws
StorageException {
- try {
- QueryManager manager = getSession().getWorkspace()
- .getQueryManager();
- String queryString = "//" + MAILBOXES_PATH
- + "//element(*,jamesMailbox:mailbox)[jcr:like(@"
- + JCRMailbox.NAME_PROPERTY + ",'" + mailboxName + "%')]";
- QueryResult result = manager.createQuery(queryString, Query.XPATH)
- .execute();
- NodeIterator it = result.getNodes();
- return it.hasNext();
- } catch (RepositoryException e) {
- throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
- }
- }
-
- /*
* (non-Javadoc)
* @see
org.apache.james.imap.store.mail.MailboxMapper#findMailboxById(java.lang.Object)
*/
@@ -284,5 +260,28 @@ public class JCRMailboxMapper extends Ab
throw new StorageException(HumanReadableText.SAVE_FAILED, e);
}
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.apache.james.imap.store.mail.MailboxMapper#hasChildren(org.apache.james.
+ * imap.store.mail.model.Mailbox)
+ */
+ public boolean hasChildren(Mailbox<String> mailbox)
+ throws StorageException, MailboxNotFoundException {
+ try {
+ QueryManager manager = getSession().getWorkspace()
+ .getQueryManager();
+ String queryString = "//" + MAILBOXES_PATH
+ + "//element(*,jamesMailbox:mailbox)[jcr:like(@"
+ + JCRMailbox.NAME_PROPERTY + ",'" + mailbox.getName() +
delimiter + "%')]";
+ QueryResult result = manager.createQuery(queryString, Query.XPATH)
+ .execute();
+ NodeIterator it = result.getNodes();
+ return it.hasNext();
+ } catch (RepositoryException e) {
+ throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
+ }
+ }
}
Modified:
james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java?rev=952602&r1=952601&r2=952602&view=diff
==============================================================================
---
james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java
(original)
+++
james/imap/trunk/jpa/src/main/java/org/apache/james/imap/jpa/JPAMailboxSessionMapperFactory.java
Tue Jun 8 11:04:30 2010
@@ -26,6 +26,7 @@ import org.apache.james.imap.jpa.mail.JP
import org.apache.james.imap.jpa.user.JPASubscriptionMapper;
import org.apache.james.imap.mailbox.MailboxSession;
import org.apache.james.imap.store.MailboxSessionMapperFactory;
+import org.apache.james.imap.store.StoreConstants;
import org.apache.james.imap.store.mail.MailboxMapper;
import org.apache.james.imap.store.mail.MessageMapper;
import org.apache.james.imap.store.user.SubscriptionMapper;
@@ -34,17 +35,23 @@ import org.apache.james.imap.store.user.
* JPA implementation of {...@link MailboxSessionMapperFactory}
*
*/
-public class JPAMailboxSessionMapperFactory extends
MailboxSessionMapperFactory<Long> {
+public class JPAMailboxSessionMapperFactory extends
MailboxSessionMapperFactory<Long> implements StoreConstants{
private final EntityManagerFactory entityManagerFactory;
+ private final char delimiter;
public JPAMailboxSessionMapperFactory(EntityManagerFactory
entityManagerFactory) {
- this.entityManagerFactory = entityManagerFactory;
+ this(entityManagerFactory, DEFAULT_FOLDER_DELIMITER);
}
+ public JPAMailboxSessionMapperFactory(EntityManagerFactory
entityManagerFactory, char delimiter) {
+ this.entityManagerFactory = entityManagerFactory;
+ this.delimiter = delimiter;
+ }
+
@Override
public MailboxMapper<Long> createMailboxMapper(MailboxSession session) {
- return new JPAMailboxMapper(entityManagerFactory);
+ return new JPAMailboxMapper(entityManagerFactory, delimiter);
}
@Override
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=952602&r1=952601&r2=952602&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 Jun 8 11:04:30 2010
@@ -39,19 +39,11 @@ import org.apache.james.imap.store.mail.
public class JPAMailboxMapper extends JPATransactionalMapper implements
MailboxMapper<Long> {
private static final char SQL_WILDCARD_CHAR = '%';
+ private final char delimiter;
- public JPAMailboxMapper(EntityManagerFactory entityManagerFactory) {
+ public JPAMailboxMapper(EntityManagerFactory entityManagerFactory, char
delimiter) {
super(entityManagerFactory);
- }
-
- /**
- * @see org.apache.james.imap.store.mail.MailboxMapper#hasChildren
- */
- public boolean existsMailboxStartingWith(String mailboxName) throws
StorageException {
-
- final String name = mailboxName + SQL_WILDCARD_CHAR;
- final Long numberOfChildMailboxes = (Long)
getEntityManager().createNamedQuery("countMailboxesWithNameLike").setParameter("nameParam",
name).getSingleResult();
- return numberOfChildMailboxes != null && numberOfChildMailboxes > 0;
+ this.delimiter = delimiter;
}
/**
@@ -136,4 +128,14 @@ public class JPAMailboxMapper extends JP
throw new StorageException(HumanReadableText.SEARCH_FAILED, e);
}
}
+
+ /**
+ * @see
org.apache.james.imap.store.mail.MailboxMapper#hasChildren(java.lang.String)
+ */
+ public boolean hasChildren(Mailbox<Long> mailbox) throws StorageException,
+ MailboxNotFoundException {
+ final String name = mailbox.getName() + delimiter + SQL_WILDCARD_CHAR;
+ final Long numberOfChildMailboxes = (Long)
getEntityManager().createNamedQuery("countMailboxesWithNameLike").setParameter("nameParam",
name).getSingleResult();
+ return numberOfChildMailboxes != null && numberOfChildMailboxes > 0;
+ }
}
Modified:
james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java?rev=952602&r1=952601&r2=952602&view=diff
==============================================================================
---
james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java
(original)
+++
james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/InMemoryMailboxSessionMapperFactory.java
Tue Jun 8 11:04:30 2010
@@ -25,23 +25,28 @@ import org.apache.james.imap.mailbox.Mai
import org.apache.james.imap.mailbox.MailboxSession;
import org.apache.james.imap.mailbox.SubscriptionException;
import org.apache.james.imap.store.MailboxSessionMapperFactory;
+import org.apache.james.imap.store.StoreConstants;
import org.apache.james.imap.store.mail.MailboxMapper;
import org.apache.james.imap.store.mail.MessageMapper;
import org.apache.james.imap.store.transaction.TransactionalMapper;
import org.apache.james.imap.store.user.SubscriptionMapper;
-public class InMemoryMailboxSessionMapperFactory extends
MailboxSessionMapperFactory<Long> {
+public class InMemoryMailboxSessionMapperFactory extends
MailboxSessionMapperFactory<Long> implements StoreConstants {
private MailboxMapper<Long> mailboxMapper;
private MessageMapper<Long> messageMapper;
private SubscriptionMapper subscriptionMapper;
- public InMemoryMailboxSessionMapperFactory() {
- mailboxMapper = new InMemoryMailboxMapper();
+ public InMemoryMailboxSessionMapperFactory(char delimiter) {
+ mailboxMapper = new InMemoryMailboxMapper(delimiter);
messageMapper = new InMemoryMessageMapper();
subscriptionMapper = new InMemorySubscriptionMapper();
}
+ public InMemoryMailboxSessionMapperFactory() {
+ this(DEFAULT_FOLDER_DELIMITER);
+ }
+
public MailboxMapper<Long> getMailboxMapper(MailboxSession session) throws
MailboxException {
return mailboxMapper;
}
Modified:
james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java?rev=952602&r1=952601&r2=952602&view=diff
==============================================================================
---
james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java
(original)
+++
james/imap/trunk/memory/src/main/java/org/apache/james/imap/inmemory/mail/InMemoryMailboxMapper.java
Tue Jun 8 11:04:30 2010
@@ -33,10 +33,12 @@ import org.apache.james.imap.store.mail.
public class InMemoryMailboxMapper implements MailboxMapper<Long> {
private static final int INITIAL_SIZE = 128;
- private Map<Long, InMemoryMailbox> mailboxesById;
+ private final Map<Long, InMemoryMailbox> mailboxesById;
+ private final char delimiter;
- public InMemoryMailboxMapper() {
+ public InMemoryMailboxMapper(char delimiter) {
mailboxesById = new ConcurrentHashMap<Long,
InMemoryMailbox>(INITIAL_SIZE);
+ this.delimiter = delimiter;
}
/*
@@ -110,21 +112,6 @@ public class InMemoryMailboxMapper imple
/*
* (non-Javadoc)
- * @see
org.apache.james.imap.store.mail.MailboxMapper#existsMailboxStartingWith(java.lang.String)
- */
- public boolean existsMailboxStartingWith(String mailboxName) throws
StorageException {
- boolean result = false;
- for (final InMemoryMailbox mailbox:mailboxesById.values()) {
- if (mailbox.getName().startsWith(mailboxName)) {
- result = true;
- break;
- }
- }
- return result;
- }
-
- /*
- * (non-Javadoc)
* @see
org.apache.james.imap.store.mail.MailboxMapper#save(org.apache.james.imap.store.mail.model.Mailbox)
*/
public void save(Mailbox<Long> mailbox) throws StorageException {
@@ -143,5 +130,20 @@ public class InMemoryMailboxMapper imple
// TODO Auto-generated method stub
}
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.imap.store.mail.MailboxMapper#hasChildren(org.apache.james.imap.store.mail.model.Mailbox)
+ */
+ public boolean hasChildren(Mailbox<Long> mailbox) throws StorageException,
+ MailboxNotFoundException {
+ String mailboxName = mailbox.getName() + delimiter;
+ for (final InMemoryMailbox box:mailboxesById.values()) {
+ if (box.getName().startsWith(mailboxName)) {
+ return true;
+ }
+ }
+ return false;
+ }
}
Modified:
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.java
URL:
http://svn.apache.org/viewvc/james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.java?rev=952602&r1=952601&r2=952602&view=diff
==============================================================================
---
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.java
(original)
+++
james/imap/trunk/store/src/main/java/org/apache/james/imap/store/StoreConstants.java
Tue Jun 8 11:04:30 2010
@@ -20,6 +20,8 @@ package org.apache.james.imap.store;
public interface StoreConstants {
+ public static final char DEFAULT_FOLDER_DELIMITER = '.';
+
public static final String USER_NAMESPACE_PREFIX = "#mail";
}
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=952602&r1=952601&r2=952602&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 Jun 8 11:04:30 2010
@@ -40,7 +40,6 @@ import org.apache.james.imap.mailbox.Mai
import org.apache.james.imap.mailbox.MailboxSession;
import org.apache.james.imap.mailbox.MessageRange;
import org.apache.james.imap.mailbox.StandardMailboxMetaDataComparator;
-import org.apache.james.imap.mailbox.StorageException;
import org.apache.james.imap.mailbox.SubscriptionException;
import org.apache.james.imap.mailbox.MailboxMetaData.Selectability;
import org.apache.james.imap.mailbox.util.MailboxEventDispatcher;
@@ -75,7 +74,7 @@ public abstract class StoreMailboxManage
private UidConsumer<Id> consumer;
public StoreMailboxManager(MailboxSessionMapperFactory<Id>
mailboxSessionMapperFactory, final Authenticator authenticator, final
Subscriber subscriber, final UidConsumer<Id> consumer) {
- this(mailboxSessionMapperFactory, authenticator, subscriber, consumer,
'.');
+ this(mailboxSessionMapperFactory, authenticator, subscriber, consumer,
DEFAULT_FOLDER_DELIMITER);
}
@@ -316,7 +315,7 @@ public abstract class StoreMailboxManage
final String match = name.substring(baseLength);
if (mailboxExpression.isExpressionMatch(match, delimiter)) {
final MailboxMetaData.Children inferiors;
- if (hasChildren(name, mapper)) {
+ if (mapper.hasChildren(mailbox)) {
inferiors = MailboxMetaData.Children.HAS_CHILDREN;
} else {
inferiors = MailboxMetaData.Children.HAS_NO_CHILDREN;
@@ -330,17 +329,6 @@ public abstract class StoreMailboxManage
}
- /**
- * Does the mailbox with the given name have inferior child mailboxes?
- * @param name not null
- * @return true when the mailbox has children, false otherwise
- * @throws StorageException
- * @throws TorqueException
- */
- private boolean hasChildren(String name, final MailboxMapper<Id> mapper)
throws StorageException {
- return mapper.existsMailboxStartingWith(name + delimiter);
- }
-
/*
* (non-Javadoc)
* @see
org.apache.james.imap.mailbox.MailboxManager#mailboxExists(java.lang.String,
org.apache.james.imap.mailbox.MailboxSession)
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=952602&r1=952601&r2=952602&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 Jun 8 11:04:30 2010
@@ -39,60 +39,51 @@ public interface MailboxMapper<Id> exten
* @throws StorageException
*/
public abstract void save(Mailbox<Id> mailbox) throws StorageException;
-
+
/**
- * Return the {...@link Mailbox} for the given name
+ * Delete the given {...@link Mailbox} from the underlying storage
*
- * @param name
- * @return mailbox
+ * @param mailbox
* @throws StorageException
- * @throws MailboxNotFoundException
*/
- public abstract Mailbox<Id> findMailboxByName(String name)
- throws StorageException, MailboxNotFoundException;
+ public abstract void delete(Mailbox<Id> mailbox) throws StorageException;
/**
- * Return if the given {...@link Mailbox} has children
- *
- * @param mailboxName not null
- * @return true when the mailbox has children, false otherwise
- * @throws StorageException
- */
- public abstract boolean existsMailboxStartingWith(String mailboxName)
throws StorageException;
-
- /**
- * Delete the given {...@link Mailbox} from the underlying storage
+ * Delete all {...@link Mailbox} objects from the underlying storage
*
- * @param mailbox
* @throws StorageException
*/
- public abstract void delete(Mailbox<Id> mailbox) throws StorageException;
+ public abstract void deleteAll() throws StorageException;
/**
- * Return a List of {...@link Mailbox} which name is like the given name
+ * Return the count of {...@link Mailbox} objects with the given name
*
* @param name
- * @return mailboxList
+ * @return count
* @throws StorageException
*/
- public abstract List<Mailbox<Id>> findMailboxWithNameLike(String name)
+ public abstract long countMailboxesWithName(String name)
throws StorageException;
/**
- * Delete all {...@link Mailbox} objects from the underlying storage
+ * Return the {...@link Mailbox} for the given name
*
+ * @param name
+ * @return mailbox
* @throws StorageException
+ * @throws MailboxNotFoundException
*/
- public abstract void deleteAll() throws StorageException;
+ public abstract Mailbox<Id> findMailboxByName(String mailboxName)
+ throws StorageException, MailboxNotFoundException;
/**
- * Return the count of {...@link Mailbox} objects with the given name
+ * Return a List of {...@link Mailbox} which name is like the given name
*
* @param name
- * @return count
+ * @return mailboxList
* @throws StorageException
*/
- public abstract long countMailboxesWithName(String name)
+ public abstract List<Mailbox<Id>> findMailboxWithNameLike(String
mailboxName)
throws StorageException;
/**
@@ -105,4 +96,15 @@ public interface MailboxMapper<Id> exten
*/
public abstract Mailbox<Id> findMailboxById(Id mailboxId)
throws StorageException, MailboxNotFoundException;
+
+ /**
+ * Return if the given {...@link Mailbox} has children
+ *
+ * @param mailbox not null
+ * @return true when the mailbox has children, false otherwise
+ * @throws StorageException
+ * @throws MailboxNotFoundException
+ */
+ public abstract boolean hasChildren(Mailbox<Id> mailbox)
+ throws StorageException, MailboxNotFoundException;
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]