KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derbyTesting > unitTests > store > T_SecondaryIndexRow


1 /*
2
3    Derby - Class org.apache.derbyTesting.unitTests.store.T_SecondaryIndexRow
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.derbyTesting.unitTests.store;
23
24 import org.apache.derby.impl.store.access.conglomerate.*;
25
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import org.apache.derby.iapi.services.io.Storable;
29
30 import org.apache.derby.iapi.error.StandardException;
31
32 import org.apache.derby.iapi.types.DataValueDescriptor;
33
34 import org.apache.derby.iapi.types.RowLocation;
35
36
37 /**
38 This class implements a row which will be stored in a secondary index on
39 a heap table.
40 <p>
41 This class creates a new DataValueDescriptor array which will be the row used
42 to insert into the secondary index. The fields of this object array are made
43 up of references to DataValueDescriptors provided by the caller: the
44 DataValueDescriptors in the template and a RowLocation.
45 The interface is designed to support the standard access method interface
46 where callers provide a single template and then read rows into that template
47 over and over. This class keeps a reference to the objects in the template
48 and the rowlocation,
49 so the state of this object changes whenever the caller changes the template.
50 The caller provides a template which will contain a heap row,
51 and a RowLocation which provides the location of the row within the heap table.
52 <p>
53 So for example to create an index from a base table by reading the base table
54 and inserting each row one at a time into the secondary index you would
55 do something like:
56
57 DataValueDescriptors[] template = get_template_for_base_table();
58 RowLocation rowloc = ScanController_var.newRowLocationTemplate();
59 T_SecondaryIndexRow indrow = new T_SecondaryIndexRow();
60
61 indrow.init(template, rowloc, numcols_in_index);
62
63 while (ScanController_variable.next())
64 {
65     fetch(template)
66     fetchLocation(rowloc)
67
68     ConglomerateController_on_btree.insert(indrow.getRow());
69 }
70
71 **/

72
73 public class T_SecondaryIndexRow
74 {
75
76     DataValueDescriptor[] row;
77     RowLocation init_rowlocation = null;
78
79     /* Constructors for This class: */
80     public T_SecondaryIndexRow(){}
81
82     /* Private/Protected methods of This class: */
83     /* Public Methods of T_SecondaryIndexRow class: */
84
85     /**
86      * get the rows location field.
87      *
88      * @return The base table row location field from the secondary index.
89      *
90      * @exception StandardException Standard exception policy.
91      **/

92     /*
93     private RowLocation getRowLocationField()
94         throws StandardException
95     {
96         return(init_rowlocation);
97     }
98     */

99
100     /**
101      * Initialize the class.
102      * <p>
103      * Save away pointers to the base table template row, and the rowlocation
104      * class. Build default map of base columns to key columns, this map
105      * can be changed with setMap().
106      * <p>
107      *
108      * @param template The template for the base table row.
109      * @param rowlocation The template for the row location.
110      * @param numkeys The total number of columns in the secondary index
111      * including the rowlocation column.
112      *
113      * @exception StandardException Standard exception policy.
114      **/

115     public void init(
116     DataValueDescriptor[] template,
117     RowLocation rowlocation,
118     int numkeys)
119         throws StandardException
120     {
121         if (SanityManager.DEBUG)
122         {
123             if (numkeys != (template.length + 1))
124                 SanityManager.THROWASSERT(
125                     "numkeys = " + numkeys +
126                     " template.length = " + template.length);
127         }
128
129         init_rowlocation = rowlocation;
130
131         /* create new object array for the row, and copy all object references
132          * from template row to new secondary index row.
133          */

134         row = new DataValueDescriptor[numkeys];
135
136         System.arraycopy(template, 0, row, 0, template.length);
137
138         /* add the reference to the row location column as the last column */
139         row[row.length - 1] = rowlocation;
140     }
141
142     /**
143      * Return the secondary index row.
144      * <p>
145      * Return the DataValueDescriptor array that represents the branch row,
146      * for use in raw store calls to fetch, insert, and update.
147      * <p>
148      *
149      * @return The branch row object array.
150      **/

151     public DataValueDescriptor[] getRow()
152     {
153         return(this.row);
154     }
155
156     public String JavaDoc toString()
157     {
158         String JavaDoc s = "{ ";
159         for (int colid = 0; colid < row.length; colid++)
160         {
161             s += row[colid];
162             if (colid < (row.length - 1))
163                 s += ", ";
164         }
165         s += " }";
166         return s;
167     }
168 }
169
Popular Tags