KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > jpa > bridge > JpaIndirectQuery


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19
20
21 package org.apache.cayenne.jpa.bridge;
22
23 import java.util.Map JavaDoc;
24
25 import org.apache.cayenne.jpa.JpaProviderException;
26 import org.apache.cayenne.jpa.map.JpaNamedQuery;
27 import org.apache.cayenne.map.DataMap;
28 import org.apache.cayenne.map.ObjEntity;
29 import org.apache.cayenne.query.IndirectQuery;
30 import org.apache.cayenne.query.ParameterizedQuery;
31 import org.apache.cayenne.query.Query;
32
33 /**
34  * A superclass of indirect queries that map JPA to Cayenne queries.
35  *
36  * @author Andrus Adamchik
37  */

38 public abstract class JpaIndirectQuery extends IndirectQuery implements
39         ParameterizedQuery {
40
41     protected JpaNamedQuery jpaQuery;
42     protected DataMap parentMap;
43     protected ObjEntity parentEntity;
44     protected Map JavaDoc parameters;
45
46     public Query createQuery(Map JavaDoc parameters) {
47         JpaIndirectQuery clone;
48         try {
49             clone = (JpaIndirectQuery) getClass().newInstance();
50         }
51         catch (Exception JavaDoc e) {
52             throw new JpaProviderException("Error cloning a query", e);
53         }
54
55         clone.setJpaQuery(jpaQuery);
56         clone.setParentEntity(parentEntity);
57         clone.setParentMap(parentMap);
58         clone.parameters = parameters;
59
60         return clone;
61     }
62
63     public JpaNamedQuery getJpaQuery() {
64         return jpaQuery;
65     }
66
67     public void setJpaQuery(JpaNamedQuery query) {
68         this.jpaQuery = query;
69     }
70
71     public ObjEntity getParentEntity() {
72         return parentEntity;
73     }
74
75     public void setParentEntity(ObjEntity parentEntity) {
76         this.parentEntity = parentEntity;
77     }
78
79     public DataMap getParentMap() {
80         return parentMap;
81     }
82
83     public void setParentMap(DataMap parentMap) {
84         this.parentMap = parentMap;
85     }
86 }
87
Popular Tags