01: package ru.emdev.EmForge.email.logger;
02:
03: import org.apache.commons.logging.Log;
04: import org.apache.commons.logging.LogFactory;
05: import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
06:
07: import ru.emdev.EmForge.email.Email;
08:
09: /** Implementation of EmailLogger interfaces based on Spring's HibernateTemplate
10: *
11: * @author akakunin
12: *
13: */
14: public class EmailLoggerImpl extends HibernateDaoSupport implements
15: EmailLogger {
16: private final Log logger = LogFactory.getLog(getClass());
17:
18: public void logEmail(Email email) {
19: try {
20: EmailLog emailLog = new EmailLog();
21: emailLog.setSubject(email.getSubject());
22: emailLog.setToAddress(email.getToName());
23: emailLog.setCcAddress(email.getCarbonCopy());
24: emailLog.setBody(email.getContent());
25: emailLog.setPriority(email.getPriority());
26:
27: getHibernateTemplate().saveOrUpdate(emailLog);
28: } catch (Exception ex) {
29: logger.error("Cannot log email:", ex);
30: }
31: }
32:
33: public EmailLog getById(Integer id) {
34: return (EmailLog) getHibernateTemplate()
35: .get(EmailLog.class, id);
36: }
37:
38: }
|