001: /*
002:
003: Derby - Class org.apache.derby.impl.sql.compile.LOBTypeCompiler
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.sql.compile;
023:
024: import org.apache.derby.iapi.services.loader.ClassFactory;
025:
026: import org.apache.derby.iapi.services.sanity.SanityManager;
027:
028: import org.apache.derby.iapi.services.io.StoredFormatIds;
029:
030: import org.apache.derby.iapi.error.StandardException;
031:
032: import org.apache.derby.iapi.types.BitDataValue;
033: import org.apache.derby.iapi.types.DataValueFactory;
034: import org.apache.derby.iapi.types.TypeId;
035:
036: import org.apache.derby.iapi.types.DataTypeDescriptor;
037:
038: import org.apache.derby.iapi.sql.compile.TypeCompiler;
039:
040: import org.apache.derby.iapi.reference.ClassName;
041:
042: import java.sql.Types;
043: import org.apache.derby.iapi.reference.JDBC20Translation;
044:
045: /**
046: * This class implements TypeCompiler for the SQL LOB types.
047: *
048: * @author Jonas S Karlsson
049: */
050:
051: public class LOBTypeCompiler extends BaseTypeCompiler {
052: /**
053: * Tell whether this type (BLOB) can be compared to the given type. //
054: * BLOBS are not comparable.
055: *
056: * @param otherType The TypeId of the other type.
057: */
058:
059: public boolean comparable(TypeId otherType, boolean forEquals,
060: ClassFactory cf) {
061: return false;
062: }
063:
064: /**
065: * Tell whether this type (LOB) can be converted to the given type.
066: *
067: * @see TypeCompiler#convertible
068: */
069: public boolean convertible(TypeId otherType,
070: boolean forDataTypeFunction) {
071:
072: return (otherType.isBlobTypeId());
073: }
074:
075: /**
076: * Tell whether this type (LOB) is compatible with the given type.
077: *
078: * @param otherType The TypeId of the other type.
079: */
080: public boolean compatible(TypeId otherType) {
081: return convertible(otherType, false);
082: }
083:
084: /**
085: * Tell whether this type (LOB) can be stored into from the given type.
086: *
087: * @param otherType The TypeId of the other type.
088: * @param cf A ClassFactory
089: */
090:
091: public boolean storable(TypeId otherType, ClassFactory cf) {
092: // no automatic conversions at store time
093:
094: return (otherType.isBlobTypeId());
095: }
096:
097: /** @see TypeCompiler#interfaceName */
098: public String interfaceName() {
099: return ClassName.BitDataValue;
100: }
101:
102: /**
103: * @see TypeCompiler#getCorrespondingPrimitiveTypeName
104: */
105:
106: public String getCorrespondingPrimitiveTypeName() {
107: int formatId = getStoredFormatIdFromTypeId();
108: switch (formatId) {
109: case StoredFormatIds.BLOB_TYPE_ID:
110: return "java.sql.Blob";
111: default:
112: if (SanityManager.DEBUG)
113: SanityManager
114: .THROWASSERT("unexpected formatId in getCorrespondingPrimitiveTypeName() - "
115: + formatId);
116: return null;
117: }
118: }
119:
120: /**
121: * @see TypeCompiler#getCastToCharWidth
122: */
123: public int getCastToCharWidth(DataTypeDescriptor dts) {
124: return dts.getMaximumWidth();
125: }
126:
127: protected String nullMethodName() {
128: int formatId = getStoredFormatIdFromTypeId();
129: switch (formatId) {
130: case StoredFormatIds.BLOB_TYPE_ID:
131: return "getNullBlob";
132: default:
133: if (SanityManager.DEBUG)
134: SanityManager
135: .THROWASSERT("unexpected formatId in nullMethodName() - "
136: + formatId);
137: return null;
138: }
139: }
140:
141: protected String dataValueMethodName() {
142: int formatId = getStoredFormatIdFromTypeId();
143: switch (formatId) {
144: case StoredFormatIds.BLOB_TYPE_ID:
145: return "getBlobDataValue";
146: default:
147: if (SanityManager.DEBUG)
148: SanityManager
149: .THROWASSERT("unexpected formatId in dataValueMethodName() - "
150: + formatId);
151: return null;
152: }
153: }
154: }
|