001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.conglomerate.OpenConglomerateScratchSpace
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to you under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.store.access.conglomerate;
023:
024: import org.apache.derby.iapi.error.StandardException;
025:
026: import org.apache.derby.iapi.store.access.DynamicCompiledOpenConglomInfo;
027: import org.apache.derby.iapi.store.access.RowUtil;
028:
029: import org.apache.derby.iapi.types.DataValueDescriptor;
030:
031: import org.apache.derby.iapi.services.io.FormatableBitSet;
032: import org.apache.derby.iapi.services.loader.InstanceGetter;
033:
034: /**
035:
036: A utility class to store and use temporary scratch space associated with
037: a conglomerate.
038:
039: **/
040:
041: public class OpenConglomerateScratchSpace implements
042: DynamicCompiledOpenConglomInfo {
043:
044: /**************************************************************************
045: * Fields of the class
046: **************************************************************************
047: */
048:
049: /**
050: * A template of info about the classes in the returned row.
051: * <p>
052: * This template is allocated on demand, and is used to efficiently
053: * create new rows for export from this class. This variable is for
054: * use by get_row_for_export().
055: **/
056: private FormatableBitSet row_for_export_column_list;
057: private InstanceGetter[] row_for_export_class_template;
058:
059: /**
060: * A Scratch template used for searching and qualifying rows in the
061: * conglomerate. This is a full template, independent of the FormatableBitSet
062: * used for access.
063: **/
064: private DataValueDescriptor[] scratch_template;
065:
066: /**
067: * A Scratch row used for qualifying rows in the
068: * conglomerate. This is a row which matches the FormatableBitSet of rows being
069: * returned.
070: **/
071: private DataValueDescriptor[] scratch_row;
072:
073: /**
074: * A complete array of format id's for this conglomerate.
075: **/
076: private int[] format_ids;
077:
078: /**************************************************************************
079: * Constructors for This class:
080: **************************************************************************
081: */
082: public OpenConglomerateScratchSpace(int[] format_ids) {
083: this .format_ids = format_ids;
084: }
085:
086: /**************************************************************************
087: * Private/Protected methods of This class:
088: **************************************************************************
089: */
090:
091: /**************************************************************************
092: * Public Methods of This class:
093: **************************************************************************
094: */
095:
096: /**
097: * Return an empty template (possibly partial) row to be given back to
098: * a client.
099: * <p>
100: * The main use of this is for fetchSet() and fetchNextGroup() which
101: * allocate rows and then give them back entirely to the caller.
102: * <p>
103: *
104: * @return The row to use.
105: *
106: * @exception StandardException Standard exception policy.
107: **/
108: public DataValueDescriptor[] get_row_for_export()
109: throws StandardException {
110: // Create a partial row class template template from the initial scan
111: // parameters.
112: if (row_for_export_class_template == null) {
113: row_for_export_class_template = RowUtil
114: .newClassInfoTemplate(row_for_export_column_list,
115: format_ids);
116: }
117:
118: // Allocate a new row based on the class template.
119: return (RowUtil
120: .newRowFromClassInfoTemplate(row_for_export_class_template));
121: }
122:
123: /**
124: * Return an empty template (possibly partial) row to be used and
125: * reused internally for processing.
126: * <p>
127: * The main use of this is for qualifying rows where a row has not been
128: * provided by the client. This routine cache's a single row for reuse
129: * by the caller, if the caller needs 2 concurrent scratch rows, some other
130: * mechanism must be used.
131: * <p>
132: *
133: * @return The row to use.
134: *
135: * @exception StandardException Standard exception policy.
136: **/
137: public DataValueDescriptor[] get_scratch_row()
138: throws StandardException {
139: // Create a partial row class template template from the initial scan
140: // parameters.
141: if (scratch_row == null) {
142: scratch_row = get_row_for_export();
143: }
144:
145: // Allocate a new row based on the class template.
146: return (scratch_row);
147: }
148:
149: /**
150: * Return a complete empty row.
151: * <p>
152: * The main use of this is for searching a tree where a complete copy of
153: * the row is needed for searching.
154: * <p>
155: *
156: * @return The template to use.
157: *
158: * @exception StandardException Standard exception policy.
159: **/
160: public DataValueDescriptor[] get_template()
161: throws StandardException {
162: // Create a partial row class template from the initial scan parameters.
163: if (scratch_template == null) {
164: scratch_template = TemplateRow.newRow(
165: (FormatableBitSet) null, format_ids);
166: }
167:
168: return (scratch_template);
169: }
170:
171: /**
172: * Initialize scratch space for reuse by possibly different template.
173: * <p>
174: * Some data is only valid per statement.
175: **/
176: public void init(FormatableBitSet export_column_list) {
177: row_for_export_class_template = null;
178: row_for_export_column_list = null;
179: }
180: }
|