KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > conglomerate > BinaryOrderableWrapper


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.conglomerate.BinaryOrderableWrapper
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.conglomerate;
23
24
25 import org.apache.derby.iapi.services.io.ArrayInputStream;
26
27 import org.apache.derby.iapi.services.sanity.SanityManager;
28
29 import org.apache.derby.iapi.services.io.Storable;
30 import org.apache.derby.iapi.services.io.TypedFormat;
31
32 import org.apache.derby.iapi.error.StandardException;
33
34 import org.apache.derby.iapi.store.access.BinaryOrderable;
35
36 import java.io.Externalizable JavaDoc;
37 import java.io.ObjectOutput JavaDoc;
38 import java.io.ObjectInput JavaDoc;
39 import java.io.IOException JavaDoc;
40
41 /**
42
43 The BinaryOrderableWrapper is a wrapper class which intercepts the
44 readExternal() callback made by raw store during a fetch, and does a comparison
45 instead.
46 **/

47
48 class BinaryOrderableWrapper implements Storable
49 {
50
51     BinaryOrderable ref_object;
52     BinaryOrderable other_object;
53     int cmp_result;
54
55     /* Constructors for This class: */
56     BinaryOrderableWrapper()
57     {
58     }
59
60     /* Private/Protected methods of This class: */
61     /**
62      * Short one line description of routine.
63      * <p>
64      * Longer descrption of routine.
65      * <p>
66      *
67      * @param ref_object The object that this object is wrapping (ie. being
68      * read from disk)
69      * @param other_object The object to compare ref_object to.
70      **/

71     protected void init (
72     BinaryOrderable ref_object,
73     BinaryOrderable other_object)
74     {
75         this.ref_object = ref_object;
76         this.other_object = other_object;
77     }
78
79     /* Public Methods of This class: */
80     /**
81      * Short one line description of routine.
82      * <p>
83      * Longer descrption of routine.
84      * <p>
85      *
86      * @return The identifier to be used to open the conglomerate later.
87      **/

88     public int getCmpResult()
89     {
90         return(this.cmp_result);
91     }
92
93
94     /* Public Methods of Storable interface - Externalizable, TypedFormat:
95     */

96
97     public int getTypeFormatId() {
98         // RESOLVE - what should this return?
99
if (SanityManager.DEBUG)
100             SanityManager.THROWASSERT("If someone calls this it is a problem.");
101         return(((TypedFormat)this.ref_object).getTypeFormatId());
102     }
103
104     /**
105     Return whether the value is null or not.
106     The containerid being zero is what determines nullness; subclasses
107     are not expected to override this method.
108     @see org.apache.derby.iapi.services.io.Storable#isNull
109     **/

110     public boolean isNull()
111     {
112         // RESOLVE - what does it mean for this wrapper to be called isNull()?
113
if (SanityManager.DEBUG)
114             SanityManager.THROWASSERT("If someone calls this it is a problem.");
115         return(false);
116     }
117
118     /**
119     Restore the in-memory representation to the null value.
120     The containerid being zero is what determines nullness; subclasses
121     are not expected to override this method.
122
123     @see org.apache.derby.iapi.services.io.Storable#restoreToNull
124     **/

125     public void restoreToNull()
126     {
127         // RESOLVE - base object is null.
128
if (SanityManager.DEBUG)
129             SanityManager.THROWASSERT("WORK TODO - code up null compare.");
130
131         return;
132     }
133
134     /**
135     Restore the in-memory representation from the stream.
136
137     @exception ClassNotFoundException Thrown if the stored representation is
138     serialized and a class named in the stream could not be found.
139
140     @exception IOException thrown by readObject()
141
142     
143     @see java.io.Externalizable#readExternal
144     */

145     public void readExternal(ObjectInput JavaDoc in)
146         throws IOException JavaDoc, ClassNotFoundException JavaDoc
147     {
148
149         // do the read byte by byte and return the comparison
150
this.cmp_result = this.ref_object.binarycompare(in, this.other_object);
151         
152         if (SanityManager.DEBUG)
153             SanityManager.THROWASSERT("WORK TODO - code up readExternal.");
154     }
155     public void readExternalFromArray(ArrayInputStream in)
156         throws IOException JavaDoc, ClassNotFoundException JavaDoc
157     {
158
159         // do the read byte by byte and return the comparison
160
this.cmp_result = this.ref_object.binarycompare(in, this.other_object);
161         
162         if (SanityManager.DEBUG)
163             SanityManager.THROWASSERT("WORK TODO - code up readExternal.");
164     }
165     
166     /**
167      * Store the stored representation of the column value in the stream.
168      * <p>
169      * A BinaryOrderableWrapper is never used to store data out, only to read
170      * data from disk and compare it to another byte stream.
171      *
172      * @param out Stream to write the object to.
173      *
174      * @exception IOException thrown by writeObject()
175      *
176      **/

177     public void writeExternal(ObjectOutput JavaDoc out)
178         throws IOException JavaDoc
179     {
180         if (SanityManager.DEBUG)
181             SanityManager.THROWASSERT("Write should never be called.");
182         return;
183     }
184 }
185
Popular Tags