Source Code Cross Referenced for MysqlDefs.java in  » Database-JDBC-Connection-Pool » mysql-connector-java-5.1.3 » com » mysql » jdbc » 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 JDBC Connection Pool » mysql connector java 5.1.3 » com.mysql.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         Copyright (C) 2002-2007 MySQL AB
003:
004:         This program is free software; you can redistribute it and/or modify
005:         it under the terms of version 2 of the GNU General Public License as 
006:         published by the Free Software Foundation.
007:
008:         There are special exceptions to the terms and conditions of the GPL 
009:         as it is applied to this software. View the full text of the 
010:         exception in file EXCEPTIONS-CONNECTOR-J in the directory of this 
011:         software distribution.
012:
013:         This program is distributed in the hope that it will be useful,
014:         but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         GNU General Public License for more details.
017:
018:         You should have received a copy of the GNU General Public License
019:         along with this program; if not, write to the Free Software
020:         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
021:
022:
023:
024:         */
025:        package com.mysql.jdbc;
026:
027:        import java.sql.Types;
028:        import java.util.HashMap;
029:        import java.util.Iterator;
030:        import java.util.Map;
031:
032:        /**
033:         * MysqlDefs contains many values that are needed for communication with the
034:         * MySQL server.
035:         * 
036:         * @author Mark Matthews
037:         * @version $Id: MysqlDefs.java 6376 2007-04-05 21:56:05Z mmatthews $
038:         */
039:        public final class MysqlDefs {
040:            // ~ Static fields/initializers
041:            // ---------------------------------------------
042:
043:            static final int COM_BINLOG_DUMP = 18;
044:
045:            static final int COM_CHANGE_USER = 17;
046:
047:            static final int COM_CLOSE_STATEMENT = 25;
048:
049:            static final int COM_CONNECT_OUT = 20;
050:
051:            static final int COM_END = 29;
052:
053:            static final int COM_EXECUTE = 23;
054:
055:            static final int COM_FETCH = 28;
056:
057:            static final int COM_LONG_DATA = 24;
058:
059:            static final int COM_PREPARE = 22;
060:
061:            static final int COM_REGISTER_SLAVE = 21;
062:
063:            static final int COM_RESET_STMT = 26;
064:
065:            static final int COM_SET_OPTION = 27;
066:
067:            static final int COM_TABLE_DUMP = 19;
068:
069:            static final int CONNECT = 11;
070:
071:            static final int CREATE_DB = 5;
072:
073:            static final int DEBUG = 13;
074:
075:            static final int DELAYED_INSERT = 16;
076:
077:            static final int DROP_DB = 6;
078:
079:            static final int FIELD_LIST = 4;
080:
081:            static final int FIELD_TYPE_BIT = 16;
082:
083:            public static final int FIELD_TYPE_BLOB = 252;
084:
085:            static final int FIELD_TYPE_DATE = 10;
086:
087:            static final int FIELD_TYPE_DATETIME = 12;
088:
089:            // Data Types
090:            static final int FIELD_TYPE_DECIMAL = 0;
091:
092:            static final int FIELD_TYPE_DOUBLE = 5;
093:
094:            static final int FIELD_TYPE_ENUM = 247;
095:
096:            static final int FIELD_TYPE_FLOAT = 4;
097:
098:            static final int FIELD_TYPE_GEOMETRY = 255;
099:
100:            static final int FIELD_TYPE_INT24 = 9;
101:
102:            static final int FIELD_TYPE_LONG = 3;
103:
104:            static final int FIELD_TYPE_LONG_BLOB = 251;
105:
106:            static final int FIELD_TYPE_LONGLONG = 8;
107:
108:            static final int FIELD_TYPE_MEDIUM_BLOB = 250;
109:
110:            static final int FIELD_TYPE_NEW_DECIMAL = 246;
111:
112:            static final int FIELD_TYPE_NEWDATE = 14;
113:
114:            static final int FIELD_TYPE_NULL = 6;
115:
116:            static final int FIELD_TYPE_SET = 248;
117:
118:            static final int FIELD_TYPE_SHORT = 2;
119:
120:            static final int FIELD_TYPE_STRING = 254;
121:
122:            static final int FIELD_TYPE_TIME = 11;
123:
124:            static final int FIELD_TYPE_TIMESTAMP = 7;
125:
126:            static final int FIELD_TYPE_TINY = 1;
127:
128:            // Older data types
129:            static final int FIELD_TYPE_TINY_BLOB = 249;
130:
131:            static final int FIELD_TYPE_VAR_STRING = 253;
132:
133:            static final int FIELD_TYPE_VARCHAR = 15;
134:
135:            // Newer data types
136:            static final int FIELD_TYPE_YEAR = 13;
137:
138:            static final int INIT_DB = 2;
139:
140:            static final long LENGTH_BLOB = 65535;
141:
142:            static final long LENGTH_LONGBLOB = 4294967295L;
143:
144:            static final long LENGTH_MEDIUMBLOB = 16777215;
145:
146:            static final long LENGTH_TINYBLOB = 255;
147:
148:            // Limitations
149:            static final int MAX_ROWS = 50000000; // From the MySQL FAQ
150:
151:            /**
152:             * Used to indicate that the server sent no field-level character set
153:             * information, so the driver should use the connection-level character
154:             * encoding instead.
155:             */
156:            public static final int NO_CHARSET_INFO = -1;
157:
158:            static final byte OPEN_CURSOR_FLAG = 1;
159:
160:            static final int PING = 14;
161:
162:            static final int PROCESS_INFO = 10;
163:
164:            static final int PROCESS_KILL = 12;
165:
166:            static final int QUERY = 3;
167:
168:            static final int QUIT = 1;
169:
170:            // ~ Methods
171:            // ----------------------------------------------------------------
172:
173:            static final int RELOAD = 7;
174:
175:            static final int SHUTDOWN = 8;
176:
177:            //
178:            // Constants defined from mysql
179:            //
180:            // DB Operations
181:            static final int SLEEP = 0;
182:
183:            static final int STATISTICS = 9;
184:
185:            static final int TIME = 15;
186:
187:            /**
188:             * Maps the given MySQL type to the correct JDBC type.
189:             */
190:            static int mysqlToJavaType(int mysqlType) {
191:                int jdbcType;
192:
193:                switch (mysqlType) {
194:                case MysqlDefs.FIELD_TYPE_NEW_DECIMAL:
195:                case MysqlDefs.FIELD_TYPE_DECIMAL:
196:                    jdbcType = Types.DECIMAL;
197:
198:                    break;
199:
200:                case MysqlDefs.FIELD_TYPE_TINY:
201:                    jdbcType = Types.TINYINT;
202:
203:                    break;
204:
205:                case MysqlDefs.FIELD_TYPE_SHORT:
206:                    jdbcType = Types.SMALLINT;
207:
208:                    break;
209:
210:                case MysqlDefs.FIELD_TYPE_LONG:
211:                    jdbcType = Types.INTEGER;
212:
213:                    break;
214:
215:                case MysqlDefs.FIELD_TYPE_FLOAT:
216:                    jdbcType = Types.REAL;
217:
218:                    break;
219:
220:                case MysqlDefs.FIELD_TYPE_DOUBLE:
221:                    jdbcType = Types.DOUBLE;
222:
223:                    break;
224:
225:                case MysqlDefs.FIELD_TYPE_NULL:
226:                    jdbcType = Types.NULL;
227:
228:                    break;
229:
230:                case MysqlDefs.FIELD_TYPE_TIMESTAMP:
231:                    jdbcType = Types.TIMESTAMP;
232:
233:                    break;
234:
235:                case MysqlDefs.FIELD_TYPE_LONGLONG:
236:                    jdbcType = Types.BIGINT;
237:
238:                    break;
239:
240:                case MysqlDefs.FIELD_TYPE_INT24:
241:                    jdbcType = Types.INTEGER;
242:
243:                    break;
244:
245:                case MysqlDefs.FIELD_TYPE_DATE:
246:                    jdbcType = Types.DATE;
247:
248:                    break;
249:
250:                case MysqlDefs.FIELD_TYPE_TIME:
251:                    jdbcType = Types.TIME;
252:
253:                    break;
254:
255:                case MysqlDefs.FIELD_TYPE_DATETIME:
256:                    jdbcType = Types.TIMESTAMP;
257:
258:                    break;
259:
260:                case MysqlDefs.FIELD_TYPE_YEAR:
261:                    jdbcType = Types.DATE;
262:
263:                    break;
264:
265:                case MysqlDefs.FIELD_TYPE_NEWDATE:
266:                    jdbcType = Types.DATE;
267:
268:                    break;
269:
270:                case MysqlDefs.FIELD_TYPE_ENUM:
271:                    jdbcType = Types.CHAR;
272:
273:                    break;
274:
275:                case MysqlDefs.FIELD_TYPE_SET:
276:                    jdbcType = Types.CHAR;
277:
278:                    break;
279:
280:                case MysqlDefs.FIELD_TYPE_TINY_BLOB:
281:                    jdbcType = Types.VARBINARY;
282:
283:                    break;
284:
285:                case MysqlDefs.FIELD_TYPE_MEDIUM_BLOB:
286:                    jdbcType = Types.LONGVARBINARY;
287:
288:                    break;
289:
290:                case MysqlDefs.FIELD_TYPE_LONG_BLOB:
291:                    jdbcType = Types.LONGVARBINARY;
292:
293:                    break;
294:
295:                case MysqlDefs.FIELD_TYPE_BLOB:
296:                    jdbcType = Types.LONGVARBINARY;
297:
298:                    break;
299:
300:                case MysqlDefs.FIELD_TYPE_VAR_STRING:
301:                case MysqlDefs.FIELD_TYPE_VARCHAR:
302:                    jdbcType = Types.VARCHAR;
303:
304:                    break;
305:
306:                case MysqlDefs.FIELD_TYPE_STRING:
307:                    jdbcType = Types.CHAR;
308:
309:                    break;
310:                case MysqlDefs.FIELD_TYPE_GEOMETRY:
311:                    jdbcType = Types.BINARY;
312:
313:                    break;
314:                case MysqlDefs.FIELD_TYPE_BIT:
315:                    jdbcType = Types.BIT;
316:
317:                    break;
318:                default:
319:                    jdbcType = Types.VARCHAR;
320:                }
321:
322:                return jdbcType;
323:            }
324:
325:            /**
326:             * Maps the given MySQL type to the correct JDBC type.
327:             */
328:            static int mysqlToJavaType(String mysqlType) {
329:                if (mysqlType.equalsIgnoreCase("BIT")) {
330:                    return mysqlToJavaType(FIELD_TYPE_BIT);
331:                } else if (mysqlType.equalsIgnoreCase("TINYINT")) { //$NON-NLS-1$
332:                    return mysqlToJavaType(FIELD_TYPE_TINY);
333:                } else if (mysqlType.equalsIgnoreCase("SMALLINT")) { //$NON-NLS-1$
334:                    return mysqlToJavaType(FIELD_TYPE_SHORT);
335:                } else if (mysqlType.equalsIgnoreCase("MEDIUMINT")) { //$NON-NLS-1$
336:                    return mysqlToJavaType(FIELD_TYPE_INT24);
337:                } else if (mysqlType.equalsIgnoreCase("INT") || mysqlType.equalsIgnoreCase("INTEGER")) { //$NON-NLS-1$ //$NON-NLS-2$
338:                    return mysqlToJavaType(FIELD_TYPE_LONG);
339:                } else if (mysqlType.equalsIgnoreCase("BIGINT")) { //$NON-NLS-1$
340:                    return mysqlToJavaType(FIELD_TYPE_LONGLONG);
341:                } else if (mysqlType.equalsIgnoreCase("INT24")) { //$NON-NLS-1$
342:                    return mysqlToJavaType(FIELD_TYPE_INT24);
343:                } else if (mysqlType.equalsIgnoreCase("REAL")) { //$NON-NLS-1$
344:                    return mysqlToJavaType(FIELD_TYPE_DOUBLE);
345:                } else if (mysqlType.equalsIgnoreCase("FLOAT")) { //$NON-NLS-1$
346:                    return mysqlToJavaType(FIELD_TYPE_FLOAT);
347:                } else if (mysqlType.equalsIgnoreCase("DECIMAL")) { //$NON-NLS-1$
348:                    return mysqlToJavaType(FIELD_TYPE_DECIMAL);
349:                } else if (mysqlType.equalsIgnoreCase("NUMERIC")) { //$NON-NLS-1$
350:                    return mysqlToJavaType(FIELD_TYPE_DECIMAL);
351:                } else if (mysqlType.equalsIgnoreCase("DOUBLE")) { //$NON-NLS-1$
352:                    return mysqlToJavaType(FIELD_TYPE_DOUBLE);
353:                } else if (mysqlType.equalsIgnoreCase("CHAR")) { //$NON-NLS-1$
354:                    return mysqlToJavaType(FIELD_TYPE_STRING);
355:                } else if (mysqlType.equalsIgnoreCase("VARCHAR")) { //$NON-NLS-1$
356:                    return mysqlToJavaType(FIELD_TYPE_VAR_STRING);
357:                } else if (mysqlType.equalsIgnoreCase("DATE")) { //$NON-NLS-1$
358:                    return mysqlToJavaType(FIELD_TYPE_DATE);
359:                } else if (mysqlType.equalsIgnoreCase("TIME")) { //$NON-NLS-1$
360:                    return mysqlToJavaType(FIELD_TYPE_TIME);
361:                } else if (mysqlType.equalsIgnoreCase("YEAR")) { //$NON-NLS-1$
362:                    return mysqlToJavaType(FIELD_TYPE_YEAR);
363:                } else if (mysqlType.equalsIgnoreCase("TIMESTAMP")) { //$NON-NLS-1$
364:                    return mysqlToJavaType(FIELD_TYPE_TIMESTAMP);
365:                } else if (mysqlType.equalsIgnoreCase("DATETIME")) { //$NON-NLS-1$
366:                    return mysqlToJavaType(FIELD_TYPE_DATETIME);
367:                } else if (mysqlType.equalsIgnoreCase("TINYBLOB")) { //$NON-NLS-1$
368:                    return java.sql.Types.BINARY;
369:                } else if (mysqlType.equalsIgnoreCase("BLOB")) { //$NON-NLS-1$
370:                    return java.sql.Types.LONGVARBINARY;
371:                } else if (mysqlType.equalsIgnoreCase("MEDIUMBLOB")) { //$NON-NLS-1$
372:                    return java.sql.Types.LONGVARBINARY;
373:                } else if (mysqlType.equalsIgnoreCase("LONGBLOB")) { //$NON-NLS-1$
374:                    return java.sql.Types.LONGVARBINARY;
375:                } else if (mysqlType.equalsIgnoreCase("TINYTEXT")) { //$NON-NLS-1$
376:                    return java.sql.Types.VARCHAR;
377:                } else if (mysqlType.equalsIgnoreCase("TEXT")) { //$NON-NLS-1$
378:                    return java.sql.Types.LONGVARCHAR;
379:                } else if (mysqlType.equalsIgnoreCase("MEDIUMTEXT")) { //$NON-NLS-1$
380:                    return java.sql.Types.LONGVARCHAR;
381:                } else if (mysqlType.equalsIgnoreCase("LONGTEXT")) { //$NON-NLS-1$
382:                    return java.sql.Types.LONGVARCHAR;
383:                } else if (mysqlType.equalsIgnoreCase("ENUM")) { //$NON-NLS-1$
384:                    return mysqlToJavaType(FIELD_TYPE_ENUM);
385:                } else if (mysqlType.equalsIgnoreCase("SET")) { //$NON-NLS-1$
386:                    return mysqlToJavaType(FIELD_TYPE_SET);
387:                } else if (mysqlType.equalsIgnoreCase("GEOMETRY")) {
388:                    return mysqlToJavaType(FIELD_TYPE_GEOMETRY);
389:                } else if (mysqlType.equalsIgnoreCase("BINARY")) {
390:                    return Types.BINARY; // no concrete type on the wire
391:                } else if (mysqlType.equalsIgnoreCase("VARBINARY")) {
392:                    return Types.VARBINARY; // no concrete type on the wire
393:                } else if (mysqlType.equalsIgnoreCase("BIT")) {
394:                    return mysqlToJavaType(FIELD_TYPE_BIT);
395:                }
396:
397:                // Punt
398:                return java.sql.Types.OTHER;
399:            }
400:
401:            /**
402:             * @param mysqlType
403:             * @return
404:             */
405:            public static String typeToName(int mysqlType) {
406:                switch (mysqlType) {
407:                case MysqlDefs.FIELD_TYPE_DECIMAL:
408:                    return "FIELD_TYPE_DECIMAL";
409:
410:                case MysqlDefs.FIELD_TYPE_TINY:
411:                    return "FIELD_TYPE_TINY";
412:
413:                case MysqlDefs.FIELD_TYPE_SHORT:
414:                    return "FIELD_TYPE_SHORT";
415:
416:                case MysqlDefs.FIELD_TYPE_LONG:
417:                    return "FIELD_TYPE_LONG";
418:
419:                case MysqlDefs.FIELD_TYPE_FLOAT:
420:                    return "FIELD_TYPE_FLOAT";
421:
422:                case MysqlDefs.FIELD_TYPE_DOUBLE:
423:                    return "FIELD_TYPE_DOUBLE";
424:
425:                case MysqlDefs.FIELD_TYPE_NULL:
426:                    return "FIELD_TYPE_NULL";
427:
428:                case MysqlDefs.FIELD_TYPE_TIMESTAMP:
429:                    return "FIELD_TYPE_TIMESTAMP";
430:
431:                case MysqlDefs.FIELD_TYPE_LONGLONG:
432:                    return "FIELD_TYPE_LONGLONG";
433:
434:                case MysqlDefs.FIELD_TYPE_INT24:
435:                    return "FIELD_TYPE_INT24";
436:
437:                case MysqlDefs.FIELD_TYPE_DATE:
438:                    return "FIELD_TYPE_DATE";
439:
440:                case MysqlDefs.FIELD_TYPE_TIME:
441:                    return "FIELD_TYPE_TIME";
442:
443:                case MysqlDefs.FIELD_TYPE_DATETIME:
444:                    return "FIELD_TYPE_DATETIME";
445:
446:                case MysqlDefs.FIELD_TYPE_YEAR:
447:                    return "FIELD_TYPE_YEAR";
448:
449:                case MysqlDefs.FIELD_TYPE_NEWDATE:
450:                    return "FIELD_TYPE_NEWDATE";
451:
452:                case MysqlDefs.FIELD_TYPE_ENUM:
453:                    return "FIELD_TYPE_ENUM";
454:
455:                case MysqlDefs.FIELD_TYPE_SET:
456:                    return "FIELD_TYPE_SET";
457:
458:                case MysqlDefs.FIELD_TYPE_TINY_BLOB:
459:                    return "FIELD_TYPE_TINY_BLOB";
460:
461:                case MysqlDefs.FIELD_TYPE_MEDIUM_BLOB:
462:                    return "FIELD_TYPE_MEDIUM_BLOB";
463:
464:                case MysqlDefs.FIELD_TYPE_LONG_BLOB:
465:                    return "FIELD_TYPE_LONG_BLOB";
466:
467:                case MysqlDefs.FIELD_TYPE_BLOB:
468:                    return "FIELD_TYPE_BLOB";
469:
470:                case MysqlDefs.FIELD_TYPE_VAR_STRING:
471:                    return "FIELD_TYPE_VAR_STRING";
472:
473:                case MysqlDefs.FIELD_TYPE_STRING:
474:                    return "FIELD_TYPE_STRING";
475:
476:                case MysqlDefs.FIELD_TYPE_VARCHAR:
477:                    return "FIELD_TYPE_VARCHAR";
478:
479:                case MysqlDefs.FIELD_TYPE_GEOMETRY:
480:                    return "FIELD_TYPE_GEOMETRY";
481:
482:                default:
483:                    return " Unknown MySQL Type # " + mysqlType;
484:                }
485:            }
486:
487:            private static Map mysqlToJdbcTypesMap = new HashMap();
488:
489:            static {
490:                mysqlToJdbcTypesMap.put("BIT", Constants
491:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_BIT)));
492:
493:                mysqlToJdbcTypesMap.put("TINYINT", Constants
494:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_TINY)));
495:                mysqlToJdbcTypesMap.put("SMALLINT", Constants
496:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_SHORT)));
497:                mysqlToJdbcTypesMap.put("MEDIUMINT", Constants
498:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_INT24)));
499:                mysqlToJdbcTypesMap.put("INT", Constants
500:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_LONG)));
501:                mysqlToJdbcTypesMap.put("INTEGER", Constants
502:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_LONG)));
503:                mysqlToJdbcTypesMap.put("BIGINT", Constants
504:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_LONGLONG)));
505:                mysqlToJdbcTypesMap.put("INT24", Constants
506:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_INT24)));
507:                mysqlToJdbcTypesMap.put("REAL", Constants
508:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_DOUBLE)));
509:                mysqlToJdbcTypesMap.put("FLOAT", Constants
510:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_FLOAT)));
511:                mysqlToJdbcTypesMap.put("DECIMAL", Constants
512:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_DECIMAL)));
513:                mysqlToJdbcTypesMap.put("NUMERIC", Constants
514:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_DECIMAL)));
515:                mysqlToJdbcTypesMap.put("DOUBLE", Constants
516:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_DOUBLE)));
517:                mysqlToJdbcTypesMap.put("CHAR", Constants
518:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_STRING)));
519:                mysqlToJdbcTypesMap
520:                        .put(
521:                                "VARCHAR",
522:                                Constants
523:                                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_VAR_STRING)));
524:                mysqlToJdbcTypesMap.put("DATE", Constants
525:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_DATE)));
526:                mysqlToJdbcTypesMap.put("TIME", Constants
527:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_TIME)));
528:                mysqlToJdbcTypesMap.put("YEAR", Constants
529:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_YEAR)));
530:                mysqlToJdbcTypesMap.put("TIMESTAMP", Constants
531:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_TIMESTAMP)));
532:                mysqlToJdbcTypesMap.put("DATETIME", Constants
533:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_DATETIME)));
534:                mysqlToJdbcTypesMap.put("TINYBLOB", Constants
535:                        .integerValueOf(java.sql.Types.BINARY));
536:                mysqlToJdbcTypesMap.put("BLOB", Constants
537:                        .integerValueOf(java.sql.Types.LONGVARBINARY));
538:                mysqlToJdbcTypesMap.put("MEDIUMBLOB", Constants
539:                        .integerValueOf(java.sql.Types.LONGVARBINARY));
540:                mysqlToJdbcTypesMap.put("LONGBLOB", Constants
541:                        .integerValueOf(java.sql.Types.LONGVARBINARY));
542:                mysqlToJdbcTypesMap.put("TINYTEXT", Constants
543:                        .integerValueOf(java.sql.Types.VARCHAR));
544:                mysqlToJdbcTypesMap.put("TEXT", Constants
545:                        .integerValueOf(java.sql.Types.LONGVARCHAR));
546:                mysqlToJdbcTypesMap.put("MEDIUMTEXT", Constants
547:                        .integerValueOf(java.sql.Types.LONGVARCHAR));
548:                mysqlToJdbcTypesMap.put("LONGTEXT", Constants
549:                        .integerValueOf(java.sql.Types.LONGVARCHAR));
550:                mysqlToJdbcTypesMap.put("ENUM", Constants
551:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_ENUM)));
552:                mysqlToJdbcTypesMap.put("SET", Constants
553:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_SET)));
554:                mysqlToJdbcTypesMap.put("GEOMETRY", Constants
555:                        .integerValueOf(mysqlToJavaType(FIELD_TYPE_GEOMETRY)));
556:            }
557:
558:            static final void appendJdbcTypeMappingQuery(StringBuffer buf,
559:                    String mysqlTypeColumnName) {
560:
561:                buf.append("CASE ");
562:                Map typesMap = new HashMap();
563:                typesMap.putAll(mysqlToJdbcTypesMap);
564:                typesMap.put("BINARY", Constants.integerValueOf(Types.BINARY));
565:                typesMap.put("VARBINARY", Constants
566:                        .integerValueOf(Types.VARBINARY));
567:
568:                Iterator mysqlTypes = typesMap.keySet().iterator();
569:
570:                while (mysqlTypes.hasNext()) {
571:                    String mysqlTypeName = (String) mysqlTypes.next();
572:                    buf.append(" WHEN ");
573:                    buf.append(mysqlTypeColumnName);
574:                    buf.append("='");
575:                    buf.append(mysqlTypeName);
576:                    buf.append("' THEN ");
577:                    buf.append(typesMap.get(mysqlTypeName));
578:
579:                    if (mysqlTypeName.equalsIgnoreCase("DOUBLE")
580:                            || mysqlTypeName.equalsIgnoreCase("FLOAT")
581:                            || mysqlTypeName.equalsIgnoreCase("DECIMAL")
582:                            || mysqlTypeName.equalsIgnoreCase("NUMERIC")) {
583:                        buf.append(" WHEN ");
584:                        buf.append(mysqlTypeColumnName);
585:                        buf.append("='");
586:                        buf.append(mysqlTypeName);
587:                        buf.append(" unsigned' THEN ");
588:                        buf.append(typesMap.get(mysqlTypeName));
589:                    }
590:                }
591:
592:                buf.append(" ELSE ");
593:                buf.append(Types.OTHER);
594:                buf.append(" END ");
595:
596:            }
597:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.