Clover Coverage Report - itracker
Coverage timestamp: Tue May 1 2012 16:42:12 CEST
45   120   20   6.43
14   89   0.44   7
7     2.86  
1    
 
 
  BaseHibernateDAOImpl       Line # 15 45 20 0% 0.0
 
No Tests
 
1    package org.itracker.persistence.dao;
2   
3    import java.util.Date;
4   
5    import org.hibernate.HibernateException;
6    import org.itracker.model.Entity;
7    import org.springframework.dao.InvalidDataAccessResourceUsageException;
8    import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
9   
10    /**
11    * Contains common behaviour to all hibernate factories
12    *
13    * @author rui silva
14    */
 
15    public abstract class BaseHibernateDAOImpl<T extends Entity> extends HibernateDaoSupport
16    implements BaseDAO<T> {
17   
18    /**
19    *
20    */
 
21  0 toggle public BaseHibernateDAOImpl() {
22  0 super();
23    }
24   
25    /**
26    * insert a new entity.
27    * create- and lastmodified-date is set with current time.
28    *
29    * @param entity - detached entity object
30    */
 
31  0 toggle public void save(T entity) {
32  0 if (null == entity) {
33  0 throw new InvalidDataAccessResourceUsageException( "entity must not be null" );
34    }
35  0 try {
36  0 Date createDate = new Date();
37  0 entity.setCreateDate(createDate);
38  0 entity.setLastModifiedDate(createDate);
39  0 getSession().save(entity);
40    } catch (HibernateException ex) {
41  0 logger.debug("save: caught HibernateException, call to convertHibernateException", ex);
42  0 throw convertHibernateAccessException(ex);
43    }
44    }
45   
46    /**
47    * inserts a new detached entity or updates if it already exists.
48    * create- and update-date are set automatically.
49    *
50    * @param entity - entity object to be inserted or updated
51    */
 
52  0 toggle public void saveOrUpdate(T entity) {
53  0 if (null == entity) {
54  0 throw new InvalidDataAccessResourceUsageException( "entity must not be null" );
55    }
56   
57  0 try {
58  0 if (null == entity.getCreateDate()){
59  0 entity.setCreateDate(new Date());
60  0 entity.setLastModifiedDate(entity.getCreateDate());
61    } else {
62  0 entity.setLastModifiedDate(new Date());
63    }
64  0 getSession().saveOrUpdate(entity);
65    } catch (HibernateException ex) {
66  0 logger.debug("saveOrUpdate: caught HibernateException, call to convertHibernateException", ex);
67  0 throw convertHibernateAccessException(ex);
68    }
69    }
70   
 
71  0 toggle public void delete(T entity) {
72  0 if (null == entity) {
73  0 throw new InvalidDataAccessResourceUsageException( "entity must not be null" );
74    }
75  0 try {
76  0 getSession().delete(entity);
77  0 getSession().flush();
78    } catch (HibernateException ex) {
79  0 logger.debug("delete: caught HibernateException, call to convertHibernateException", ex);
80  0 throw convertHibernateAccessException(ex);
81    }
82    }
83   
 
84  0 toggle public void detach(T entity) {
85  0 if (null == entity) {
86  0 throw new InvalidDataAccessResourceUsageException( "entity must not be null" );
87    }
88  0 try {
89  0 getSession().evict(entity);
90    } catch (HibernateException ex) {
91  0 logger.debug("detach: caught HibernateException, call to convertHibernateException", ex);
92  0 throw convertHibernateAccessException(ex);
93    }
94    }
95   
 
96  0 toggle public void refresh(T entity) {
97  0 if (null == entity) {
98  0 throw new InvalidDataAccessResourceUsageException( "entity must not be null" );
99    }
100  0 try {
101  0 getSession().refresh(entity);
102    } catch (HibernateException ex) {
103  0 logger.debug("refresh: caught HibernateException, call to convertHibernateException", ex);
104  0 throw convertHibernateAccessException(ex);
105    }
106    }
107   
 
108  0 toggle @SuppressWarnings("unchecked")
109    public T merge(T entity) {
110  0 if (null == entity) {
111  0 throw new InvalidDataAccessResourceUsageException( "entity must not be null" );
112    }
113  0 try {
114  0 return (T)getSession().merge(entity);
115    } catch (HibernateException ex) {
116  0 logger.debug("merge: caught HibernateException, call to convertHibernateException", ex);
117  0 throw convertHibernateAccessException(ex);
118    }
119    }
120    }