Source Code Cross Referenced for CharTypeCompiler.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » sql » compile » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database DBMS » db derby 10.2 » org.apache.derby.impl.sql.compile 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.sql.compile.CharTypeCompiler
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.StringDataValue;
033:        import org.apache.derby.iapi.types.DataValueDescriptor;
034:        import org.apache.derby.iapi.types.TypeId;
035:        import org.apache.derby.iapi.types.DataTypeDescriptor;
036:
037:        import org.apache.derby.iapi.sql.compile.TypeCompiler;
038:
039:        import org.apache.derby.iapi.reference.ClassName;
040:        import org.apache.derby.iapi.reference.SQLState;
041:
042:        import org.apache.derby.iapi.util.StringUtil;
043:
044:        import java.sql.Types;
045:        import org.apache.derby.iapi.reference.JDBC20Translation;
046:
047:        /**
048:         * This class implements TypeCompiler for the SQL char datatypes.
049:         *
050:         * @author Jeff Lichtman
051:         */
052:
053:        public final class CharTypeCompiler extends BaseTypeCompiler {
054:            /**
055:             * Tell whether this type (char) can be compared to the given type.
056:             * Long types can not be compared.
057:             * VARCHAR AND CHAR can be compared to CHAR/VARCHAR/DATE/TIME/TIMESTAMP
058:             *
059:             *
060:             * @param otherType     The TypeId of the other type.
061:             */
062:
063:            public boolean comparable(TypeId otherType, boolean forEquals,
064:                    ClassFactory cf) {
065:
066:                // Long Types cannot be compared
067:                if (getTypeId().isLongConcatableTypeId()
068:                        || otherType.isLongConcatableTypeId())
069:                    return false;
070:
071:                // CHAR and VARCHAR can compare to Strings or DATE/TIME/TIMESTAMP
072:                if ((otherType.isStringTypeId()
073:                        || otherType.isDateTimeTimeStampTypeID() || otherType
074:                        .isBooleanTypeId()))
075:                    return true;
076:
077:                TypeCompiler otherTC = getTypeCompiler(otherType);
078:                return (otherType.userType() && otherTC.comparable(getTypeId(),
079:                        forEquals, cf));
080:            }
081:
082:            /**
083:             * Tell whether this type (char) can be converted to the given type.
084:             *
085:             * @see TypeCompiler#convertible
086:             */
087:            public boolean convertible(TypeId otherType,
088:                    boolean forDataTypeFunction) {
089:                // LONGVARCHAR can only be converted from  character types
090:                // or CLOB.
091:                if (getTypeId().isLongVarcharTypeId()) {
092:                    return (otherType.isStringTypeId());
093:                }
094:
095:                // The double function can convert CHAR and VARCHAR
096:                if (forDataTypeFunction && otherType.isDoubleTypeId())
097:                    return (getTypeId().isStringTypeId());
098:
099:                // can't CAST to CHAR and VARCHAR from REAL or DOUBLE
100:                // or binary types or XML
101:                // all other types are ok.
102:                if (otherType.isFloatingPointTypeId()
103:                        || otherType.isBitTypeId() || otherType.isBlobTypeId()
104:                        || otherType.isXMLTypeId())
105:                    return false;
106:
107:                return true;
108:            }
109:
110:            /**
111:             * Tell whether this type (char) is compatible with the given type.
112:             *
113:             * @param otherType     The TypeId of the other type.
114:             */
115:            public boolean compatible(TypeId otherType) {
116:                return (otherType.isStringTypeId() || (otherType
117:                        .isDateTimeTimeStampTypeId() && !getTypeId()
118:                        .isLongVarcharTypeId()));
119:
120:            }
121:
122:            /**
123:             * Tell whether this type (char) can be stored into from the given type.
124:             *
125:             * @param otherType     The TypeId of the other type.
126:             * @param cf            A ClassFactory
127:             */
128:
129:            public boolean storable(TypeId otherType, ClassFactory cf) {
130:                // Same rules as cast except we can't assign from numbers
131:                if (convertible(otherType, false) && !otherType.isBlobTypeId()
132:                        && !otherType.isNumericTypeId())
133:                    return true;
134:
135:                /*
136:                 ** If the other type is user-defined, use the java types to determine
137:                 ** assignability.
138:                 */
139:                return userTypeStorable(getTypeId(), otherType, cf);
140:            }
141:
142:            /** @see TypeCompiler#interfaceName */
143:            public String interfaceName() {
144:                return ClassName.StringDataValue;
145:            }
146:
147:            /**
148:             * @see TypeCompiler#getCorrespondingPrimitiveTypeName
149:             */
150:
151:            public String getCorrespondingPrimitiveTypeName() {
152:                /* Only numerics and booleans get mapped to Java primitives */
153:                return "java.lang.String";
154:            }
155:
156:            /**
157:             * @see TypeCompiler#getCastToCharWidth
158:             */
159:            public int getCastToCharWidth(DataTypeDescriptor dts) {
160:                return dts.getMaximumWidth();
161:            }
162:
163:            /** @see TypeCompiler#getMatchingNationalCharTypeName */
164:            public String getMatchingNationalCharTypeName() {
165:                int formatId = getStoredFormatIdFromTypeId();
166:                switch (formatId) {
167:                case StoredFormatIds.CHAR_TYPE_ID:
168:                case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:
169:                    return TypeId.NATIONAL_CHAR_NAME;
170:
171:                case StoredFormatIds.LONGVARCHAR_TYPE_ID:
172:                case StoredFormatIds.NATIONAL_LONGVARCHAR_TYPE_ID:
173:                    return TypeId.NATIONAL_LONGVARCHAR_NAME;
174:
175:                case StoredFormatIds.VARCHAR_TYPE_ID:
176:                case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
177:                    return TypeId.NATIONAL_VARCHAR_NAME;
178:
179:                default:
180:                    if (SanityManager.DEBUG) {
181:                        SanityManager
182:                                .THROWASSERT("unexpected formatId in getMatchingNationalCharTypeName() - "
183:                                        + formatId);
184:                    }
185:                    return null;
186:                }
187:            }
188:
189:            protected String nullMethodName() {
190:                int formatId = getStoredFormatIdFromTypeId();
191:                switch (formatId) {
192:                case StoredFormatIds.CHAR_TYPE_ID:
193:                    return "getNullChar";
194:
195:                case StoredFormatIds.LONGVARCHAR_TYPE_ID:
196:                    return "getNullLongvarchar";
197:
198:                case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:
199:                    return "getNullNationalChar";
200:
201:                case StoredFormatIds.NATIONAL_LONGVARCHAR_TYPE_ID:
202:                    return "getNullNationalLongvarchar";
203:
204:                case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
205:                    return "getNullNationalVarchar";
206:
207:                case StoredFormatIds.VARCHAR_TYPE_ID:
208:                    return "getNullVarchar";
209:
210:                default:
211:                    if (SanityManager.DEBUG) {
212:                        SanityManager
213:                                .THROWASSERT("unexpected formatId in nullMethodName() - "
214:                                        + formatId);
215:                    }
216:                    return null;
217:                }
218:            }
219:
220:            protected String dataValueMethodName() {
221:                int formatId = getStoredFormatIdFromTypeId();
222:                switch (formatId) {
223:                case StoredFormatIds.CHAR_TYPE_ID:
224:                    return "getCharDataValue";
225:
226:                case StoredFormatIds.LONGVARCHAR_TYPE_ID:
227:                    return "getLongvarcharDataValue";
228:
229:                case StoredFormatIds.NATIONAL_CHAR_TYPE_ID:
230:                    return "getNationalCharDataValue";
231:
232:                case StoredFormatIds.NATIONAL_LONGVARCHAR_TYPE_ID:
233:                    return "getNationalLongvarcharDataValue";
234:
235:                case StoredFormatIds.NATIONAL_VARCHAR_TYPE_ID:
236:                    return "getNationalVarcharDataValue";
237:
238:                case StoredFormatIds.VARCHAR_TYPE_ID:
239:                    return "getVarcharDataValue";
240:
241:                default:
242:                    if (SanityManager.DEBUG) {
243:                        SanityManager
244:                                .THROWASSERT("unexpected formatId in dataValueMethodName() - "
245:                                        + formatId);
246:                    }
247:                    return null;
248:                }
249:            }
250:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.