KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > iapi > types > SQLLongVarbit


1 /*
2
3    Derby - Class org.apache.derby.iapi.types.SQLLongVarbit
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.iapi.types;
23
24 import org.apache.derby.iapi.types.DataTypeDescriptor;
25 import org.apache.derby.iapi.types.DataValueDescriptor;
26 import org.apache.derby.iapi.types.TypeId;
27 import org.apache.derby.iapi.types.BitDataValue;
28 import org.apache.derby.iapi.types.DataValueDescriptor;
29 import org.apache.derby.iapi.reference.SQLState;
30 import org.apache.derby.iapi.reference.Limits;
31 import org.apache.derby.iapi.error.StandardException;
32
33 import org.apache.derby.iapi.types.Orderable;
34
35 import org.apache.derby.iapi.services.io.FormatIdUtil;
36 import org.apache.derby.iapi.services.io.StoredFormatIds;
37
38 import org.apache.derby.iapi.services.sanity.SanityManager;
39
40 import org.apache.derby.iapi.types.BooleanDataValue;
41 import org.apache.derby.iapi.types.StringDataValue;
42 import org.apache.derby.iapi.types.NumberDataValue;
43
44 import java.io.ObjectOutput JavaDoc;
45 import java.io.ObjectInput JavaDoc;
46 import java.io.IOException JavaDoc;
47 import java.sql.ResultSet JavaDoc;
48 import java.sql.SQLException JavaDoc;
49
50 /**
51  * SQLLongVarbit represents the SQL type LONG VARCHAR FOR BIT DATA
52  * It is an extension of SQLVarbit and is virtually indistinguishable
53  * other than normalization.
54  */

55 public class SQLLongVarbit extends SQLVarbit
56 {
57
58     public String JavaDoc getTypeName()
59     {
60         return TypeId.LONGVARBIT_NAME;
61     }
62
63     /**
64      * Return max memory usage for a SQL LongVarbit
65      */

66     int getMaxMemoryUsage()
67     {
68         return Limits.DB2_LONGVARCHAR_MAXWIDTH;
69     }
70
71     /**
72      * @see DataValueDescriptor#getNewNull
73      */

74     public DataValueDescriptor getNewNull()
75     {
76         return new SQLLongVarbit();
77     }
78
79     /**
80         Return my format identifier.
81
82         @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId
83     */

84     public int getTypeFormatId()
85     {
86         return StoredFormatIds.SQL_LONGVARBIT_ID;
87     }
88
89
90     /*
91      * Orderable interface
92      */

93
94
95     /*
96      * Column interface
97      */

98
99
100     /*
101      * class interface
102      */

103
104     /*
105      * constructors
106      */

107     public SQLLongVarbit()
108     {
109     }
110
111     public SQLLongVarbit(byte[] val)
112     {
113         super(val);
114     }
115
116     /**
117      * Normalization method - this method may be called when putting
118      * a value into a SQLVarbit, for example, when inserting into a SQLVarbit
119      * column. See NormalizeResultSet in execution.
120      *
121      * This overrides SQLBit -- the difference is that we don't
122      * expand SQLVarbits to fit the target.
123      *
124      * @param desiredType The type to normalize the source column to
125      * @param source The value to normalize
126      *
127      *
128      * @exception StandardException Thrown for null into
129      * non-nullable column, and for
130      * truncation error
131      */

132
133     public void normalize(
134                 DataTypeDescriptor desiredType,
135                 DataValueDescriptor source)
136                     throws StandardException
137     {
138         if (source instanceof SQLLongVarbit) {
139             // avoid creating an object in memory if a matching type.
140
// this may be a stream.
141
SQLLongVarbit other = (SQLLongVarbit) source;
142             this.stream = other.stream;
143             this.dataValue = other.dataValue;
144         }
145         else
146             setValue(source.getBytes());
147     }
148
149     /*
150      * DataValueDescriptor interface
151      */

152
153     /** @see DataValueDescriptor#typePrecedence */
154     public int typePrecedence()
155     {
156         return TypeId.LONGVARBIT_PRECEDENCE;
157     }
158 }
159
Popular Tags