1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package org.directdemocracyportal.democracy.service.dao.hibernate; |
6 | |
|
7 | |
import java.util.List; |
8 | |
|
9 | |
import org.directdemocracyportal.democracy.model.application.OnlinePoliticalParty; |
10 | |
import org.directdemocracyportal.democracy.model.world.PoliticalParty; |
11 | |
import org.directdemocracyportal.democracy.service.dao.PoliticalPartyDAO; |
12 | |
import org.hibernate.criterion.DetachedCriteria; |
13 | |
import org.hibernate.criterion.Restrictions; |
14 | |
import org.springframework.dao.DataAccessException; |
15 | |
import org.springframework.transaction.annotation.Propagation; |
16 | |
import org.springframework.transaction.annotation.Transactional; |
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
@Transactional(propagation = Propagation.MANDATORY) |
22 | |
public class HibernatePoliticalPartyDAO extends |
23 | |
GenericHibernateDAO<PoliticalParty, Long> implements PoliticalPartyDAO |
24 | |
{ |
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
public HibernatePoliticalPartyDAO() { |
30 | 1 | super(PoliticalParty.class); |
31 | 1 | } |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
@Transactional(readOnly = true) |
39 | |
public PoliticalParty findByName(String name) throws DataAccessException { |
40 | 1 | DetachedCriteria findPartyByName = DetachedCriteria |
41 | |
.forClass(PoliticalParty.class); |
42 | 1 | findPartyByName.add(Restrictions.eq("name", name)); |
43 | |
|
44 | |
@SuppressWarnings("unchecked") |
45 | 1 | List<PoliticalParty> result = this.getHibernateTemplate() |
46 | |
.findByCriteria(findPartyByName); |
47 | |
|
48 | 1 | return result.isEmpty() ? null : result.get(0); |
49 | |
} |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
@Override |
57 | |
public PoliticalParty findByShortCode(String shortCode) { |
58 | 0 | DetachedCriteria findPartyByShortCode = DetachedCriteria |
59 | |
.forClass(PoliticalParty.class); |
60 | 0 | findPartyByShortCode.add(Restrictions.eq("shortCode", shortCode)); |
61 | |
|
62 | |
@SuppressWarnings("unchecked") |
63 | 0 | List<PoliticalParty> result = this.getHibernateTemplate() |
64 | |
.findByCriteria(findPartyByShortCode); |
65 | |
|
66 | 0 | return result.isEmpty() ? null : result.get(0); |
67 | |
} |
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
@SuppressWarnings("unchecked") |
75 | |
public List<OnlinePoliticalParty> getAllOnline() throws DataAccessException { |
76 | 0 | return getHibernateTemplate().find( |
77 | |
"from " + OnlinePoliticalParty.class.getSimpleName()); |
78 | |
} |
79 | |
} |