KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > execute > GenericQualifier


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

21
22 package org.apache.derby.impl.sql.execute;
23
24 import org.apache.derby.iapi.sql.Activation;
25
26 import org.apache.derby.iapi.error.StandardException;
27
28 import org.apache.derby.iapi.store.access.Qualifier;
29
30 import org.apache.derby.iapi.types.DataValueDescriptor;
31
32 import org.apache.derby.iapi.services.loader.GeneratedMethod;
33
34 import org.apache.derby.iapi.services.sanity.SanityManager;
35
36 /**
37  * This is the implementation for Qualifier. It is used for generated scans.
38  *
39  * @author Jeff Lichtman
40  */

41
42 public class GenericQualifier implements Qualifier
43 {
44     private int columnId;
45     private int operator;
46     private GeneratedMethod orderableGetter;
47     private Activation activation;
48     private boolean orderedNulls;
49     private boolean unknownRV;
50     private boolean negateCompareResult;
51     protected int variantType;
52
53     private DataValueDescriptor orderableCache = null;
54
55     public GenericQualifier(int columnId,
56                             int operator,
57                             GeneratedMethod orderableGetter,
58                             Activation activation,
59                             boolean orderedNulls,
60                             boolean unknownRV,
61                             boolean negateCompareResult,
62                             int variantType)
63     {
64         this.columnId = columnId;
65         this.operator = operator;
66         this.orderableGetter = orderableGetter;
67         this.activation = activation;
68         this.orderedNulls = orderedNulls;
69         this.unknownRV = unknownRV;
70         this.negateCompareResult = negateCompareResult;
71         this.variantType = variantType;
72     }
73
74     /*
75      * Qualifier interface
76      */

77
78     /**
79      * @see Qualifier#getColumnId
80      */

81     public int getColumnId()
82     {
83         return columnId;
84     }
85
86     /**
87      * @see Qualifier#getOrderable
88      *
89      * @exception StandardException Thrown on error
90      */

91     public DataValueDescriptor getOrderable() throws StandardException
92     {
93         if (variantType != VARIANT)
94         {
95             if (orderableCache == null)
96             {
97                 orderableCache = (DataValueDescriptor) (orderableGetter.invoke(activation));
98             }
99             return orderableCache;
100         }
101         return (DataValueDescriptor) (orderableGetter.invoke(activation));
102     }
103
104     /** Get the operator to use in the comparison.
105      *
106      * @see Qualifier#getOperator
107      **/

108     public int getOperator()
109     {
110         return operator;
111     }
112
113     /** Should the result from the compare operation be negated? If true
114      * then only rows which fail the compare operation will qualify.
115      *
116      * @see Qualifier#negateCompareResult
117      **/

118     public boolean negateCompareResult()
119     {
120         return negateCompareResult;
121     }
122
123     /** Get the getOrderedNulls argument to use in the comparison.
124      *
125      * @see Qualifier#getOrderedNulls
126      **/

127     public boolean getOrderedNulls()
128     {
129         return orderedNulls;
130     }
131
132     /** Get the getOrderedNulls argument to use in the comparison.
133      *
134      * @see Qualifier#getUnknownRV
135      **/

136     public boolean getUnknownRV()
137     {
138         return unknownRV;
139     }
140
141     /** Clear the DataValueDescriptor cache, if one exists.
142      * (The DataValueDescriptor can be 1 of 3 types:
143      * o VARIANT - cannot be cached as its value can
144      * vary within a scan
145      * o SCAN_INVARIANT - can be cached within a scan as its
146      * value will not change within a scan
147      * o QUERY_INVARIANT- can be cached across the life of the query
148      * as its value will never change
149      * o CONSTANT - never changes
150      *
151      * @see Qualifier#getUnknownRV
152      */

153     public void clearOrderableCache()
154     {
155         if ((variantType == SCAN_INVARIANT) || (variantType == VARIANT))
156         {
157             orderableCache = null;
158         }
159     }
160     
161     /**
162      * This method reinitializes all the state of
163      * the Qualifier. It is used to distinguish between
164      * resetting something that is query invariant
165      * and something that is constant over every
166      * execution of a query. Basically, clearOrderableCache()
167      * will only clear out its cache if it is a VARIANT
168      * or SCAN_INVARIANT value. However, each time a
169      * query is executed, the QUERY_INVARIANT qualifiers need
170      * to be reset.
171      */

172     public void reinitialize()
173     {
174         if (variantType != CONSTANT)
175         {
176             orderableCache = null;
177         }
178     }
179
180     public String JavaDoc toString()
181     {
182         if (SanityManager.DEBUG)
183         {
184             return "columnId: "+columnId+
185                 "\noperator: "+operator+
186                 "\norderedNulls: "+orderedNulls+
187                 "\nunknownRV: "+unknownRV+
188                 "\nnegateCompareResult: "+negateCompareResult;
189         }
190         else
191         {
192             return "";
193         }
194     }
195 }
196
Popular Tags