1 /**
2 * Copyright 2005-2014 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.krad.data.jpa;
17
18 import javax.persistence.EntityManager;
19 import javax.persistence.TypedQuery;
20 import java.util.List;
21
22 /**
23 * JPA specialization of DataObjectCriteriaQuery.
24 *
25 * @author Kuali Rice Team (rice.collab@kuali.org)
26 */
27 class JpaCriteriaQuery extends DataObjectCriteriaQueryBase<NativeJpaQueryTranslator.TranslationContext, TypedQuery> {
28
29 /**
30 * The query translator to use for this implementation.
31 */
32 protected QueryTranslator<NativeJpaQueryTranslator.TranslationContext, TypedQuery> queryTranslator;
33
34 /**
35 * Creates a new JPA-specific criteria query.
36 *
37 * @param em the entity manager used in interacting with the database.
38 */
39 public JpaCriteriaQuery(EntityManager em) {
40 this.queryTranslator = new NativeJpaQueryTranslator(em);
41 }
42
43 /**
44 * {@inheritDoc}
45 */
46 @Override
47 protected QueryTranslator<NativeJpaQueryTranslator.TranslationContext, TypedQuery> getQueryTranslator() {
48 return queryTranslator;
49 }
50
51 /**
52 * {@inheritDoc}
53 */
54 @Override
55 @SuppressWarnings("unchecked")
56 public <T> List<T> getResults(TypedQuery query) {
57 return query.getResultList();
58 }
59
60 /**
61 * {@inheritDoc}
62 */
63 @Override
64 protected int getRowCount(TypedQuery query) {
65 // NOTE: is there a better way to do this (e.g. without retrieving full results)?
66 return query.getResultList().size();
67 }
68
69 /**
70 * {@inheritDoc}
71 */
72 @Override
73 public int getIncludedRowCount(TypedQuery query, List rows) {
74 return rows.size();
75 }
76 }