KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > store > access > StorableFormatId


1 /*
2
3    Derby - Class org.apache.derby.impl.store.access.StorableFormatId
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;
23
24 import org.apache.derby.iapi.reference.SQLState;
25
26 import org.apache.derby.iapi.services.io.ArrayInputStream;
27
28 import org.apache.derby.iapi.services.sanity.SanityManager;
29
30 import org.apache.derby.iapi.services.io.Storable;
31
32 import org.apache.derby.iapi.services.io.FormatIdUtil;
33 import org.apache.derby.iapi.services.io.StoredFormatIds;
34
35 import org.apache.derby.iapi.error.StandardException;
36
37 import org.apache.derby.iapi.types.DataValueDescriptor;
38
39 import org.apache.derby.iapi.types.Orderable;
40
41 import org.apache.derby.iapi.services.cache.ClassSize;
42
43 import org.apache.derby.iapi.types.DataType;
44
45 import java.sql.ResultSet JavaDoc;
46 import java.sql.SQLException JavaDoc;
47
48 import java.io.ObjectOutput JavaDoc;
49 import java.io.ObjectInput JavaDoc;
50 import java.io.IOException JavaDoc;
51
52 public class StorableFormatId extends DataType
53 {
54
55     private int format_id;
56
57     private static final int BASE_MEMORY_USAGE = ClassSize.estimateBaseFromCatalog( StorableFormatId.class);
58
59     public int estimateMemoryUsage()
60     {
61         return BASE_MEMORY_USAGE;
62     }
63
64     /* Constructors: */
65
66     public StorableFormatId()
67     {
68     }
69
70     public StorableFormatId(int value)
71     {
72         this.format_id = value;
73     }
74
75     /* Private methods */
76
77     public int getValue()
78     {
79         // RESOLVE (mikem) just temporary; value could be null
80
return format_id;
81     }
82
83     public void setValue(int input_value)
84     {
85         this.format_id = input_value;
86     }
87
88     /*
89      * Storable interface, implies Externalizable, TypedFormat
90      */

91
92     /**
93         Return my format identifier.
94
95         @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId
96     */

97     public int getTypeFormatId()
98     {
99         return StoredFormatIds.ACCESS_FORMAT_ID;
100     }
101
102     public boolean isNull()
103     {
104         return false;
105     }
106
107     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc
108     {
109        FormatIdUtil.writeFormatIdInteger(out, format_id);
110     }
111
112     /** @see java.io.Externalizable#readExternal */
113     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc
114     {
115         format_id = FormatIdUtil.readFormatIdInteger(in);
116     }
117     public void readExternalFromArray(ArrayInputStream in) throws IOException JavaDoc
118     {
119         format_id = FormatIdUtil.readFormatIdInteger(in);
120     }
121
122
123     public void restoreToNull()
124     {
125         format_id = 0;
126     }
127
128     /**************************************************************************
129      * Public Methods implementing DataValueDescriptor interface.
130      **************************************************************************
131      */

132
133     /**
134      * Gets the length of the data value. The meaning of this is
135      * implementation-dependent. For string types, it is the number of
136      * characters in the string. For numeric types, it is the number of
137      * bytes used to store the number. This is the actual length
138      * of this value, not the length of the type it was defined as.
139      * For example, a VARCHAR value may be shorter than the declared
140      * VARCHAR (maximum) length.
141      *
142      * @return The length of the data value
143      *
144      * @exception StandardException On error
145      *
146      * @see org.apache.derby.iapi.types.DataValueDescriptor#getLength
147      */

148     public int getLength()
149         throws StandardException
150     {
151         throw(StandardException.newException(
152                 SQLState.HEAP_UNIMPLEMENTED_FEATURE));
153     }
154     /**
155      * Gets the value in the data value descriptor as a String.
156      * Throws an exception if the data value is not a string.
157      *
158      * @return The data value as a String.
159      *
160      * @exception StandardException Thrown on error
161      *
162      * @see org.apache.derby.iapi.types.DataValueDescriptor#getString
163      */

164     public String JavaDoc getString() throws StandardException
165     {
166         throw(StandardException.newException(
167                 SQLState.HEAP_UNIMPLEMENTED_FEATURE));
168     }
169
170     /**
171      * Gets the value in the data value descriptor as a Java Object.
172      * The type of the Object will be the Java object type corresponding
173      * to the data value's SQL type. JDBC defines a mapping between Java
174      * object types and SQL types - we will allow that to be extended
175      * through user type definitions. Throws an exception if the data
176      * value is not an object (yeah, right).
177      *
178      * @return The data value as an Object.
179      *
180      * @exception StandardException Thrown on error
181      *
182      * @see org.apache.derby.iapi.types.DataValueDescriptor#getObject
183      */

184     public Object JavaDoc getObject() throws StandardException
185     {
186         return(this);
187     }
188
189     /**
190      * <U>Shallow copy</U>.
191      * <p>
192      * Clone the DataValueDescriptor and copy its contents.
193      * We clone the data value wrapper (e.g. SQLDecimal)
194      * and reuse its contents (the underlying BigDecimal).
195      * The resultant DataValueDescriptor will point to the same
196      * value as the original DataValueDescriptor (unless the value
197      * is a primitive type, e.g. SQLInteger/integer).
198      *
199      * @return A clone of the DataValueDescriptor reusing its contents.
200      *
201      * @see org.apache.derby.iapi.types.DataValueDescriptor#getClone
202      */

203     public DataValueDescriptor getClone()
204     {
205         if (SanityManager.DEBUG)
206             SanityManager.THROWASSERT("Not implemented!.");
207
208         return(null);
209     }
210
211     /**
212      * Get a new null value of the same type as this data value.
213      *
214      * @see org.apache.derby.iapi.types.DataValueDescriptor#getNewNull
215      */

216     public DataValueDescriptor getNewNull()
217     {
218         if (SanityManager.DEBUG)
219             SanityManager.THROWASSERT("Not implemented!.");
220
221         return(null);
222     }
223
224     /**
225      * Set the value based on the value for the specified DataValueDescriptor
226      * from the specified ResultSet.
227      *
228      * @param resultSet The specified ResultSet.
229      * @param colNumber The 1-based column # into the resultSet.
230      * @param isNullable Whether or not the column is nullable
231      * (No need to call wasNull() if not)
232      *
233      * @exception StandardException Thrown on error
234      * @exception SQLException Error accessing the result set
235      *
236      * @see org.apache.derby.iapi.types.DataValueDescriptor#setValueFromResultSet
237      */

238     public void setValueFromResultSet(
239     ResultSet JavaDoc resultSet,
240     int colNumber,
241     boolean isNullable)
242         throws StandardException, SQLException JavaDoc
243     {
244         throw(StandardException.newException(
245                 SQLState.HEAP_UNIMPLEMENTED_FEATURE));
246     }
247
248     /**
249      * Set the value of this DataValueDescriptor from another.
250      *
251      * @param theValue The Date value to set this DataValueDescriptor to
252      *
253      * @see org.apache.derby.iapi.types.DataValueDescriptor#setValue
254      */

255     protected void setFrom(DataValueDescriptor theValue)
256         throws StandardException
257     {
258         throw(StandardException.newException(
259                 SQLState.HEAP_UNIMPLEMENTED_FEATURE));
260     }
261
262     /**
263      * Get the SQL name of the datatype
264      *
265      * @return The SQL name of the datatype
266      *
267      * @see org.apache.derby.iapi.types.DataValueDescriptor#getTypeName
268      */

269     public String JavaDoc getTypeName()
270     {
271         if (SanityManager.DEBUG)
272             SanityManager.THROWASSERT("Not implemented!.");
273
274         return(null);
275     }
276
277     /**
278      * Compare this Orderable with a given Orderable for the purpose of
279      * index positioning. This method treats nulls as ordered values -
280      * that is, it treats SQL null as equal to null and less than all
281      * other values.
282      *
283      * @param other The Orderable to compare this one to.
284      *
285      * @return <0 - this Orderable is less than other.
286      * 0 - this Orderable equals other.
287      * >0 - this Orderable is greater than other.
288      *
289      * The code should not explicitly look for -1, or 1.
290      *
291      * @exception StandardException Thrown on error
292      *
293      * @see DataValueDescriptor#compare
294      */

295     public int compare(DataValueDescriptor other)
296         throws StandardException
297     {
298         throw(StandardException.newException(
299                 SQLState.HEAP_UNIMPLEMENTED_FEATURE));
300     }
301
302
303 }
304
Popular Tags