DocumentContentDataDAOImpl.java

  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. import java.util.List;

  21. import javax.persistence.TypedQuery;
  22. import javax.persistence.criteria.CriteriaQuery;
  23. import javax.persistence.criteria.Predicate;
  24. import javax.persistence.criteria.Root;

  25. import org.springframework.stereotype.Repository;

  26. import com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData;
  27. import com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData_;
  28. import com.hack23.cia.service.data.api.DocumentContentDataDAO;

  29. /**
  30.  * The Class DocumentContentDataDAOImpl.
  31.  */
  32. @Repository("DocumentContentDataDAO")
  33. final class DocumentContentDataDAOImpl extends
  34. AbstractGenericDAOImpl<DocumentContentData, Long>
  35. implements DocumentContentDataDAO {

  36.     /**
  37.      * Instantiates a new document content data dao impl.
  38.      */
  39.     public DocumentContentDataDAOImpl() {
  40.         super(DocumentContentData.class);
  41.     }

  42.     @Override
  43.     public boolean checkDocumentContentData(final String documentId) {
  44.         final CriteriaQuery<DocumentContentData> criteriaQuery = getCriteriaBuilder()
  45.                 .createQuery(DocumentContentData.class);
  46.         final Root<DocumentContentData> root = criteriaQuery.from(DocumentContentData.class);
  47.         criteriaQuery.select(root);
  48.         final Predicate condition = getCriteriaBuilder().equal(root.get(DocumentContentData_.id), documentId);
  49.         criteriaQuery.where(condition);
  50.         final TypedQuery<DocumentContentData> typedQuery = getEntityManager()
  51.                 .createQuery(criteriaQuery);
  52.         addCacheHints(typedQuery, "checkDocumentContentData");

  53.         final List<DocumentContentData> resultList = typedQuery.getResultList();

  54.         return !resultList.isEmpty();
  55.     }


  56.     @Override
  57.     public List<String> getIdList() {
  58.         final CriteriaQuery<String> criteria = getCriteriaBuilder().createQuery(String.class);
  59.         final Root<DocumentContentData> root = criteria.from(DocumentContentData.class);
  60.         criteria.select(root.get(DocumentContentData_.id));
  61.         return getEntityManager().createQuery(criteria).getResultList();
  62.     }

  63. }