001: /*
002:
003: Derby - Class org.apache.derby.iapi.types.SQLLongVarbit
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.iapi.types;
023:
024: import org.apache.derby.iapi.types.DataTypeDescriptor;
025: import org.apache.derby.iapi.types.DataValueDescriptor;
026: import org.apache.derby.iapi.types.TypeId;
027: import org.apache.derby.iapi.types.BitDataValue;
028: import org.apache.derby.iapi.types.DataValueDescriptor;
029: import org.apache.derby.iapi.reference.SQLState;
030: import org.apache.derby.iapi.reference.Limits;
031: import org.apache.derby.iapi.error.StandardException;
032:
033: import org.apache.derby.iapi.types.Orderable;
034:
035: import org.apache.derby.iapi.services.io.FormatIdUtil;
036: import org.apache.derby.iapi.services.io.StoredFormatIds;
037:
038: import org.apache.derby.iapi.services.sanity.SanityManager;
039:
040: import org.apache.derby.iapi.types.BooleanDataValue;
041: import org.apache.derby.iapi.types.StringDataValue;
042: import org.apache.derby.iapi.types.NumberDataValue;
043:
044: import java.io.ObjectOutput;
045: import java.io.ObjectInput;
046: import java.io.IOException;
047: import java.sql.ResultSet;
048: import java.sql.SQLException;
049:
050: /**
051: * SQLLongVarbit represents the SQL type LONG VARCHAR FOR BIT DATA
052: * It is an extension of SQLVarbit and is virtually indistinguishable
053: * other than normalization.
054: */
055: public class SQLLongVarbit extends SQLVarbit {
056:
057: public String getTypeName() {
058: return TypeId.LONGVARBIT_NAME;
059: }
060:
061: /**
062: * Return max memory usage for a SQL LongVarbit
063: */
064: int getMaxMemoryUsage() {
065: return Limits.DB2_LONGVARCHAR_MAXWIDTH;
066: }
067:
068: /**
069: * @see DataValueDescriptor#getNewNull
070: */
071: public DataValueDescriptor getNewNull() {
072: return new SQLLongVarbit();
073: }
074:
075: /**
076: Return my format identifier.
077:
078: @see org.apache.derby.iapi.services.io.TypedFormat#getTypeFormatId
079: */
080: public int getTypeFormatId() {
081: return StoredFormatIds.SQL_LONGVARBIT_ID;
082: }
083:
084: /*
085: * Orderable interface
086: */
087:
088: /*
089: * Column interface
090: */
091:
092: /*
093: * class interface
094: */
095:
096: /*
097: * constructors
098: */
099: public SQLLongVarbit() {
100: }
101:
102: public SQLLongVarbit(byte[] val) {
103: super (val);
104: }
105:
106: /**
107: * Normalization method - this method may be called when putting
108: * a value into a SQLVarbit, for example, when inserting into a SQLVarbit
109: * column. See NormalizeResultSet in execution.
110: *
111: * This overrides SQLBit -- the difference is that we don't
112: * expand SQLVarbits to fit the target.
113: *
114: * @param desiredType The type to normalize the source column to
115: * @param source The value to normalize
116: *
117: *
118: * @exception StandardException Thrown for null into
119: * non-nullable column, and for
120: * truncation error
121: */
122:
123: public void normalize(DataTypeDescriptor desiredType,
124: DataValueDescriptor source) throws StandardException {
125: if (source instanceof SQLLongVarbit) {
126: // avoid creating an object in memory if a matching type.
127: // this may be a stream.
128: SQLLongVarbit other = (SQLLongVarbit) source;
129: this .stream = other.stream;
130: this .dataValue = other.dataValue;
131: } else
132: setValue(source.getBytes());
133: }
134:
135: /*
136: * DataValueDescriptor interface
137: */
138:
139: /** @see DataValueDescriptor#typePrecedence */
140: public int typePrecedence() {
141: return TypeId.LONGVARBIT_PRECEDENCE;
142: }
143: }
|