001: /*
002:
003: Derby - Class org.apache.derby.impl.store.access.conglomerate.BinaryOrderableWrapper
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.services.io.ArrayInputStream;
025:
026: import org.apache.derby.iapi.services.sanity.SanityManager;
027:
028: import org.apache.derby.iapi.services.io.Storable;
029: import org.apache.derby.iapi.services.io.TypedFormat;
030:
031: import org.apache.derby.iapi.error.StandardException;
032:
033: import org.apache.derby.iapi.store.access.BinaryOrderable;
034:
035: import java.io.Externalizable;
036: import java.io.ObjectOutput;
037: import java.io.ObjectInput;
038: import java.io.IOException;
039:
040: /**
041:
042: The BinaryOrderableWrapper is a wrapper class which intercepts the
043: readExternal() callback made by raw store during a fetch, and does a comparison
044: instead.
045: **/
046:
047: class BinaryOrderableWrapper implements Storable {
048:
049: BinaryOrderable ref_object;
050: BinaryOrderable other_object;
051: int cmp_result;
052:
053: /* Constructors for This class: */
054: BinaryOrderableWrapper() {
055: }
056:
057: /* Private/Protected methods of This class: */
058: /**
059: * Short one line description of routine.
060: * <p>
061: * Longer descrption of routine.
062: * <p>
063: *
064: * @param ref_object The object that this object is wrapping (ie. being
065: * read from disk)
066: * @param other_object The object to compare ref_object to.
067: **/
068: protected void init(BinaryOrderable ref_object,
069: BinaryOrderable other_object) {
070: this .ref_object = ref_object;
071: this .other_object = other_object;
072: }
073:
074: /* Public Methods of This class: */
075: /**
076: * Short one line description of routine.
077: * <p>
078: * Longer descrption of routine.
079: * <p>
080: *
081: * @return The identifier to be used to open the conglomerate later.
082: **/
083: public int getCmpResult() {
084: return (this .cmp_result);
085: }
086:
087: /* Public Methods of Storable interface - Externalizable, TypedFormat:
088: */
089:
090: public int getTypeFormatId() {
091: // RESOLVE - what should this return?
092: if (SanityManager.DEBUG)
093: SanityManager
094: .THROWASSERT("If someone calls this it is a problem.");
095: return (((TypedFormat) this .ref_object).getTypeFormatId());
096: }
097:
098: /**
099: Return whether the value is null or not.
100: The containerid being zero is what determines nullness; subclasses
101: are not expected to override this method.
102: @see org.apache.derby.iapi.services.io.Storable#isNull
103: **/
104: public boolean isNull() {
105: // RESOLVE - what does it mean for this wrapper to be called isNull()?
106: if (SanityManager.DEBUG)
107: SanityManager
108: .THROWASSERT("If someone calls this it is a problem.");
109: return (false);
110: }
111:
112: /**
113: Restore the in-memory representation to the null value.
114: The containerid being zero is what determines nullness; subclasses
115: are not expected to override this method.
116:
117: @see org.apache.derby.iapi.services.io.Storable#restoreToNull
118: **/
119: public void restoreToNull() {
120: // RESOLVE - base object is null.
121: if (SanityManager.DEBUG)
122: SanityManager
123: .THROWASSERT("WORK TODO - code up null compare.");
124:
125: return;
126: }
127:
128: /**
129: Restore the in-memory representation from the stream.
130:
131: @exception ClassNotFoundException Thrown if the stored representation is
132: serialized and a class named in the stream could not be found.
133:
134: @exception IOException thrown by readObject()
135:
136:
137: @see java.io.Externalizable#readExternal
138: */
139: public void readExternal(ObjectInput in) throws IOException,
140: ClassNotFoundException {
141:
142: // do the read byte by byte and return the comparison
143: this .cmp_result = this .ref_object.binarycompare(in,
144: this .other_object);
145:
146: if (SanityManager.DEBUG)
147: SanityManager
148: .THROWASSERT("WORK TODO - code up readExternal.");
149: }
150:
151: public void readExternalFromArray(ArrayInputStream in)
152: throws IOException, ClassNotFoundException {
153:
154: // do the read byte by byte and return the comparison
155: this .cmp_result = this .ref_object.binarycompare(in,
156: this .other_object);
157:
158: if (SanityManager.DEBUG)
159: SanityManager
160: .THROWASSERT("WORK TODO - code up readExternal.");
161: }
162:
163: /**
164: * Store the stored representation of the column value in the stream.
165: * <p>
166: * A BinaryOrderableWrapper is never used to store data out, only to read
167: * data from disk and compare it to another byte stream.
168: *
169: * @param out Stream to write the object to.
170: *
171: * @exception IOException thrown by writeObject()
172: *
173: **/
174: public void writeExternal(ObjectOutput out) throws IOException {
175: if (SanityManager.DEBUG)
176: SanityManager.THROWASSERT("Write should never be called.");
177: return;
178: }
179: }
|