KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > store > raw > FetchDescriptor


1 /*
2
3    Derby - Class org.apache.derby.iapi.store.raw.FetchDescriptor
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.iapi.store.raw;
23
24 import org.apache.derby.iapi.services.sanity.SanityManager;
25
26 import org.apache.derby.iapi.store.access.Qualifier;
27
28 import org.apache.derby.iapi.services.io.FormatableBitSet;
29
30 /**
31
32 FetchDescriptor is used to package up all the arguments necessary to
33 describe what rows and what row parts should be returned from the store
34 back to language as part of a fetch.
35 <p>
36 The FetchDescriptor may also contain scratch space used to process the
37 qualifiers passed in the scan. This scratch space will be used to cache
38 information about the qualifiers, valid column list, row size so that
39 calculations need only be done once per scan rather than every iteration.
40 **/

41
42 public final class FetchDescriptor
43 {
44
45     /**************************************************************************
46      * Fields of the class
47      **************************************************************************
48      */

49     private int row_length;
50     private FormatableBitSet validColumns;
51     private Qualifier[][] qualifier_list;
52     private int[] materialized_cols;
53     private int maxFetchColumnId;
54
55     private static final int ZERO_FILL_LENGTH = 100;
56     private static final int[] zero_fill_array = new int[ZERO_FILL_LENGTH];
57
58     // use int arrays rather than FormatableBitSet's to get most efficient processing
59
// in performance critical loop which reads columns from page.
60
private int[] validColumnsArray;
61
62     /**************************************************************************
63      * Constructors for This class:
64      **************************************************************************
65      */

66     FetchDescriptor()
67     {
68     }
69
70     public FetchDescriptor(
71     int input_row_length)
72     {
73         row_length = input_row_length;
74     }
75
76     public FetchDescriptor(
77     int input_row_length,
78     int single_valid_column_number)
79     {
80         row_length = input_row_length;
81         maxFetchColumnId = single_valid_column_number;
82         validColumnsArray = new int[maxFetchColumnId + 1];
83         validColumnsArray[single_valid_column_number] = 1;
84     }
85
86     public FetchDescriptor(
87     int input_row_length,
88     FormatableBitSet input_validColumns,
89     Qualifier[][] input_qualifier_list)
90     {
91         row_length = input_row_length;
92         qualifier_list = input_qualifier_list;
93
94         if (qualifier_list != null)
95         {
96             materialized_cols = new int[row_length];
97         }
98
99         setValidColumns(input_validColumns);
100     }
101
102
103     /**************************************************************************
104      * Public Methods of This class:
105      **************************************************************************
106      */

107
108     /**
109      * Return the column list bit map.
110      * <p>
111      * A description of which columns to return from every fetch in the scan.
112      * A row array and a valid column bit map work together to describe the row
113      * to be returned by the scan - see RowUtil for description of how these two
114      * parameters work together to describe a "row".
115      *
116      * @return The column list bit map.
117      *
118      * @exception StandardException Standard exception policy.
119      **/

120     public final FormatableBitSet getValidColumns()
121     {
122         return(validColumns);
123     }
124
125     public final int[] getValidColumnsArray()
126     {
127         return(validColumnsArray);
128     }
129
130     public final void setValidColumns(
131     FormatableBitSet input_validColumns)
132     {
133         validColumns = input_validColumns;
134
135         setMaxFetchColumnId();
136
137         if (validColumns != null)
138         {
139             validColumnsArray = new int[maxFetchColumnId + 1];
140             for (int i = maxFetchColumnId; i >= 0; i--)
141             {
142                 validColumnsArray[i] = ((validColumns.isSet(i)) ? 1 : 0);
143             }
144         }
145     }
146
147     /**
148      * Return the qualifier array.
149      * <p>
150      * Return the array of qualifiers in this FetchDescriptor. The array of
151      * qualifiers which, applied to each key, restricts the rows returned by
152      * the scan. Rows for which any one of the qualifiers returns false are
153      * not returned by the scan. If null, all rows are returned. Qualifiers
154      * can only reference columns which are included in the scanColumnList.
155      * The column id that a qualifier returns in the column id the table, not
156      * the column id in the partial row being returned.
157      * <p>
158      * A null qualifier array means there are no qualifiers.
159      *
160      * @return The qualifier array, it may be null.
161      *
162      * @exception StandardException Standard exception policy.
163      **/

164     public final Qualifier[][] getQualifierList()
165     {
166         return(qualifier_list);
167     }
168
169
170     /**
171      * Internal to store.
172      **/

173     public final int[] getMaterializedColumns()
174     {
175         return(materialized_cols);
176     }
177
178
179     /**
180      * Internal to store.
181      **/

182     public final int getMaxFetchColumnId()
183     {
184         return(maxFetchColumnId);
185     }
186
187     private final void setMaxFetchColumnId()
188     {
189         maxFetchColumnId = row_length - 1;
190
191         if (validColumns != null)
192         {
193             int vCol_length = validColumns.getLength();
194
195             if (vCol_length < maxFetchColumnId + 1)
196                 maxFetchColumnId = vCol_length - 1;
197
198             for (; maxFetchColumnId >= 0; maxFetchColumnId--)
199             {
200                 if (validColumns.isSet(maxFetchColumnId))
201                     break;
202             }
203         }
204     }
205
206     /**
207      * Internal to store.
208      **/

209     public final void reset()
210     {
211         int[] cols = materialized_cols;
212
213         if (cols != null)
214         {
215             // New row, clear the array map.
216

217             /*
218              * this was too slow.
219             for (int i = cols.length - 1; i >= 0;)
220             {
221                 
222                 cols[i--] = 0;
223             }
224             */

225
226             if (cols.length <= ZERO_FILL_LENGTH)
227             {
228                 // fast path the usual case.
229
System.arraycopy(
230                     zero_fill_array, 0,
231                     cols, 0,
232                     cols.length);
233             }
234             else
235             {
236                 int offset = 0;
237                 int howMany = cols.length;
238
239                 while (howMany > 0)
240                 {
241                     int count =
242                         howMany > zero_fill_array.length ?
243                                 zero_fill_array.length : howMany;
244
245                     System.arraycopy(
246                         zero_fill_array, 0, cols, offset, count);
247                     howMany -= count;
248                     offset += count;
249                 }
250             }
251         }
252     }
253 }
254
Popular Tags