KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > oracle > toplink > essentials > queryframework > EJBQLCall


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 // Copyright (c) 1998, 2005, Oracle. All rights reserved.
22
package oracle.toplink.essentials.queryframework;
23
24 // Java imports
25
import java.sql.*;
26 import java.io.*;
27
28 // TopLink imports
29
import oracle.toplink.essentials.internal.databaseaccess.*;
30 import oracle.toplink.essentials.internal.queryframework.*;
31 import oracle.toplink.essentials.internal.parsing.ejbql.*;
32 import oracle.toplink.essentials.internal.sessions.AbstractRecord;
33 import oracle.toplink.essentials.internal.sessions.AbstractSession;
34
35 /**
36  * <b>Purpose</b>: Used as an abstraction of a database invocation.
37  * A call is an EJBQL string.
38  * <p><b>Responsibilities</b>:<ul>
39  * <li> Parse the EJBQL String
40  * <li> Populate the contained query's selection criteria. Add attributes to ReportQuery (if required).
41  * </ul>
42  * @author Jon Driscoll and Joel Lucuik
43  * @since TopLink 4.0
44  */

45 /**
46  * <b>Purpose</b>: Used as an abstraction of a database invocation.
47  * A call is an EJBQL string.
48  */

49 public class EJBQLCall implements Serializable, Call {
50     // Back reference to query, unfortunately required for events.
51
protected DatabaseQuery query;
52     protected String JavaDoc ejbqlString;
53
54     // Check that we aren't parsing more than once
55
protected boolean isParsed;
56
57     /**
58      * PUBLIC
59      * Create a new EJBQLCall.
60      */

61     public EJBQLCall() {
62         super();
63     }
64
65     /**
66      * PUBLIC
67      * Create a new EJBQLCall with an ejbqlString
68      */

69     public EJBQLCall(String JavaDoc ejbqlString) {
70         this();
71         this.ejbqlString = ejbqlString;
72     }
73
74     /**
75      * INTERNAL:
76      * Return the appropriate mechanism,
77      * with the call added as necessary.
78      */

79     public DatabaseQueryMechanism buildNewQueryMechanism(DatabaseQuery query) {
80         return new EJBQLCallQueryMechanism(query, this);
81     }
82
83     //bug4324564: removed buildParserFor to remove Antlr.jar compile dependency -CD
84
// See class oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParserFactory.buildParserFor
85

86
87     /**
88      * INTERNAL:
89      * Return the appropriate mechanism,
90      * with the call added as necessary.
91      */

92     public DatabaseQueryMechanism buildQueryMechanism(DatabaseQuery query, DatabaseQueryMechanism mechanism) {
93         return buildNewQueryMechanism(query);
94     }
95
96     public Object JavaDoc clone() {
97         try {
98             return super.clone();
99         } catch (CloneNotSupportedException JavaDoc cnse) {
100             return null;
101         }
102     }
103
104     /**
105      * INTERNAL:
106      * Return the string for the call
107      */

108     public String JavaDoc getCallString() {
109         return getEjbqlString();
110     }
111
112     /**
113      * INTERNAL:
114      * Return the EJBQL string for this call
115      */

116     public String JavaDoc getEjbqlString() {
117         return ejbqlString;
118     }
119
120     /**
121      * INTERNAL
122      * Return the isParsed state
123      */

124     private boolean getIsParsed() {
125         return isParsed;
126     }
127
128     /**
129      * Back reference to query, unfortunately required for events.
130      */

131     public DatabaseQuery getQuery() {
132         return query;
133     }
134
135     /**
136      * INTERNAL:
137      * Return the SQL string for this call. Always return null
138      * since this is an EJBQL call
139      */

140     public String JavaDoc getLogString(Accessor accessor) {
141         return getSQLString();
142     }
143
144     /**
145      * INTERNAL:
146      * Return the SQL string for this call. Always return null
147      * since this is an EJBQL call
148      */

149     public String JavaDoc getSQLString() {
150         return null;
151     }
152
153     /**
154      * INTERNAL:
155      * Yes this is an EJBQLCall
156      */

157     public boolean isEJBQLCall() {
158         return true;
159     }
160
161     /**
162      * Return whether all the results of the call have been returned.
163      */

164     public boolean isFinished() {
165         //never used, but required for implementing Call.
166
return true;
167     }
168
169     /**
170      * INTERNAL
171      * Is this query Parsed
172      */

173     public boolean isParsed() {
174         return getIsParsed();
175     }
176
177     //bug4324564: removed parseEJBQLString to remove Antlr.jar compile dependency -CD
178
// See class oracle.toplink.essentials.internal.parsing.ejbql.EJBQLParserFactory.parseEJBQLString
179

180     /**
181      * Populate the query using the information retrieved from parsing the EJBQL.
182      */

183     public void populateQuery(AbstractSession session) {
184         if (!isParsed()) {
185             //bug4324564: moved code to EJBQLParserFactory.populateQuery -CD
186
(new EJBQLParserFactory()).populateQuery(getEjbqlString(), (ObjectLevelReadQuery)getQuery(), session);
187             // Make sure we don't parse and prepare again.
188
this.setIsParsed(true);
189         }
190     }
191
192     /**
193      * INTERNAL:
194      * Prepare the JDBC statement, this may be parameterize or a call statement.
195      * If caching statements this must check for the pre-prepared statement and re-bind to it.
196      */

197     public PreparedStatement prepareStatement(DatabaseAccessor accessor, AbstractRecord translationRow, AbstractSession session) throws SQLException {
198         return null;
199     }
200
201     /**
202      * INTERNAL:
203      * Set the EJBQL string for this call
204      */

205     public void setEjbqlString(java.lang.String JavaDoc newEjbqlString) {
206         ejbqlString = newEjbqlString;
207     }
208
209     /**
210      * INTERNAL
211      * Set the isParsed state
212      */

213     public void setIsParsed(boolean newIsParsed) {
214         isParsed = newIsParsed;
215     }
216
217     /**
218      * INTERNAL:
219      * Back reference to query, unfortunately required for events.
220      */

221     public void setQuery(DatabaseQuery query) {
222         this.query = query;
223     }
224
225     /**
226      * INTERNAL:
227      * translate method comment.
228      */

229     public void translate(AbstractRecord translationRow, AbstractRecord modifyRow, AbstractSession session) {
230     }
231 }
232
Popular Tags