Author: norman Date: Mon Jun 20 18:44:25 2011 New Revision: 1137741 URL: http://svn.apache.org/viewvc?rev=1137741&view=rev Log: Allow the MessageMapper to handle Message fetching by pass the datatype which need to get fetched to it. See MAILBOX-89
Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java Modified: james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java (original) +++ james/mailbox/trunk/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/JCRMessageMapper.java Mon Jun 20 18:44:25 2011 @@ -252,14 +252,12 @@ public class JCRMessageMapper extends Ab } } + /* * (non-Javadoc) - * - * @see - * org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache - * .james.imap.mailbox.MessageRange) + * @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox, org.apache.james.mailbox.MessageRange, org.apache.james.mailbox.store.mail.MessageMapper.FetchType, org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback) */ - public void findInMailbox(Mailbox<String> mailbox, MessageRange set, MessageCallback<String> callback) throws MailboxException { + public void findInMailbox(Mailbox<String> mailbox, MessageRange set, FetchType fType, MessageCallback<String> callback) throws MailboxException { try { List<Message<String>> results; long from = set.getUidFrom(); Modified: james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java (original) +++ james/mailbox/trunk/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/JPAMessageMapper.java Mon Jun 20 18:44:25 2011 @@ -115,10 +115,12 @@ public class JPAMessageMapper extends Ab entityManager = null; } } - /** - * @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache.james.mailbox.MessageRange) + + /* + * (non-Javadoc) + * @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox, org.apache.james.mailbox.MessageRange, org.apache.james.mailbox.store.mail.MessageMapper.FetchType, org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback) */ - public void findInMailbox(Mailbox<Long> mailbox, MessageRange set, MessageCallback<Long> callback) throws MailboxException { + public void findInMailbox(Mailbox<Long> mailbox, MessageRange set, FetchType fType, MessageCallback<Long> callback) throws MailboxException { try { List<Message<Long>> results; long from = set.getUidFrom(); Modified: james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java (original) +++ james/mailbox/trunk/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/MaildirMessageMapper.java Mon Jun 20 18:44:25 2011 @@ -110,11 +110,11 @@ public class MaildirMessageMapper extend } } - /* + /* * (non-Javadoc) - * @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox, org.apache.james.mailbox.MessageRange) + * @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(org.apache.james.mailbox.store.mail.model.Mailbox, org.apache.james.mailbox.MessageRange, org.apache.james.mailbox.store.mail.MessageMapper.FetchType, org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback) */ - public void findInMailbox(Mailbox<Integer> mailbox, MessageRange set, MessageCallback<Integer> callback) + public void findInMailbox(Mailbox<Integer> mailbox, MessageRange set, FetchType fType, MessageCallback<Integer> callback) throws MailboxException { final List<Message<Integer>> results; final long from = set.getUidFrom(); @@ -472,7 +472,7 @@ public class MaildirMessageMapper extend final List<UpdatedFlags> updatedFlags = new ArrayList<UpdatedFlags>(); final MaildirFolder folder = maildirStore.createMaildirFolder(mailbox); - findInMailbox(mailbox, set, new MessageCallback<Integer>() { + findInMailbox(mailbox, set, FetchType.Metadata, new MessageCallback<Integer>() { public void onMessages(List<Message<Integer>> members) throws MailboxException { for (final Message<Integer> member : members) { Modified: james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java (original) +++ james/mailbox/trunk/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryMessageMapper.java Mon Jun 20 18:44:25 2011 @@ -93,7 +93,7 @@ public class InMemoryMessageMapper exten * (non-Javadoc) * @see org.apache.james.mailbox.store.mail.MessageMapper#findInMailbox(java.lang.Object, org.apache.james.mailbox.MessageRange) */ - public void findInMailbox(Mailbox<Long> mailbox, MessageRange set, MessageCallback<Long> callback) throws MailboxException { + public void findInMailbox(Mailbox<Long> mailbox, MessageRange set, FetchType ftype, MessageCallback<Long> callback) throws MailboxException { final List<Message<Long>> results; final int batchSize = set.getBatchSize(); final MessageRange.Type type = set.getType(); @@ -150,7 +150,7 @@ public class InMemoryMessageMapper exten public Map<Long, MessageMetaData> expungeMarkedForDeletion(final Mailbox<Long> mailbox, MessageRange set) throws MailboxException { final Map<Long, MessageMetaData> filteredResult = new HashMap<Long, MessageMetaData>(); - findInMailbox(mailbox, set, new MessageCallback<Long>() { + findInMailbox(mailbox, set, FetchType.Metadata, new MessageCallback<Long>() { public void onMessages(List<Message<Long>> results) throws MailboxException { for (final Iterator<Message<Long>> it = results.iterator(); it.hasNext();) { Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java Mon Jun 20 18:44:25 2011 @@ -50,6 +50,7 @@ import org.apache.james.mailbox.SearchQu import org.apache.james.mailbox.UpdatedFlags; import org.apache.james.mailbox.MessageResult.FetchGroup; import org.apache.james.mailbox.store.mail.MessageMapper; +import org.apache.james.mailbox.store.mail.MessageMapper.FetchType; import org.apache.james.mailbox.store.mail.MessageMapperFactory; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.Message; @@ -548,12 +549,55 @@ public class StoreMessageManager<Id> imp */ public void getMessages(MessageRange set, final FetchGroup fetchGroup, MailboxSession mailboxSession, final MessageCallback messageCallback) throws MailboxException { - mapperFactory.getMessageMapper(mailboxSession).findInMailbox(getMailboxEntity(), set, new org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback<Id>() { + mapperFactory.getMessageMapper(mailboxSession).findInMailbox(getMailboxEntity(), set, getFetchType(fetchGroup), new org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback<Id>() { public void onMessages(List<Message<Id>> rows) throws MailboxException { messageCallback.onMessages(new ResultIterator<Id>(rows.iterator(), fetchGroup)); } }); } + + /** + * Use the passed {@link FetchGroup} and calculate the right {@link FetchType} for it + * + * @param group + * @return fetchType + */ + protected static final FetchType getFetchType(FetchGroup group) { + int content = group.content(); + boolean headers = false; + boolean body = false; + boolean full = false; + + if ((content & FetchGroup.HEADERS) > 0) { + headers = true; + content -= FetchGroup.HEADERS; + } + if ((content & FetchGroup.BODY_CONTENT) > 0) { + body = true; + content -= FetchGroup.BODY_CONTENT; + } + + if ((content & FetchGroup.FULL_CONTENT) > 0) { + full = true; + content -= FetchGroup.FULL_CONTENT; + } + + if ((content & FetchGroup.MIME_DESCRIPTOR) > 0) { + // If we need the mimedescriptor we MAY need the full content later too. + // This gives us no other choice then request it + full = true; + content -= FetchGroup.MIME_DESCRIPTOR; + } + if (full || (body && headers)) { + return FetchType.Full; + } else if (body) { + return FetchType.Body; + } else if (headers) { + return FetchType.Headers; + } else { + return FetchType.Metadata; + } + } /** * Return a List which holds all uids of recent messages and optional reset @@ -643,7 +687,7 @@ public class StoreMessageManager<Id> imp MessageMapper<Id> messageMapper = mapperFactory.getMessageMapper(session); final Map<Long, MessageMetaData> copiedMessages = new HashMap<Long, MessageMetaData>(); - messageMapper.findInMailbox(getMailboxEntity(), set, new org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback<Id>() { + messageMapper.findInMailbox(getMailboxEntity(), set, FetchType.Full, new org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback<Id>() { public void onMessages(List<Message<Id>> originalRows) throws MailboxException { Iterator<MessageMetaData> ids = to.copy(originalRows, session); Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/AbstractMessageMapper.java Mon Jun 20 18:44:25 2011 @@ -170,7 +170,7 @@ public abstract class AbstractMessageMap */ public Iterator<UpdatedFlags> updateFlags(final Mailbox<Id> mailbox, final Flags flags, final boolean value, final boolean replace, final MessageRange set) throws MailboxException { final List<UpdatedFlags> updatedFlags = new ArrayList<UpdatedFlags>(); - findInMailbox(mailbox, set, new MessageCallback<Id>() { + findInMailbox(mailbox, set, FetchType.Metadata, new MessageCallback<Id>() { public void onMessages(List<Message<Id>> members) throws MailboxException { Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/mail/MessageMapper.java Mon Jun 20 18:44:25 2011 @@ -30,6 +30,7 @@ import org.apache.james.mailbox.MessageR import org.apache.james.mailbox.UpdatedFlags; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.Message; +import org.apache.james.mailbox.store.mail.model.Property; import org.apache.james.mailbox.store.transaction.Mapper; /** @@ -44,10 +45,11 @@ public interface MessageMapper<Id> exten * * @param mailbox The mailbox to search * @param set message range for batch processing + * @param type * @param callback callback object * @throws MailboxException */ - void findInMailbox(Mailbox<Id> mailbox, MessageRange set, MessageCallback<Id> callback) + void findInMailbox(Mailbox<Id> mailbox, MessageRange set, FetchType type, MessageCallback<Id> callback) throws MailboxException; /** @@ -182,5 +184,53 @@ public interface MessageMapper<Id> exten */ void onMessages(List<Message<Id>> list) throws MailboxException; } + + /** + * Specify what data needs to get filled in a {@link Message} before returning it + * + * + */ + public static enum FetchType { + + /** + * Fetch only the meta data of the {@link Message} which includes: + * <p> + * {@link Message#getUid()} + * {@link Message#getModSeq()} + * {@link Message#getBodyOctets()} + * {@link Message#getFullContentOctets()} + * {@link Message#getInternalDate()} + * {@link Message#getMailboxId()} + * {@link Message#getMediaType()} + * {@link Message#getModSeq()} + * {@link Message#getSubType()} + * {@link Message#getTextualLineCount()} + * </p> + */ + Metadata, + /** + * Fetch the {@link #Metadata}, {@link Property}'s and the {@link Header}'s for the {@link Message}. This includes: + * + * <p> + * {@link Message#getProperties()} + * {@link Message#getHeaders()} + * </p> + */ + Headers, + /** + * Fetch the {@link #Metadata} and the Body for the {@link Message}. This includes: + * + * <p> + * {@link Message#getBodyContent()} + * </p> + */ + Body, + + /** + * Fetch the complete {@link Message} + * + */ + Full + } } \ No newline at end of file Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/quota/ListeningQuotaManager.java Mon Jun 20 18:44:25 2011 @@ -34,6 +34,7 @@ import org.apache.james.mailbox.store.Ma import org.apache.james.mailbox.store.StoreMailboxManager; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.Message; +import org.apache.james.mailbox.store.mail.MessageMapper.FetchType; import org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback; /** @@ -98,7 +99,7 @@ public abstract class ListeningQuotaMana final AtomicLong mSizes = new AtomicLong(0); List<Mailbox> mailboxes = factory.getMailboxMapper(session).findMailboxWithPathLike(new MailboxPath(session.getPersonalSpace(), id, "%")); for (int i = 0; i < mailboxes.size(); i++) { - factory.getMessageMapper(session).findInMailbox(mailboxes.get(i), MessageRange.all(), new MessageCallback<Object>() { + factory.getMessageMapper(session).findInMailbox(mailboxes.get(i), MessageRange.all(), FetchType.Metadata, new MessageCallback<Object>() { long messageSizes = 0; @Override Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/LazyMessageSearchIndex.java Mon Jun 20 18:44:25 2011 @@ -28,6 +28,7 @@ import org.apache.james.mailbox.MailboxE import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageRange; import org.apache.james.mailbox.SearchQuery; +import org.apache.james.mailbox.store.mail.MessageMapper.FetchType; import org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.Message; @@ -83,7 +84,7 @@ public class LazyMessageSearchIndex<Id> done = oldDone; } synchronized (done) { - getFactory().getMessageMapper(session).findInMailbox(mailbox, MessageRange.all(), new MessageCallback<Id>() { + getFactory().getMessageMapper(session).findInMailbox(mailbox, MessageRange.all(), FetchType.Full, new MessageCallback<Id>() { @Override public void onMessages(List<Message<Id>> list) throws MailboxException { Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/ListeningMessageSearchIndex.java Mon Jun 20 18:44:25 2011 @@ -32,6 +32,7 @@ import org.apache.james.mailbox.store.Ma import org.apache.james.mailbox.store.MailboxEventDispatcher.ExpungedImpl; import org.apache.james.mailbox.store.MailboxEventDispatcher.FlagsUpdatedImpl; import org.apache.james.mailbox.store.MailboxEventDispatcher.MailboxDeletionImpl; +import org.apache.james.mailbox.store.mail.MessageMapper.FetchType; import org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback; import org.apache.james.mailbox.store.mail.MessageMapperFactory; import org.apache.james.mailbox.store.mail.model.Mailbox; @@ -80,7 +81,7 @@ public abstract class ListeningMessageSe while (uids.hasNext()) { long next = uids.next(); - factory.getMessageMapper(session).findInMailbox(mailbox, MessageRange.one(next), new MessageCallback<Id>() { + factory.getMessageMapper(session).findInMailbox(mailbox, MessageRange.one(next), FetchType.Full, new MessageCallback<Id>() { @Override public void onMessages(List<Message<Id>> list) throws MailboxException { Modified: james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java URL: http://svn.apache.org/viewvc/james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java?rev=1137741&r1=1137740&r2=1137741&view=diff ============================================================================== --- james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java (original) +++ james/mailbox/trunk/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java Mon Jun 20 18:44:25 2011 @@ -31,6 +31,7 @@ import org.apache.james.mailbox.SearchQu import org.apache.james.mailbox.SearchQuery.NumericRange; import org.apache.james.mailbox.SearchQuery.UidCriterion; import org.apache.james.mailbox.store.mail.MessageMapper; +import org.apache.james.mailbox.store.mail.MessageMapper.FetchType; import org.apache.james.mailbox.store.mail.MessageMapper.MessageCallback; import org.apache.james.mailbox.store.mail.MessageMapperFactory; import org.apache.james.mailbox.store.mail.model.Mailbox; @@ -64,7 +65,7 @@ public class SimpleMessageSearchIndex<Id NumericRange[] ranges = uidCrit.getOperator().getRange(); for (int i = 0; i < ranges.length; i++) { NumericRange r = ranges[i]; - mapper.findInMailbox(mailbox, MessageRange.range(r.getLowValue(), r.getHighValue()), new MessageCallback<Id>() { + mapper.findInMailbox(mailbox, MessageRange.range(r.getLowValue(), r.getHighValue()), FetchType.Metadata, new MessageCallback<Id>() { public void onMessages(List<Message<Id>> list) throws MailboxException { for (int i = 0; i < list.size(); i++) { @@ -84,7 +85,7 @@ public class SimpleMessageSearchIndex<Id final List<Message<Id>> hits = new ArrayList<Message<Id>>(); - mapper.findInMailbox(mailbox, MessageRange.all(), new MessageCallback<Id>() { + mapper.findInMailbox(mailbox, MessageRange.all(), FetchType.Full, new MessageCallback<Id>() { public void onMessages(List<Message<Id>> list) throws MailboxException { for (int i = 0; i < list.size(); i++) { --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org