Class SendMailDaoHib
- java.lang.Object
-
- lumis.portal.sendmail.dao.hibernate.SendMailDaoHib
-
- All Implemented Interfaces:
ISendMailDao
public class SendMailDaoHib extends java.lang.Object implements ISendMailDao
Hibernate based implementation ofISendMailDao
.- Since:
- 4.0.4
- Version:
- $Revision$ $Date$
-
-
Constructor Summary
Constructors Constructor Description SendMailDaoHib()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addMailToSendQueue(IMultipleMail mail, java.lang.String queueId, ITransaction transaction)
Adds an mail to the send queue.void
addMailToSendQueue(ISingleMail mail, java.lang.String queueId, ITransaction transaction)
Adds an mail to the send queue.IMailAttachment
createMailAttachment()
Factory method for creating a new mail attachment instance.IMailDestination
createMailDestination()
Factory method for creating a new mail destination instance.IMultipleMail
createMultipleMail()
Factory method for creating a new blank mail instance.ISingleMail
createSingleMail()
Factory method for creating a new blank mail instance.ISingleMail
createSingleMail(IMultipleMail mail, IMailDestination destination)
This implementation actually uses the same mail instance, only sets the values in the to, cc and bcc fields.void
deleteMail(java.lang.String mailId, ITransaction transaction)
Deletes the whole mail structure, including the body, attachments, destinations.void
deleteMailBody(java.lang.String mailId, ITransaction transaction)
Deletes the whole mail's body, including the body message and the attachments.void
deleteMailDestination(java.lang.String mailDestinationId, ITransaction transaction)
Deletes the mail destination.IMailDestination
fetchNextPendingDestination(IMultipleMail mail)
Returns for the next destination pending for sending for the given mail, and marks its status as sending.IBaseMail
fetchNextQueuedMail(java.lang.String queueId)
Returns the next queued mail pending for sending, and marks its status as sending.java.lang.String
generateNewQueueId()
Returns a new generated queue id.IMailConfig
getMailConfig(ITransaction transaction)
Returns the IMailConfig containing the configurations for sending e-mails.java.lang.String
lockNextQueue()
Locks the next queue mail available and returns its id.void
setMailConfig(IMailConfig mailConfig, ITransaction transaction)
Sets the IMailConfig containing the configurations for sending e-mails.void
unfetchMail(java.lang.String mailId)
Puts a mail back on its place in the queue to be available to another queue processing.void
unlockQueue(java.lang.String queueId)
Unlocks a mail queue.void
updateMailSendStatus(IMailSendStatus mailSendStatus)
Updates the mail send status as set in the given instance.
-
-
-
Method Detail
-
createMultipleMail
public IMultipleMail createMultipleMail() throws PortalException
Description copied from interface:ISendMailDao
Factory method for creating a new blank mail instance. Use this method to obtain an instance ofIMultipleMail
, to fill it with the required data and use it in the other methods in this interface.- Specified by:
createMultipleMail
in interfaceISendMailDao
- Returns:
- a new blank mail instance.
- Throws:
PortalException
- See Also:
ISendMailDao.createSingleMail()
,ISendMailDao.createMailAttachment()
,ISendMailDao.createMailDestination()
-
createSingleMail
public ISingleMail createSingleMail() throws PortalException
Description copied from interface:ISendMailDao
Factory method for creating a new blank mail instance. Use this method to obtain an instance ofISingleMail
, to fill it with the required data and use it in the other methods in this interface.- Specified by:
createSingleMail
in interfaceISendMailDao
- Returns:
- a new blank mail instance.
- Throws:
PortalException
- See Also:
ISendMailDao.createMultipleMail()
,ISendMailDao.createMailAttachment()
-
createMailAttachment
public IMailAttachment createMailAttachment()
Description copied from interface:ISendMailDao
Factory method for creating a new mail attachment instance. Use this method to obtain an instance ofIMailAttachment
, to fill it with the required data and use it in the other methods in this interface.- Specified by:
createMailAttachment
in interfaceISendMailDao
- Returns:
- a new mail attachment instance.
- See Also:
ISendMailDao.createSingleMail()
,ISendMailDao.createMultipleMail()
,IMailBody.getAttachments()
-
createMailDestination
public IMailDestination createMailDestination()
Description copied from interface:ISendMailDao
Factory method for creating a new mail destination instance. Use this method to obtain an instance ofIMailDestination
, to fill it with the required data and use it in the other methods in this interface.- Specified by:
createMailDestination
in interfaceISendMailDao
- Returns:
- a new mail destination instance.
- See Also:
ISendMailDao.createMultipleMail()
,IMultipleMail.getDestinations()
-
generateNewQueueId
public java.lang.String generateNewQueueId() throws DaoException
Description copied from interface:ISendMailDao
Returns a new generated queue id.- Specified by:
generateNewQueueId
in interfaceISendMailDao
- Returns:
- a new generated queue id.
- Throws:
DaoException
- if the queue id could not be generated.
-
getMailConfig
public IMailConfig getMailConfig(ITransaction transaction) throws DaoException
Description copied from interface:ISendMailDao
Returns the IMailConfig containing the configurations for sending e-mails.- Specified by:
getMailConfig
in interfaceISendMailDao
- Parameters:
transaction
- the transaction for persistence access.- Returns:
- the IMailConfig, never null.
- Throws:
DaoException
- if it was not possible to obtain the IMailConfig.- See Also:
ISendMailDao.setMailConfig(IMailConfig, ITransaction)
-
setMailConfig
public void setMailConfig(IMailConfig mailConfig, ITransaction transaction) throws DaoException
Description copied from interface:ISendMailDao
Sets the IMailConfig containing the configurations for sending e-mails.- Specified by:
setMailConfig
in interfaceISendMailDao
- Parameters:
mailConfig
- the IMailConfig.transaction
- the transaction for persistence access.- Throws:
DaoException
- if it was not possible to set the IMailConfig.- See Also:
ISendMailDao.getMailConfig(ITransaction)
-
addMailToSendQueue
public void addMailToSendQueue(ISingleMail mail, java.lang.String queueId, ITransaction transaction) throws DaoException
Description copied from interface:ISendMailDao
Adds an mail to the send queue.- Specified by:
addMailToSendQueue
in interfaceISendMailDao
- Parameters:
mail
- the mail. This instance must have been created byISendMailDao.createSingleMail()
.queueId
- the id of the queue where the mail will be added to. If null a new queue will be generated.transaction
- the transaction for persistence access.- Throws:
DaoException
- if it was not possible to add the mail to the send queue.- See Also:
ISendMailDao.addMailToSendQueue(IMultipleMail, String, ITransaction)
,#createMail()
,ISendMailDao.createMailAttachment()
-
addMailToSendQueue
public void addMailToSendQueue(IMultipleMail mail, java.lang.String queueId, ITransaction transaction) throws DaoException
Description copied from interface:ISendMailDao
Adds an mail to the send queue.- Specified by:
addMailToSendQueue
in interfaceISendMailDao
- Parameters:
mail
- the mail. This instance must have been created byISendMailDao.createMultipleMail()
.queueId
- the id of the queue where the mail will be added to. If null a new queue will be generated.transaction
- the transaction for persistence access.- Throws:
DaoException
- if it was not possible to add the mail to the send queue.- See Also:
ISendMailDao.addMailToSendQueue(ISingleMail, String, ITransaction)
,#createMail()
,ISendMailDao.createMailAttachment()
,ISendMailDao.createMailDestination()
-
createSingleMail
public ISingleMail createSingleMail(IMultipleMail mail, IMailDestination destination)
This implementation actually uses the same mail instance, only sets the values in the to, cc and bcc fields.This can be done because both
IMultipleMail
andISingleMail
are implemented by theMail
class, but theISingleMail
destination fields are ignored when used as aIMultipleMail
in this Dao.- Specified by:
createSingleMail
in interfaceISendMailDao
- Parameters:
mail
- the mail.destination
- the destination- Returns:
- the corresponding
ISingleMail
instance.
-
fetchNextQueuedMail
public IBaseMail fetchNextQueuedMail(java.lang.String queueId) throws DaoException
Description copied from interface:ISendMailDao
Returns the next queued mail pending for sending, and marks its status as sending. Must also update the queue lock expiration date time.This operation must be atomic and garantee that the same mail will not be returned many times, even if this method is called simultaneously by many threads in many servers in the cluster.
- Specified by:
fetchNextQueuedMail
in interfaceISendMailDao
- Parameters:
queueId
- the id of the queue from where the mail will be taken.- Returns:
- the mail or null if none was found.
- Throws:
DaoException
-
unfetchMail
public void unfetchMail(java.lang.String mailId) throws DaoException
Description copied from interface:ISendMailDao
Puts a mail back on its place in the queue to be available to another queue processing. It status will be changed toIMailSendStatus.STATUS_SEND_PENDING
.- Specified by:
unfetchMail
in interfaceISendMailDao
- Parameters:
mailId
- the mail id.- Throws:
DaoException
-
fetchNextPendingDestination
public IMailDestination fetchNextPendingDestination(IMultipleMail mail) throws DaoException
Description copied from interface:ISendMailDao
Returns for the next destination pending for sending for the given mail, and marks its status as sending. Must also update the corresponding queue lock expiration date time.This operation must be atomic and garantee that the same destination will not be returned many times, even if this method is called simultaneously by many threads in many servers in the cluster.
- Specified by:
fetchNextPendingDestination
in interfaceISendMailDao
- Parameters:
mail
- the mail.- Returns:
- the destination or null if none was found.
- Throws:
DaoException
-
updateMailSendStatus
public void updateMailSendStatus(IMailSendStatus mailSendStatus) throws DaoException
Description copied from interface:ISendMailDao
Updates the mail send status as set in the given instance. The update is committed immediatelly.- Specified by:
updateMailSendStatus
in interfaceISendMailDao
- Parameters:
mailSendStatus
- the mail send status information.- Throws:
DaoException
-
lockNextQueue
public java.lang.String lockNextQueue() throws DaoException
Description copied from interface:ISendMailDao
Locks the next queue mail available and returns its id.This operation must be atomic and garantee that a locked queue will not be returned, even if this method is called simultaneously by many threads in many servers in the cluster.
- Specified by:
lockNextQueue
in interfaceISendMailDao
- Returns:
- the id of the locked queue, or null if there was no queue pending.
- Throws:
DaoException
-
unlockQueue
public void unlockQueue(java.lang.String queueId) throws DaoException
Description copied from interface:ISendMailDao
Unlocks a mail queue.- Specified by:
unlockQueue
in interfaceISendMailDao
- Parameters:
queueId
- the queue's id.- Throws:
DaoException
-
deleteMail
public void deleteMail(java.lang.String mailId, ITransaction transaction) throws DaoException
Description copied from interface:ISendMailDao
Deletes the whole mail structure, including the body, attachments, destinations.- Specified by:
deleteMail
in interfaceISendMailDao
- Parameters:
mailId
- the id of the mail to be deleted.transaction
- the transaction for persistence access.- Throws:
DaoException
- if it was not possible to delete the mail.
-
deleteMailBody
public void deleteMailBody(java.lang.String mailId, ITransaction transaction) throws DaoException
Description copied from interface:ISendMailDao
Deletes the whole mail's body, including the body message and the attachments.- Specified by:
deleteMailBody
in interfaceISendMailDao
- Parameters:
mailId
- the id of the mail whose body is to be deleted.transaction
- the transaction for persistence access.- Throws:
DaoException
- if it was not possible to delete the mail.
-
deleteMailDestination
public void deleteMailDestination(java.lang.String mailDestinationId, ITransaction transaction) throws DaoException
Description copied from interface:ISendMailDao
Deletes the mail destination.- Specified by:
deleteMailDestination
in interfaceISendMailDao
- Parameters:
mailDestinationId
- the id of the mail destination to be deleted.transaction
- the transaction for persistence access.- Throws:
DaoException
- if it was not possible to delete the mail destination.
-
-