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.external.riksdagen.documentcontent.impl.DocumentContentData;
31 import com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData_;
32 import com.hack23.cia.service.data.api.DocumentContentDataDAO;
33
34
35
36
37 @Repository("DocumentContentDataDAO")
38 final class DocumentContentDataDAOImpl extends
39 AbstractGenericDAOImpl<DocumentContentData, Long>
40 implements DocumentContentDataDAO {
41
42
43
44
45 public DocumentContentDataDAOImpl() {
46 super(DocumentContentData.class);
47 }
48
49 @Override
50 public boolean checkDocumentContentData(final String documentId) {
51 final CriteriaQuery<DocumentContentData> criteriaQuery = getCriteriaBuilder()
52 .createQuery(DocumentContentData.class);
53 final Root<DocumentContentData> root = criteriaQuery.from(DocumentContentData.class);
54 criteriaQuery.select(root);
55 final Predicate condition = getCriteriaBuilder().equal(root.get(DocumentContentData_.id), documentId);
56 criteriaQuery.where(condition);
57 final TypedQuery<DocumentContentData> typedQuery = getEntityManager()
58 .createQuery(criteriaQuery);
59 addCacheHints(typedQuery, "checkDocumentContentData");
60
61 final List<DocumentContentData> resultList = typedQuery.getResultList();
62
63 return !resultList.isEmpty();
64 }
65
66
67 @Override
68 public List<String> getIdList() {
69 final CriteriaQuery<String> criteria = getCriteriaBuilder().createQuery(String.class);
70 final Root<DocumentContentData> root = criteria.from(DocumentContentData.class);
71 criteria.select(root.get(DocumentContentData_.id));
72 return getEntityManager().createQuery(criteria).getResultList();
73 }
74
75 }