Source Code Cross Referenced for SQLTypes.java in  » Database-DBMS » db-derby-10.2 » org » apache » derby » impl » drda » 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.drda 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:
003:           Derby - Class org.apache.derby.impl.drda.SQLTypes
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.drda;
023:
024:        import java.sql.Types;
025:        import java.sql.SQLException;
026:        import org.apache.derby.iapi.reference.DRDAConstants;
027:        import org.apache.derby.iapi.reference.JDBC30Translation;
028:
029:        class SQLTypes {
030:
031:            // define final statics for the fdoca type codes here!!!
032:
033:            // hide the default constructor
034:            private SQLTypes() {
035:            }
036:
037:            /**
038:             * Map DB2 SQL Type to JDBC Type
039:             * 
040:             * @param sqlType SQL Type to convert
041:             * @param length storage length of type
042:             * @param ccsid ccsid of type
043:             *
044:             * @return Corresponding JDBC Type 
045:             */
046:
047:            static protected int mapDB2SqlTypeToJdbcType(int sqlType,
048:                    long length, int ccsid) {
049:                switch (getNonNullableSqlType(sqlType)) { // mask the isNullable bit
050:                case DRDAConstants.DB2_SQLTYPE_SMALL:
051:                    return java.sql.Types.SMALLINT;
052:                case DRDAConstants.DB2_SQLTYPE_INTEGER:
053:                    return java.sql.Types.INTEGER;
054:                case DRDAConstants.DB2_SQLTYPE_BIGINT:
055:                    return java.sql.Types.BIGINT;
056:                case DRDAConstants.DB2_SQLTYPE_FLOAT:
057:                    if (length == 16) // can map to either NUMERIC or DECIMAL!!! @sxg
058:                        return java.sql.Types.DECIMAL;
059:                    else if (length == 8) // can map to either DOUBLE or FLOAT!!! @sxg
060:                        return java.sql.Types.DOUBLE;
061:                    else if (length == 4)
062:                        return java.sql.Types.REAL;
063:                    else
064:                        return 0;
065:                    //throw new BugCheckException ("Encountered unexpected float length");
066:                case DRDAConstants.DB2_SQLTYPE_DECIMAL: // can map to either NUMERIC or DECIMAL!!! @sxg
067:                case DRDAConstants.DB2_SQLTYPE_ZONED: // can map to either NUMERIC or DECIMAL!!! @sxg
068:                case DRDAConstants.DB2_SQLTYPE_NUMERIC: // can map to either NUMERIC or DECIMAL!!! @sxg
069:                    return java.sql.Types.DECIMAL;
070:                case DRDAConstants.DB2_SQLTYPE_CHAR: // mixed and single byte
071:                    if (ccsid == 0xffff || ccsid == 0) // we think UW returns 0, and 390 returns 0xffff, doublecheck !!!
072:                        return java.sql.Types.BINARY;
073:                    else
074:                        return java.sql.Types.CHAR;
075:                case DRDAConstants.DB2_SQLTYPE_CSTR: // SBCS null terminated 
076:                case DRDAConstants.DB2_SQLTYPE_GRAPHIC: // fixed character DBCS
077:                    return java.sql.Types.CHAR;
078:                    // use ccsid to distinguish between BINARY and CHAR, VARBINARY and VARCHAR, LONG... !!! -j/p/s
079:                case DRDAConstants.DB2_SQLTYPE_VARGRAPH: // variable character DBCS
080:                case DRDAConstants.DB2_SQLTYPE_VARCHAR: // variable character SBCS/Mixed
081:                    if (ccsid == 0xffff || ccsid == 0) // we think UW returns 0, and 390 returns 0xffff, doublecheck !!!
082:                        return java.sql.Types.VARBINARY;
083:                    else
084:                        return java.sql.Types.VARCHAR;
085:                case DRDAConstants.DB2_SQLTYPE_LSTR: // pascal string SBCS/Mixed
086:                    return java.sql.Types.VARCHAR;
087:                case DRDAConstants.DB2_SQLTYPE_LONGRAPH: // long varchar DBCS
088:                case DRDAConstants.DB2_SQLTYPE_LONG: // long varchar SBCS/Mixed
089:                    if (ccsid == 0xffff || ccsid == 0) // we think UW returns 0, and 390 returns 0xffff, doublecheck !!!
090:                        return java.sql.Types.LONGVARBINARY;
091:                    else
092:                        return java.sql.Types.LONGVARCHAR;
093:                case DRDAConstants.DB2_SQLTYPE_DATE:
094:                    return java.sql.Types.DATE;
095:                case DRDAConstants.DB2_SQLTYPE_TIME:
096:                    return java.sql.Types.TIME;
097:                case DRDAConstants.DB2_SQLTYPE_TIMESTAMP:
098:                    return java.sql.Types.TIMESTAMP;
099:                case DRDAConstants.DB2_SQLTYPE_CLOB: // large object character SBCS/Mixed
100:                case DRDAConstants.DB2_SQLTYPE_DBCLOB: // large object character DBCS
101:                    return java.sql.Types.CLOB;
102:                case DRDAConstants.DB2_SQLTYPE_BLOB: // large object bytes
103:                case DRDAConstants.DB2_SQLTYPE_BLOB_LOCATOR:
104:                case DRDAConstants.DB2_SQLTYPE_CLOB_LOCATOR:
105:                case DRDAConstants.DB2_SQLTYPE_DBCLOB_LOCATOR:
106:                    return java.sql.Types.BLOB;
107:                default:
108:                    //throw new BugCheckException ("Encountered unexpected type code");
109:                    return 0;
110:                }
111:            }
112:
113:            /**
114:             * Map jdbc type to the DB2 DRDA SQL Types expected by jcc.
115:             *@param jdbctype  - jdbc Type to convert
116:             *@param nullable - whether the type is nullable
117:             **/
118:
119:            /**  Map JDBC Type to DB2 SqlType
120:             * @param jdbctype   JDBC Type from java.sql.Types
121:             * @param nullable   true if this is a nullable type
122:             * @param outlen     output parameter with type length
123:             *
124:             * @return Corresponding DB2 SQL Type (See DRDA Manual FD:OCA Meta 
125:             *          Data Summary, page 245)
126:             * 
127:             * @exception SQLException thrown for unrecognized SQLType
128:             */
129:
130:            static protected int mapJdbcTypeToDB2SqlType(int jdbctype,
131:                    boolean nullable, int[] outlen) throws SQLException {
132:                int nullAddVal = 0;
133:
134:                if (nullable)
135:                    nullAddVal = 1;
136:
137:                // Call FdocaConstants just to get the length
138:                FdocaConstants
139:                        .mapJdbcTypeToDrdaType(jdbctype, nullable, outlen);
140:
141:                switch (jdbctype) {
142:                case JDBC30Translation.BOOLEAN:
143:                case java.sql.Types.BIT:
144:                case java.sql.Types.TINYINT:
145:                case java.sql.Types.SMALLINT:
146:                    return DRDAConstants.DB2_SQLTYPE_SMALL + nullAddVal;
147:                case java.sql.Types.INTEGER:
148:                    return DRDAConstants.DB2_SQLTYPE_INTEGER + nullAddVal;
149:                case java.sql.Types.BIGINT:
150:                    return DRDAConstants.DB2_SQLTYPE_BIGINT + nullAddVal;
151:                case java.sql.Types.DOUBLE:
152:                case java.sql.Types.REAL:
153:                    return DRDAConstants.DB2_SQLTYPE_FLOAT + nullAddVal;
154:                case java.sql.Types.DECIMAL:
155:                case java.sql.Types.NUMERIC:
156:                    return DRDAConstants.DB2_SQLTYPE_DECIMAL + nullAddVal;
157:                case java.sql.Types.DATE:
158:                    return DRDAConstants.DB2_SQLTYPE_DATE + nullAddVal;
159:                case java.sql.Types.TIME:
160:                    return DRDAConstants.DB2_SQLTYPE_TIME + nullAddVal;
161:                case java.sql.Types.TIMESTAMP:
162:                    return DRDAConstants.DB2_SQLTYPE_TIMESTAMP + nullAddVal;
163:                case java.sql.Types.CHAR:
164:                    return DRDAConstants.DB2_SQLTYPE_CHAR + nullAddVal; // null terminated SBCS/Mixed
165:                case java.sql.Types.BINARY:
166:                    return DRDAConstants.DB2_SQLTYPE_CHAR + nullAddVal;
167:
168:                case java.sql.Types.VARCHAR:
169:                case java.sql.Types.VARBINARY:
170:                    return DRDAConstants.DB2_SQLTYPE_VARCHAR + nullAddVal;
171:                case java.sql.Types.LONGVARBINARY:
172:                    return DRDAConstants.DB2_SQLTYPE_LONG + nullAddVal;
173:                case java.sql.Types.JAVA_OBJECT:
174:                    return DRDAConstants.DB2_SQLTYPE_LONG + nullAddVal;
175:                case java.sql.Types.BLOB:
176:                    return DRDAConstants.DB2_SQLTYPE_BLOB + nullAddVal;
177:                case java.sql.Types.CLOB:
178:                    return DRDAConstants.DB2_SQLTYPE_CLOB + nullAddVal;
179:                case java.sql.Types.LONGVARCHAR:
180:                    return DRDAConstants.DB2_SQLTYPE_LONG + nullAddVal;
181:                case java.sql.Types.ARRAY:
182:                case java.sql.Types.DISTINCT:
183:                case java.sql.Types.NULL:
184:                case java.sql.Types.OTHER:
185:                case java.sql.Types.REF:
186:                case java.sql.Types.STRUCT:
187:                    throw new SQLException("Jdbc type" + jdbctype
188:                            + "not Supported yet");
189:                default:
190:                    throw new SQLException("unrecognized sql type: " + jdbctype);
191:                    //throw new BugCheckException ("Encountered unexpected type code");
192:
193:                }
194:            }
195:
196:            /**
197:             * Translate DB2 SQL Type to the non-nullable type.
198:             * @param sqlType DB2 SQL Type
199:             *
200:             * @return The Non-Nullable DB2 SQL Type.
201:             */
202:            protected static int getNonNullableSqlType(int sqlType) {
203:                return sqlType & ~1;
204:            }
205:
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.