Coverage Report - org.kuali.rice.core.framework.persistence.jpa.criteria.QueryByCriteria
 
Classes in this File Line Coverage Branch Coverage Complexity
QueryByCriteria
0%
0/17
0%
0/4
1.5
QueryByCriteria$QueryByCriteriaType
0%
0/1
N/A
1.5
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
 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  
 package org.kuali.rice.core.framework.persistence.jpa.criteria;
 17  
 
 18  
 import javax.persistence.EntityManager;
 19  
 import javax.persistence.Query;
 20  
 
 21  
 
 22  
 /**
 23  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 24  
  */
 25  
 public class QueryByCriteria {
 26  
 
 27  
     private EntityManager entityManager;
 28  
     private Criteria criteria;
 29  
     private QueryByCriteriaType type;
 30  
     
 31  0
     public enum QueryByCriteriaType {SELECT, UPDATE, DELETE}
 32  
     
 33  
     public QueryByCriteria(EntityManager entityManager, Criteria criteria) {
 34  0
         this(entityManager, criteria, QueryByCriteriaType.SELECT);
 35  0
     }
 36  
 
 37  0
     public QueryByCriteria(EntityManager entityManager, Criteria criteria, QueryByCriteriaType type) {
 38  0
         this.entityManager = entityManager;
 39  0
         this.criteria = criteria;
 40  0
         this.type = type;
 41  0
     }
 42  
 
 43  
     public Query toQuery() {
 44  0
         Query query = entityManager.createQuery(criteria.toQuery(type));
 45  0
         if (criteria.getSearchLimit() != null) {
 46  0
             query.setMaxResults(criteria.getSearchLimit());                
 47  
         }
 48  0
         criteria.prepareParameters(query);
 49  0
         return query;
 50  
     }
 51  
     
 52  
     public Query toCountQuery() {
 53  0
         Query query = entityManager.createQuery(criteria.toCountQuery());
 54  0
         if (criteria.getSearchLimit() != null) {
 55  0
             query.setMaxResults(criteria.getSearchLimit());                
 56  
         }
 57  0
         criteria.prepareParameters(query);
 58  0
         return query;
 59  
     }
 60  
 
 61  
 }