KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

60
61         public boolean comparable(TypeId otherType,
62                                   boolean forEquals,
63                                   ClassFactory cf)
64         {
65             return false;
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             // allow casting to any string
78
return (otherType.isStringTypeId()) ;
79
80         }
81
82         /**
83          * Tell whether this type (CLOB) is compatible with the given type.
84          *
85          * @param otherType The TypeId of the other type.
86          */

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

98
99         public boolean storable(TypeId otherType, ClassFactory cf)
100         {
101             // no automatic conversions at store time--but string
102
// literals (or values of type CHAR/VARCHAR) are STORABLE
103
// as clobs, even if the two types can't be COMPARED.
104
return (otherType.isStringTypeId()) ;
105         }
106
107         /** @see TypeCompiler#interfaceName */
108         public String JavaDoc interfaceName()
109         {
110             return ClassName.StringDataValue;
111         }
112
113         /**
114          * @see TypeCompiler#getCorrespondingPrimitiveTypeName
115          */

116
117         public String JavaDoc getCorrespondingPrimitiveTypeName() {
118             int formatId = getStoredFormatIdFromTypeId();
119             switch (formatId) {
120                 case StoredFormatIds.CLOB_TYPE_ID: return "java.sql.Clob";
121                 case StoredFormatIds.NCLOB_TYPE_ID: return "java.sql.Clob";
122                 default:
123                     if (SanityManager.DEBUG)
124                         SanityManager.THROWASSERT("unexpected formatId in getCorrespondingPrimitiveTypeName() - " + formatId);
125                     return null;
126             }
127         }
128
129         public String JavaDoc getMatchingNationalCharTypeName()
130         {
131             return TypeId.NCLOB_NAME;
132         }
133
134         /**
135          * @see TypeCompiler#getCastToCharWidth
136          */

137         public int getCastToCharWidth(DataTypeDescriptor dts)
138         {
139                 return dts.getMaximumWidth();
140         }
141
142         protected String JavaDoc nullMethodName() {
143             int formatId = getStoredFormatIdFromTypeId();
144             switch (formatId) {
145                 case StoredFormatIds.CLOB_TYPE_ID: return "getNullClob";
146                 case StoredFormatIds.NCLOB_TYPE_ID: return "getNullNClob";
147                 default:
148                     if (SanityManager.DEBUG)
149                         SanityManager.THROWASSERT("unexpected formatId in nullMethodName() - " + formatId);
150                     return null;
151             }
152         }
153
154         protected String JavaDoc dataValueMethodName()
155         {
156             int formatId = getStoredFormatIdFromTypeId();
157             switch (formatId) {
158                 case StoredFormatIds.CLOB_TYPE_ID: return "getClobDataValue";
159                 case StoredFormatIds.NCLOB_TYPE_ID: return "getNClobDataValue";
160                 default:
161                     if (SanityManager.DEBUG)
162                         SanityManager.THROWASSERT("unexpected formatId in dataValueMethodName() - " + formatId);
163                     return null;
164                 }
165         }
166 }
167
Popular Tags