KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > access > QueryTranslator


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 package org.apache.cayenne.access;
21
22 import java.sql.Connection JavaDoc;
23 import java.sql.PreparedStatement JavaDoc;
24
25 import org.apache.cayenne.dba.DbAdapter;
26 import org.apache.cayenne.map.DbEntity;
27 import org.apache.cayenne.map.EntityInheritanceTree;
28 import org.apache.cayenne.map.EntityResolver;
29 import org.apache.cayenne.map.ObjEntity;
30 import org.apache.cayenne.query.Query;
31
32 /**
33  * Defines API for translation Cayenne queries to JDBC PreparedStatements.
34  * <p>
35  * <i>For more information see <a HREF="../../../../../../userguide/index.html"
36  * target="_top">Cayenne User Guide. </a> </i>
37  * </p>
38  *
39  * @author Andrus Adamchik
40  */

41 public abstract class QueryTranslator {
42
43     /** Query being translated. */
44     protected Query query;
45
46     /**
47      * JDBC database connection needed to create PreparedStatement. Prior to 1.2 this
48      * property was called "con".
49      */

50     protected Connection JavaDoc connection;
51
52     /** Adapter helping to do SQL literal conversions, etc. */
53     protected DbAdapter adapter;
54
55     /**
56      * Provides access to Cayenne mapping info.
57      *
58      * @since 1.2
59      */

60     protected EntityResolver entityResolver;
61
62     /**
63      * Creates PreparedStatement. <code>logLevel</code> parameter is supplied to allow
64      * control of logging of produced SQL.
65      */

66     public abstract PreparedStatement JavaDoc createStatement() throws Exception JavaDoc;
67
68     /** Returns query object being processed. */
69     public Query getQuery() {
70         return query;
71     }
72
73     public void setQuery(Query query) {
74         this.query = query;
75     }
76
77     /**
78      * Returns Connection object used by this translator.
79      *
80      * @since 1.2
81      */

82     public Connection JavaDoc getConnection() {
83         return connection;
84     }
85
86     /**
87      * @since 1.2
88      */

89     public void setConnection(Connection JavaDoc connection) {
90         this.connection = connection;
91     }
92
93     public DbAdapter getAdapter() {
94         return adapter;
95     }
96
97     public void setAdapter(DbAdapter adapter) {
98         this.adapter = adapter;
99     }
100
101     /**
102      * Returns an EntityInheritanceTree for the root entity.
103      *
104      * @since 1.1
105      */

106     public EntityInheritanceTree getRootInheritanceTree() {
107         return getEntityResolver().lookupInheritanceTree(getRootEntity());
108     }
109
110     public ObjEntity getRootEntity() {
111         return query.getMetaData(getEntityResolver()).getObjEntity();
112     }
113
114     public DbEntity getRootDbEntity() {
115         return query.getMetaData(getEntityResolver()).getDbEntity();
116     }
117
118     /**
119      * @since 1.2
120      */

121     public EntityResolver getEntityResolver() {
122         return entityResolver;
123     }
124
125     /**
126      * @since 1.2
127      */

128     public void setEntityResolver(EntityResolver entityResolver) {
129         this.entityResolver = entityResolver;
130     }
131 }
132
Popular Tags