1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.service.data.impl;
20
21 import java.util.List;
22
23 import javax.persistence.TypedQuery;
24 import javax.persistence.criteria.CriteriaQuery;
25 import javax.persistence.criteria.Predicate;
26 import javax.persistence.criteria.Root;
27
28 import org.springframework.stereotype.Repository;
29
30 import com.hack23.cia.model.internal.application.system.impl.LanguageContentData;
31 import com.hack23.cia.model.internal.application.system.impl.LanguageContentData_;
32 import com.hack23.cia.service.data.api.LanguageContentDataDAO;
33
34
35
36
37 @Repository("LanguageContentDataDAO")
38 final class LanguageContentDataDAOImpl extends
39 AbstractGenericDAOImpl<LanguageContentData, Long> implements
40 LanguageContentDataDAO {
41
42
43
44
45 public LanguageContentDataDAOImpl() {
46 super(LanguageContentData.class);
47 }
48
49 @Override
50 public LanguageContentData findTranslation(final String key,
51 final String fromLanguage, final String toLanguage) {
52
53 final CriteriaQuery<LanguageContentData> criteriaQuery = getCriteriaBuilder()
54 .createQuery(getPersistentClass());
55 final Root<LanguageContentData> root = criteriaQuery
56 .from(getPersistentClass());
57 criteriaQuery.select(root);
58 final Predicate keyCondition = getCriteriaBuilder().equal(root.get(LanguageContentData_.refKey),
59 key);
60 final Predicate fromCondition = getCriteriaBuilder().equal(
61 root.get(LanguageContentData_.fromLanguage),
62 fromLanguage);
63 final Predicate toCondition = getCriteriaBuilder().equal(root.get(LanguageContentData_.toLanguage),
64 toLanguage);
65
66 final Predicate and = getCriteriaBuilder().and(keyCondition, fromCondition, toCondition);
67
68 criteriaQuery.where(and);
69
70 final TypedQuery<LanguageContentData> typedQuery = getEntityManager()
71 .createQuery(criteriaQuery);
72 addCacheHints(typedQuery, "findTranslation");
73
74 final List<LanguageContentData> resultList = typedQuery.getResultList();
75
76 if (resultList.isEmpty()) {
77 return null;
78 } else {
79 return resultList.get(0);
80 }
81
82 }
83
84
85
86
87
88
89 private List<Long> getIdList() {
90 final CriteriaQuery<Long> criteria = getCriteriaBuilder().createQuery(
91 Long.class);
92 final Root<LanguageContentData> root = criteria
93 .from(LanguageContentData.class);
94 criteria.select(root.get(LanguageContentData_.hjid));
95 return getEntityManager().createQuery(criteria).getResultList();
96 }
97
98 }