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.dokumentstatus.impl.DocumentData;
31  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentData_;
32  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer;
33  import com.hack23.cia.service.data.api.DocumentStatusContainerDAO;
34  
35  /**
36   * The Class DocumentStatusContainerDAOImpl.
37   */
38  @Repository("DocumentStatusContainerDAO")
39  final class DocumentStatusContainerDAOImpl extends
40  AbstractGenericDAOImpl<DocumentStatusContainer, Long> implements
41  DocumentStatusContainerDAO {
42  
43  	/**
44  	 * Instantiates a new document status container dao impl.
45  	 */
46  	public DocumentStatusContainerDAOImpl() {
47  		super(DocumentStatusContainer.class);
48  	}
49  
50  	@Override
51  	public int checkExistByDocumentId(final String id) {
52  		final CriteriaQuery<DocumentData> criteriaQuery = getCriteriaBuilder()
53  				.createQuery(DocumentData.class);
54  		final Root<DocumentData> root = criteriaQuery.from(DocumentData.class);
55  		criteriaQuery.select(root);
56  		final Predicate condition = getCriteriaBuilder().equal(root.get(DocumentData_.id), id);
57  		criteriaQuery.where(condition);
58  		final TypedQuery<DocumentData> typedQuery = getEntityManager()
59  				.createQuery(criteriaQuery);
60  		addCacheHints(typedQuery, "findFirstByProperty");
61  
62  		return typedQuery.getResultList().size();
63  	}
64  
65  	@Override
66  	public List<String> getAvaibleCommitteeProposal() {
67  		final CriteriaQuery<String> criteria = getCriteriaBuilder().createQuery(String.class);
68  		final Root<DocumentData> root = criteria.from(DocumentData.class);
69  		criteria.select(root.get(DocumentData_.id));
70  		criteria.where(getCriteriaBuilder().isNotNull(root.get(DocumentData_.committeeReportUrlXml)));
71  		return getEntityManager().createQuery(criteria).getResultList();
72  
73  	}
74  
75  	@Override
76  	public List<String> getIdList() {
77  		final CriteriaQuery<String> criteria = getCriteriaBuilder().createQuery(String.class);
78  		final Root<DocumentData> root = criteria.from(DocumentData.class);
79  		criteria.select(root.get(DocumentData_.id));
80  		return getEntityManager().createQuery(criteria).getResultList();
81  	}
82  
83  }