KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > LOBTypeCompiler


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.LOBTypeCompiler
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.sql.compile;
23
24 import org.apache.derby.iapi.services.loader.ClassFactory;
25
26 import org.apache.derby.iapi.services.sanity.SanityManager;
27
28 import org.apache.derby.iapi.services.io.StoredFormatIds;
29
30 import org.apache.derby.iapi.error.StandardException;
31
32 import org.apache.derby.iapi.types.BitDataValue;
33 import org.apache.derby.iapi.types.DataValueFactory;
34 import org.apache.derby.iapi.types.TypeId;
35
36 import org.apache.derby.iapi.types.DataTypeDescriptor;
37
38 import org.apache.derby.iapi.sql.compile.TypeCompiler;
39
40 import org.apache.derby.iapi.reference.ClassName;
41
42 import java.sql.Types JavaDoc;
43 import org.apache.derby.iapi.reference.JDBC20Translation;
44
45 /**
46  * This class implements TypeCompiler for the SQL LOB types.
47  *
48  * @author Jonas S Karlsson
49  */

50
51 public class LOBTypeCompiler extends BaseTypeCompiler
52 {
53        /**
54          * Tell whether this type (BLOB) can be compared to the given type. //
55          * BLOBS are not comparable.
56          *
57          * @param otherType The TypeId of the other type.
58          */

59
60         public boolean comparable(TypeId otherType,
61                                   boolean forEquals,
62                                   ClassFactory cf)
63         {
64             return false;
65         }
66
67
68
69         /**
70          * Tell whether this type (LOB) can be converted to the given type.
71          *
72          * @see TypeCompiler#convertible
73          */

74         public boolean convertible(TypeId otherType,
75                                    boolean forDataTypeFunction)
76         {
77
78             return (otherType.isBlobTypeId());
79         }
80
81         /**
82          * Tell whether this type (LOB) is compatible with the given type.
83          *
84          * @param otherType The TypeId of the other type.
85          */

86         public boolean compatible(TypeId otherType)
87         {
88                 return convertible(otherType,false);
89         }
90
91         /**
92          * Tell whether this type (LOB) can be stored into from the given type.
93          *
94          * @param otherType The TypeId of the other type.
95          * @param cf A ClassFactory
96          */

97
98         public boolean storable(TypeId otherType, ClassFactory cf)
99         {
100             // no automatic conversions at store time
101

102             return (otherType.isBlobTypeId());
103         }
104
105         /** @see TypeCompiler#interfaceName */
106         public String JavaDoc interfaceName()
107         {
108             return ClassName.BitDataValue;
109         }
110
111         /**
112          * @see TypeCompiler#getCorrespondingPrimitiveTypeName
113          */

114
115         public String JavaDoc getCorrespondingPrimitiveTypeName() {
116             int formatId = getStoredFormatIdFromTypeId();
117             switch (formatId) {
118                 case StoredFormatIds.BLOB_TYPE_ID: return "java.sql.Blob";
119                 default:
120                     if (SanityManager.DEBUG)
121                         SanityManager.THROWASSERT("unexpected formatId in getCorrespondingPrimitiveTypeName() - " + formatId);
122                     return null;
123             }
124         }
125
126         /**
127          * @see TypeCompiler#getCastToCharWidth
128          */

129         public int getCastToCharWidth(DataTypeDescriptor dts)
130         {
131                 return dts.getMaximumWidth();
132         }
133
134         protected String JavaDoc nullMethodName() {
135             int formatId = getStoredFormatIdFromTypeId();
136             switch (formatId) {
137                 case StoredFormatIds.BLOB_TYPE_ID: return "getNullBlob";
138                 default:
139                     if (SanityManager.DEBUG)
140                         SanityManager.THROWASSERT("unexpected formatId in nullMethodName() - " + formatId);
141                     return null;
142             }
143         }
144
145         protected String JavaDoc dataValueMethodName()
146         {
147             int formatId = getStoredFormatIdFromTypeId();
148             switch (formatId) {
149                 case StoredFormatIds.BLOB_TYPE_ID: return "getBlobDataValue";
150                 default:
151                     if (SanityManager.DEBUG)
152                         SanityManager.THROWASSERT("unexpected formatId in dataValueMethodName() - " + formatId);
153                     return null;
154                 }
155         }
156 }
157
Popular Tags