KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > btree > index > B2IStaticCompiledInfo


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.btree.index.B2IStaticCompiledInfo
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.btree.index;
23
24 import org.apache.derby.iapi.services.io.ArrayInputStream;
25
26 import org.apache.derby.iapi.services.monitor.Monitor;
27
28 import org.apache.derby.iapi.services.io.FormatIdUtil;
29 import org.apache.derby.iapi.services.io.StoredFormatIds;
30
31 import org.apache.derby.iapi.error.StandardException;
32
33 import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
34
35 import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
36 import org.apache.derby.iapi.store.access.TransactionController;
37
38 import org.apache.derby.iapi.types.DataValueDescriptor;
39
40
41 import java.io.IOException JavaDoc;
42 import java.io.ObjectInput JavaDoc;
43 import java.io.ObjectOutput JavaDoc;
44
45 /**
46
47 This class implements the static compiled information relevant to a btree
48 secondary index. It is what is returned by
49 B2I.getStaticCompiledOpenConglomInfo().
50 <p>
51 Currently the only interesting information stored is Conglomerate for this
52 index and the Conglomerate for the base table of this conglomerate.
53
54 **/

55
56 public class B2IStaticCompiledInfo implements StaticCompiledOpenConglomInfo
57 {
58
59     /**************************************************************************
60      * Fields of the class
61      **************************************************************************
62      */

63
64     /**
65      * Conglomerate data structure for this index.
66      **/

67     B2I b2i;
68
69     /**
70      * Conglomerate data structure for this base table of this index.
71      **/

72     StaticCompiledOpenConglomInfo base_table_static_info;
73
74     /**************************************************************************
75      * Constructors for This class:
76      **************************************************************************
77      */

78
79     /**
80      * Empty arg constructor used by the monitor to create object to read into.
81      **/

82     public B2IStaticCompiledInfo()
83     {
84     }
85
86     /**
87      * Constructor used to build class from scratch.
88      * <p>
89      * @param b2i the btree Conglomerate that we are compiling.
90      **/

91     B2IStaticCompiledInfo(
92     TransactionController tc,
93     B2I b2i)
94         throws StandardException
95     {
96         this.b2i = b2i;
97
98         this.base_table_static_info =
99             tc.getStaticCompiledConglomInfo(b2i.baseConglomerateId);
100     }
101
102     /**************************************************************************
103      * Private/Protected methods of This class:
104      **************************************************************************
105      */

106
107     /**************************************************************************
108      * Public Methods of This class:
109      **************************************************************************
110      */

111
112     /**************************************************************************
113      * Public Methods of StaticCompiledOpenConglomInfo Interface:
114      **************************************************************************
115      */

116
117     /**
118      * return the "Conglomerate".
119      * <p>
120      * For secondaryindex compiled info return the secondary index conglomerate.
121      * <p>
122      *
123      * @return the secondary index Conglomerate Object.
124      **/

125     public DataValueDescriptor getConglom()
126     {
127         return(b2i);
128     }
129
130     /**************************************************************************
131      * Public Methods of Storable Interface (via StaticCompiledOpenConglomInfo):
132      * This class is responsible for re/storing its own state.
133      **************************************************************************
134      */

135
136
137     /**
138     Return whether the value is null or not.
139     The containerid being zero is what determines nullness; subclasses
140     are not expected to override this method.
141     @see org.apache.derby.iapi.services.io.Storable#isNull
142     **/

143     public boolean isNull()
144     {
145         return(b2i == null);
146     }
147
148     /**
149     Restore the in-memory representation to the null value.
150     The containerid being zero is what determines nullness; subclasses
151     are not expected to override this method.
152
153     @see org.apache.derby.iapi.services.io.Storable#restoreToNull
154     **/

155     public void restoreToNull()
156     {
157         b2i = null;
158     }
159
160     /**
161      * Return my format identifier.
162      *
163      * @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId
164      **/

165     public int getTypeFormatId()
166     {
167         return StoredFormatIds.ACCESS_B2I_STATIC_COMPILED_V1_ID;
168     }
169
170     /**
171     Restore the in-memory representation from the stream.
172
173     @exception ClassNotFoundException Thrown if the stored representation is
174     serialized and a class named in the stream could not be found.
175
176     @exception IOException thrown by readObject()
177
178     
179     @see java.io.Externalizable#readExternal
180     */

181     public void readExternal(ObjectInput JavaDoc in)
182         throws IOException JavaDoc, ClassNotFoundException JavaDoc
183     {
184         // read in the B2I
185
b2i = new B2I();
186         b2i.readExternal(in);
187
188         // read in base table conglomerate
189
base_table_static_info =
190             (StaticCompiledOpenConglomInfo) in.readObject();
191     }
192     public void readExternalFromArray(ArrayInputStream in)
193         throws IOException JavaDoc, ClassNotFoundException JavaDoc
194     {
195         // read in the B2I
196
b2i = new B2I();
197         b2i.readExternal(in);
198
199         // read in base table conglomerate
200
base_table_static_info =
201             (StaticCompiledOpenConglomInfo) in.readObject();
202     }
203     
204     /**
205     Store the stored representation of the column value in the stream.
206     It might be easier to simply store the properties - which would certainly
207     make upgrading easier.
208
209     @exception IOException thrown by writeObject()
210
211     */

212     public void writeExternal(ObjectOutput JavaDoc out)
213         throws IOException JavaDoc
214     {
215         // first write the B2I object (the type we "know")
216
b2i.writeExternal(out);
217
218         // write Conglomerate object as an object
219
out.writeObject(base_table_static_info);
220     }
221 }
222
Popular Tags