View Javadoc
1   /*
2    * Copyright 2010 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
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   * The Class DocumentContentDataDAOImpl.
36   */
37  @Repository("DocumentContentDataDAO")
38  final class DocumentContentDataDAOImpl extends
39  AbstractGenericDAOImpl<DocumentContentData, Long>
40  implements DocumentContentDataDAO {
41  
42  	/**
43  	 * Instantiates a new document content data dao impl.
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  }