KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > conglomerate > OpenConglomerateScratchSpace


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.conglomerate.OpenConglomerateScratchSpace
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.store.access.conglomerate;
23
24 import org.apache.derby.iapi.error.StandardException;
25
26 import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
27 import org.apache.derby.iapi.store.access.RowUtil;
28
29 import org.apache.derby.iapi.types.DataValueDescriptor;
30
31 import org.apache.derby.iapi.services.io.FormatableBitSet;
32 import org.apache.derby.iapi.services.loader.InstanceGetter;
33
34 /**
35
36 A utility class to store and use temporary scratch space associated with
37 a conglomerate.
38
39 **/

40
41 public class OpenConglomerateScratchSpace
42     implements DynamicCompiledOpenConglomInfo
43 {
44
45     /**************************************************************************
46      * Fields of the class
47      **************************************************************************
48      */

49
50     /**
51      * A template of info about the classes in the returned row.
52      * <p>
53      * This template is allocated on demand, and is used to efficiently
54      * create new rows for export from this class. This variable is for
55      * use by get_row_for_export().
56      **/

57     private FormatableBitSet row_for_export_column_list;
58     private InstanceGetter[] row_for_export_class_template;
59
60     /**
61      * A Scratch template used for searching and qualifying rows in the
62      * conglomerate. This is a full template, independent of the FormatableBitSet
63      * used for access.
64      **/

65     private DataValueDescriptor[] scratch_template;
66
67     /**
68      * A Scratch row used for qualifying rows in the
69      * conglomerate. This is a row which matches the FormatableBitSet of rows being
70      * returned.
71      **/

72     private DataValueDescriptor[] scratch_row;
73
74     /**
75      * A complete array of format id's for this conglomerate.
76      **/

77     private int[] format_ids;
78
79     /**************************************************************************
80      * Constructors for This class:
81      **************************************************************************
82      */

83     public OpenConglomerateScratchSpace(
84     int[] format_ids)
85     {
86         this.format_ids = format_ids;
87     }
88
89     /**************************************************************************
90      * Private/Protected methods of This class:
91      **************************************************************************
92      */

93
94     /**************************************************************************
95      * Public Methods of This class:
96      **************************************************************************
97      */

98
99     /**
100      * Return an empty template (possibly partial) row to be given back to
101      * a client.
102      * <p>
103      * The main use of this is for fetchSet() and fetchNextGroup() which
104      * allocate rows and then give them back entirely to the caller.
105      * <p>
106      *
107      * @return The row to use.
108      *
109      * @exception StandardException Standard exception policy.
110      **/

111     public DataValueDescriptor[] get_row_for_export()
112         throws StandardException
113     {
114         // Create a partial row class template template from the initial scan
115
// parameters.
116
if (row_for_export_class_template == null)
117         {
118             row_for_export_class_template =
119                 RowUtil.newClassInfoTemplate(
120                     row_for_export_column_list, format_ids);
121         }
122
123         // Allocate a new row based on the class template.
124
return(
125             RowUtil.newRowFromClassInfoTemplate(row_for_export_class_template));
126     }
127
128     /**
129      * Return an empty template (possibly partial) row to be used and
130      * reused internally for processing.
131      * <p>
132      * The main use of this is for qualifying rows where a row has not been
133      * provided by the client. This routine cache's a single row for reuse
134      * by the caller, if the caller needs 2 concurrent scratch rows, some other
135      * mechanism must be used.
136      * <p>
137      *
138      * @return The row to use.
139      *
140      * @exception StandardException Standard exception policy.
141      **/

142     public DataValueDescriptor[] get_scratch_row()
143         throws StandardException
144     {
145         // Create a partial row class template template from the initial scan
146
// parameters.
147
if (scratch_row == null)
148         {
149             scratch_row = get_row_for_export();
150         }
151
152         // Allocate a new row based on the class template.
153
return(scratch_row);
154     }
155
156     /**
157      * Return a complete empty row.
158      * <p>
159      * The main use of this is for searching a tree where a complete copy of
160      * the row is needed for searching.
161      * <p>
162      *
163      * @return The template to use.
164      *
165      * @exception StandardException Standard exception policy.
166      **/

167     public DataValueDescriptor[] get_template()
168         throws StandardException
169     {
170         // Create a partial row class template from the initial scan parameters.
171
if (scratch_template == null)
172         {
173             scratch_template = TemplateRow.newRow((FormatableBitSet) null, format_ids);
174         }
175
176         return(scratch_template);
177     }
178
179     /**
180      * Initialize scratch space for reuse by possibly different template.
181      * <p>
182      * Some data is only valid per statement.
183      **/

184     public void init(
185     FormatableBitSet export_column_list)
186     {
187         row_for_export_class_template = null;
188         row_for_export_column_list = null;
189     }
190 }
191
Popular Tags