KickJava   Java API By Example, From Geeks To Geeks.

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


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 import oracle.toplink.essentials.internal.sessions.AbstractRecord;
25 import oracle.toplink.essentials.internal.sessions.AbstractSession;
26
27 /**
28  * <p><b>Purpose</b>:
29  * Abstract class for all read queries.
30  *
31  * <p><b>Responsibilities</b>:
32  * <ul>
33  * <li> Caches result of query if flag is set.
34  * </ul>
35  *
36  * @author Yvon Lavoie
37  * @since TOPLink/Java 1.0
38  */

39 public abstract class ReadQuery extends DatabaseQuery {
40
41     /** Used for retrieve limited rows through the query. */
42     protected int maxRows;
43
44     /** Used to start query results at a specific result */
45     protected int firstResult;
46
47     /* used on read queries to stamp the object to determine the last time it was refreshed to
48      * reduce work and prevent inifinite recursion on Refreshes
49      *CR #4365 - used to prevent infinit recursion on refresh object cascade all
50      * CR #2698903 - fix for the previous fix. No longer using millis but ids now.
51      */

52     protected long queryId;
53
54     /**
55      * PUBLIC:
56      * Initialize the state of the query
57      */

58     public ReadQuery() {
59         this.maxRows = 0;
60         this.firstResult = 0;
61         this.queryId = 0;
62     }
63
64     /**
65      * INTERNAL:
66      * By default return the row.
67      * Used by cursored stream.
68      */

69     public Object JavaDoc buildObject(AbstractRecord row) {
70         return row;
71     }
72
73     /**
74      * INTERNAL
75      * Used to give the subclasses oportunity to copy aspects of the cloned query
76      * to the original query.
77      */

78     protected void clonedQueryExecutionComplete(DatabaseQuery query, AbstractSession session) {
79         // Nothing by default.
80
}
81
82     /**
83      * PUBLIC:
84      * Return the value that will be set for the firstResult in the returned result set
85      */

86     public int getFirstResult() {
87         return firstResult;
88     }
89
90     /**
91      * INTERNAL:
92      * This method is used to get the time in millis that this query is being executed at.
93      * it is set just prior to executing the SQL and will be used to determine which objects should be refreshed.
94      * CR #4365
95      * CR #2698903 ... instead of using millis we will now use id's instead. Method
96      * renamed appropriately.
97      */

98     public long getQueryId() {
99         return this.queryId;
100     }
101
102     /**
103      * PUBLIC:
104      * Return the limit for the maximum number of rows that any ResultSet can contain to the given number.
105      */

106     public int getMaxRows() {
107         return this.maxRows;
108     }
109
110     /**
111      * PUBLIC:
112      * Return if this is a read query.
113      */

114     public boolean isReadQuery() {
115         return true;
116     }
117
118     /**
119      * PUBLIC:
120      * Used to set the first result in any result set that is returned for this query.
121      * This method should only be set once per query. To change the firstReslt use another query.
122      * This method will call the absolute method on the JDBC result set to move the initial row
123      * used by TopLink. Note: The set of results returned from the database will still include
124      * the results before the first result. TopLink will just not use them for object building.
125      */

126     public void setFirstResult(int firstResult) {
127         this.firstResult = firstResult;
128         setIsPrepared(false);
129     }
130
131     /**
132      * INTERNAL:
133      * This method is used to set the current system time in millis that this query is being executed at.
134      * it is set just prior to executing the SQL and will be used to determine which objects should be refreshed.
135      * CR #4365
136      * CR #2698903 ... instead of using millis we will now use id's instead. Method
137      * renamed appropriately.
138      */

139     public void setQueryId(long id) {
140         this.queryId = id;
141     }
142
143     /**
144     * PUBLIC:
145     * Used to set the limit for the maximum number of rows that any ResultSet can contain to the given number.
146     * This method should only be set once per query. To change the max rows use another query.
147     * This method limits the number of candidate results returned to TopLink that can be used to build objects
148     */

149     public void setMaxRows(int maxRows) {
150         this.maxRows = maxRows;
151         setIsPrepared(false);
152     }
153 }
154
Popular Tags