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