org.apache.james.mailbox.jpa.mail
Class JPAMessageMapper

java.lang.Object
  extended by org.apache.james.mailbox.store.transaction.TransactionalMapper
      extended by org.apache.james.mailbox.store.mail.AbstractMessageMapper<Long>
          extended by org.apache.james.mailbox.jpa.mail.JPAMessageMapper
All Implemented Interfaces:
MessageMapper<Long>, Mapper

public class JPAMessageMapper
extends AbstractMessageMapper<Long>
implements MessageMapper<Long>

JPA implementation of a MessageMapper. This class is not thread-safe!


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.james.mailbox.store.mail.MessageMapper
MessageMapper.FetchType, MessageMapper.MessageCallback<Id>
 
Nested classes/interfaces inherited from interface org.apache.james.mailbox.store.transaction.Mapper
Mapper.Transaction<T>, Mapper.VoidTransaction
 
Field Summary
protected  javax.persistence.EntityManager entityManager
           
protected  javax.persistence.EntityManagerFactory entityManagerFactory
           
 
Fields inherited from class org.apache.james.mailbox.store.mail.AbstractMessageMapper
mailboxSession
 
Constructor Summary
JPAMessageMapper(MailboxSession session, UidProvider<Long> uidProvider, ModSeqProvider<Long> modSeqProvider, javax.persistence.EntityManagerFactory entityManagerFactory)
           
 
Method Summary
protected  void begin()
           
protected  void commit()
          Commit the Transaction and close the EntityManager
protected  MessageMetaData copy(Mailbox<Long> mailbox, long uid, long modSeq, Message<Long> original)
           
 long countMessagesInMailbox(Mailbox<Long> mailbox)
           
 long countUnseenMessagesInMailbox(Mailbox<Long> mailbox)
           
 void delete(Mailbox<Long> mailbox, Message<Long> message)
           
 void endRequest()
          Close open EntityManager
 Map<Long,MessageMetaData> expungeMarkedForDeletionInMailbox(Mailbox<Long> mailbox, MessageRange set)
           
 Long findFirstUnseenMessageUid(Mailbox<Long> mailbox)
           
 void findInMailbox(Mailbox<Long> mailbox, MessageRange set, MessageMapper.FetchType fType, MessageMapper.MessageCallback<Long> callback)
           
 List<Long> findRecentMessageUidsInMailbox(Mailbox<Long> mailbox)
           
 javax.persistence.EntityManager getEntityManager()
          Return the currently used EntityManager or a new one if none exists.
protected  void rollback()
           
protected  MessageMetaData save(Mailbox<Long> mailbox, Message<Long> message)
           
 
Methods inherited from class org.apache.james.mailbox.store.mail.AbstractMessageMapper
add, copy, getHighestModSeq, getLastUid, updateFlags
 
Methods inherited from class org.apache.james.mailbox.store.transaction.TransactionalMapper
execute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.james.mailbox.store.mail.MessageMapper
add, copy, getHighestModSeq, getLastUid, updateFlags
 
Methods inherited from interface org.apache.james.mailbox.store.transaction.Mapper
execute
 

Field Detail

entityManagerFactory

protected javax.persistence.EntityManagerFactory entityManagerFactory

entityManager

protected javax.persistence.EntityManager entityManager
Constructor Detail

JPAMessageMapper

public JPAMessageMapper(MailboxSession session,
                        UidProvider<Long> uidProvider,
                        ModSeqProvider<Long> modSeqProvider,
                        javax.persistence.EntityManagerFactory entityManagerFactory)
Method Detail

getEntityManager

public javax.persistence.EntityManager getEntityManager()
Return the currently used EntityManager or a new one if none exists.

Returns:
entitymanger

begin

protected void begin()
              throws MailboxException
Specified by:
begin in class TransactionalMapper
Throws:
MailboxException

commit

protected void commit()
               throws MailboxException
Commit the Transaction and close the EntityManager

Specified by:
commit in class TransactionalMapper
Throws:
MailboxException

rollback

protected void rollback()
                 throws MailboxException
Specified by:
rollback in class TransactionalMapper
Throws:
MailboxException

endRequest

public void endRequest()
Close open EntityManager

Specified by:
endRequest in interface Mapper

findInMailbox

public void findInMailbox(Mailbox<Long> mailbox,
                          MessageRange set,
                          MessageMapper.FetchType fType,
                          MessageMapper.MessageCallback<Long> callback)
                   throws MailboxException
Specified by:
findInMailbox in interface MessageMapper<Long>
Throws:
MailboxException

countMessagesInMailbox

public long countMessagesInMailbox(Mailbox<Long> mailbox)
                            throws MailboxException
Specified by:
countMessagesInMailbox in interface MessageMapper<Long>
Throws:
MailboxException
See Also:
org.apache.james.mailbox.store.mail.MessageMapper#countMessagesInMailbox()

countUnseenMessagesInMailbox

public long countUnseenMessagesInMailbox(Mailbox<Long> mailbox)
                                  throws MailboxException
Specified by:
countUnseenMessagesInMailbox in interface MessageMapper<Long>
Throws:
MailboxException
See Also:
org.apache.james.mailbox.store.mail.MessageMapper#countUnseenMessagesInMailbox()

delete

public void delete(Mailbox<Long> mailbox,
                   Message<Long> message)
            throws MailboxException
Specified by:
delete in interface MessageMapper<Long>
Throws:
MailboxException

findFirstUnseenMessageUid

public Long findFirstUnseenMessageUid(Mailbox<Long> mailbox)
                               throws MailboxException
Specified by:
findFirstUnseenMessageUid in interface MessageMapper<Long>
Throws:
MailboxException

findRecentMessageUidsInMailbox

public List<Long> findRecentMessageUidsInMailbox(Mailbox<Long> mailbox)
                                          throws MailboxException
Specified by:
findRecentMessageUidsInMailbox in interface MessageMapper<Long>
Throws:
MailboxException

copy

protected MessageMetaData copy(Mailbox<Long> mailbox,
                               long uid,
                               long modSeq,
                               Message<Long> original)
                        throws MailboxException
Specified by:
copy in class AbstractMessageMapper<Long>
Throws:
MailboxException

save

protected MessageMetaData save(Mailbox<Long> mailbox,
                               Message<Long> message)
                        throws MailboxException
Specified by:
save in class AbstractMessageMapper<Long>
Throws:
MailboxException

expungeMarkedForDeletionInMailbox

public Map<Long,MessageMetaData> expungeMarkedForDeletionInMailbox(Mailbox<Long> mailbox,
                                                                   MessageRange set)
                                                            throws MailboxException
Specified by:
expungeMarkedForDeletionInMailbox in interface MessageMapper<Long>
Throws:
MailboxException


Copyright © 2010-2011 The Apache Software Foundation. All Rights Reserved.