001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.btree.index.B2IStaticCompiledInfo
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.btree.index;
023:
024: import org.apache.derby.iapi.services.io.ArrayInputStream;
025:
026: import org.apache.derby.iapi.services.monitor.Monitor;
027:
028: import org.apache.derby.iapi.services.io.FormatIdUtil;
029: import org.apache.derby.iapi.services.io.StoredFormatIds;
030:
031: import org.apache.derby.iapi.error.StandardException;
032:
033: import org.apache.derby.iapi.store.access.conglomerate.Conglomerate;
034:
035: import org.apache.derby.iapi.store.access.StaticCompiledOpenConglomInfo;
036: import org.apache.derby.iapi.store.access.TransactionController;
037:
038: import org.apache.derby.iapi.types.DataValueDescriptor;
039:
040: import java.io.IOException;
041: import java.io.ObjectInput;
042: import java.io.ObjectOutput;
043:
044: /**
045:
046: This class implements the static compiled information relevant to a btree
047: secondary index. It is what is returned by
048: B2I.getStaticCompiledOpenConglomInfo().
049: <p>
050: Currently the only interesting information stored is Conglomerate for this
051: index and the Conglomerate for the base table of this conglomerate.
052:
053: **/
054:
055: public class B2IStaticCompiledInfo implements
056: StaticCompiledOpenConglomInfo {
057:
058: /**************************************************************************
059: * Fields of the class
060: **************************************************************************
061: */
062:
063: /**
064: * Conglomerate data structure for this index.
065: **/
066: B2I b2i;
067:
068: /**
069: * Conglomerate data structure for this base table of this index.
070: **/
071: StaticCompiledOpenConglomInfo base_table_static_info;
072:
073: /**************************************************************************
074: * Constructors for This class:
075: **************************************************************************
076: */
077:
078: /**
079: * Empty arg constructor used by the monitor to create object to read into.
080: **/
081: public B2IStaticCompiledInfo() {
082: }
083:
084: /**
085: * Constructor used to build class from scratch.
086: * <p>
087: * @param b2i the btree Conglomerate that we are compiling.
088: **/
089: B2IStaticCompiledInfo(TransactionController tc, B2I b2i)
090: throws StandardException {
091: this .b2i = b2i;
092:
093: this .base_table_static_info = tc
094: .getStaticCompiledConglomInfo(b2i.baseConglomerateId);
095: }
096:
097: /**************************************************************************
098: * Private/Protected methods of This class:
099: **************************************************************************
100: */
101:
102: /**************************************************************************
103: * Public Methods of This class:
104: **************************************************************************
105: */
106:
107: /**************************************************************************
108: * Public Methods of StaticCompiledOpenConglomInfo Interface:
109: **************************************************************************
110: */
111:
112: /**
113: * return the "Conglomerate".
114: * <p>
115: * For secondaryindex compiled info return the secondary index conglomerate.
116: * <p>
117: *
118: * @return the secondary index Conglomerate Object.
119: **/
120: public DataValueDescriptor getConglom() {
121: return (b2i);
122: }
123:
124: /**************************************************************************
125: * Public Methods of Storable Interface (via StaticCompiledOpenConglomInfo):
126: * This class is responsible for re/storing its own state.
127: **************************************************************************
128: */
129:
130: /**
131: Return whether the value is null or not.
132: The containerid being zero is what determines nullness; subclasses
133: are not expected to override this method.
134: @see org.apache.derby.iapi.services.io.Storable#isNull
135: **/
136: public boolean isNull() {
137: return (b2i == null);
138: }
139:
140: /**
141: Restore the in-memory representation to the null value.
142: The containerid being zero is what determines nullness; subclasses
143: are not expected to override this method.
144:
145: @see org.apache.derby.iapi.services.io.Storable#restoreToNull
146: **/
147: public void restoreToNull() {
148: b2i = null;
149: }
150:
151: /**
152: * Return my format identifier.
153: *
154: * @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId
155: **/
156: public int getTypeFormatId() {
157: return StoredFormatIds.ACCESS_B2I_STATIC_COMPILED_V1_ID;
158: }
159:
160: /**
161: Restore the in-memory representation from the stream.
162:
163: @exception ClassNotFoundException Thrown if the stored representation is
164: serialized and a class named in the stream could not be found.
165:
166: @exception IOException thrown by readObject()
167:
168:
169: @see java.io.Externalizable#readExternal
170: */
171: public void readExternal(ObjectInput in) throws IOException,
172: ClassNotFoundException {
173: // read in the B2I
174: b2i = new B2I();
175: b2i.readExternal(in);
176:
177: // read in base table conglomerate
178: base_table_static_info = (StaticCompiledOpenConglomInfo) in
179: .readObject();
180: }
181:
182: public void readExternalFromArray(ArrayInputStream in)
183: throws IOException, ClassNotFoundException {
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 = (StaticCompiledOpenConglomInfo) in
190: .readObject();
191: }
192:
193: /**
194: Store the stored representation of the column value in the stream.
195: It might be easier to simply store the properties - which would certainly
196: make upgrading easier.
197:
198: @exception IOException thrown by writeObject()
199:
200: */
201: public void writeExternal(ObjectOutput out) throws IOException {
202: // first write the B2I object (the type we "know")
203: b2i.writeExternal(out);
204:
205: // write Conglomerate object as an object
206: out.writeObject(base_table_static_info);
207: }
208: }
|