| 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 |
|
|
| 12 |
|
|
| 13 |
|
@author |
| 14 |
|
|
|
|
|
| 0% |
Uncovered Elements: 66 (66) |
Complexity: 20 |
Complexity Density: 0.44 |
|
| 15 |
|
public abstract class BaseHibernateDAOImpl<T extends Entity> extends HibernateDaoSupport |
| 16 |
|
implements BaseDAO<T> { |
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 21 |
0
|
public BaseHibernateDAOImpl() {... |
| 22 |
0
|
super(); |
| 23 |
|
} |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
|
| 28 |
|
|
| 29 |
|
@param |
| 30 |
|
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 31 |
0
|
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 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
@param |
| 51 |
|
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 4 |
Complexity Density: 0.4 |
|
| 52 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 71 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 84 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 96 |
0
|
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 |
|
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
| 108 |
0
|
@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 |
|
} |