001: /*
002:
003: Derby - Class org.apache.derbyTesting.unitTests.store.T_SecondaryIndexRow
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.derbyTesting.unitTests.store;
023:
024: import org.apache.derby.impl.store.access.conglomerate.*;
025:
026: import org.apache.derby.iapi.services.sanity.SanityManager;
027:
028: import org.apache.derby.iapi.services.io.Storable;
029:
030: import org.apache.derby.iapi.error.StandardException;
031:
032: import org.apache.derby.iapi.types.DataValueDescriptor;
033:
034: import org.apache.derby.iapi.types.RowLocation;
035:
036: /**
037: This class implements a row which will be stored in a secondary index on
038: a heap table.
039: <p>
040: This class creates a new DataValueDescriptor array which will be the row used
041: to insert into the secondary index. The fields of this object array are made
042: up of references to DataValueDescriptors provided by the caller: the
043: DataValueDescriptors in the template and a RowLocation.
044: The interface is designed to support the standard access method interface
045: where callers provide a single template and then read rows into that template
046: over and over. This class keeps a reference to the objects in the template
047: and the rowlocation,
048: so the state of this object changes whenever the caller changes the template.
049: The caller provides a template which will contain a heap row,
050: and a RowLocation which provides the location of the row within the heap table.
051: <p>
052: So for example to create an index from a base table by reading the base table
053: and inserting each row one at a time into the secondary index you would
054: do something like:
055:
056: DataValueDescriptors[] template = get_template_for_base_table();
057: RowLocation rowloc = ScanController_var.newRowLocationTemplate();
058: T_SecondaryIndexRow indrow = new T_SecondaryIndexRow();
059:
060: indrow.init(template, rowloc, numcols_in_index);
061:
062: while (ScanController_variable.next())
063: {
064: fetch(template)
065: fetchLocation(rowloc)
066:
067: ConglomerateController_on_btree.insert(indrow.getRow());
068: }
069:
070: **/
071:
072: public class T_SecondaryIndexRow {
073:
074: DataValueDescriptor[] row;
075: RowLocation init_rowlocation = null;
076:
077: /* Constructors for This class: */
078: public T_SecondaryIndexRow() {
079: }
080:
081: /* Private/Protected methods of This class: */
082: /* Public Methods of T_SecondaryIndexRow class: */
083:
084: /**
085: * get the rows location field.
086: *
087: * @return The base table row location field from the secondary index.
088: *
089: * @exception StandardException Standard exception policy.
090: **/
091: /*
092: private RowLocation getRowLocationField()
093: throws StandardException
094: {
095: return(init_rowlocation);
096: }
097: */
098:
099: /**
100: * Initialize the class.
101: * <p>
102: * Save away pointers to the base table template row, and the rowlocation
103: * class. Build default map of base columns to key columns, this map
104: * can be changed with setMap().
105: * <p>
106: *
107: * @param template The template for the base table row.
108: * @param rowlocation The template for the row location.
109: * @param numkeys The total number of columns in the secondary index
110: * including the rowlocation column.
111: *
112: * @exception StandardException Standard exception policy.
113: **/
114: public void init(DataValueDescriptor[] template,
115: RowLocation rowlocation, int numkeys)
116: throws StandardException {
117: if (SanityManager.DEBUG) {
118: if (numkeys != (template.length + 1))
119: SanityManager.THROWASSERT("numkeys = " + numkeys
120: + " template.length = " + template.length);
121: }
122:
123: init_rowlocation = rowlocation;
124:
125: /* create new object array for the row, and copy all object references
126: * from template row to new secondary index row.
127: */
128: row = new DataValueDescriptor[numkeys];
129:
130: System.arraycopy(template, 0, row, 0, template.length);
131:
132: /* add the reference to the row location column as the last column */
133: row[row.length - 1] = rowlocation;
134: }
135:
136: /**
137: * Return the secondary index row.
138: * <p>
139: * Return the DataValueDescriptor array that represents the branch row,
140: * for use in raw store calls to fetch, insert, and update.
141: * <p>
142: *
143: * @return The branch row object array.
144: **/
145: public DataValueDescriptor[] getRow() {
146: return (this .row);
147: }
148:
149: public String toString() {
150: String s = "{ ";
151: for (int colid = 0; colid < row.length; colid++) {
152: s += row[colid];
153: if (colid < (row.length - 1))
154: s += ", ";
155: }
156: s += " }";
157: return s;
158: }
159: }
|