Source Code Cross Referenced for ValueConverterFactory.java in  » GIS » openjump » com » vividsolutions » jump » datastore » 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 » GIS » openjump » com.vividsolutions.jump.datastore.jdbc 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.vividsolutions.jump.datastore.jdbc;
002:
003:        import com.vividsolutions.jump.datastore.*;
004:        import java.sql.*;
005:        import java.io.*;
006:        import com.vividsolutions.jump.feature.*;
007:        import com.vividsolutions.jts.geom.*;
008:        import com.vividsolutions.jts.io.*;
009:
010:        /**
011:         * Standard data converters for JDBC.
012:         * Clients can extend this class, or simply call it.
013:         *
014:         * @author Martin Davis
015:         * @version 1.0
016:         */
017:        public class ValueConverterFactory {
018:            public static final ValueConverter DOUBLE_MAPPER = new DoubleConverter();
019:            public static final ValueConverter INTEGER_MAPPER = new IntegerConverter();
020:            public static final ValueConverter DATE_MAPPER = new DateConverter();
021:            public static final ValueConverter STRING_MAPPER = new StringConverter();
022:
023:            public ValueConverterFactory() {
024:
025:            }
026:
027:            /**
028:             * Handles finding a converter for standard JDBC types.
029:             * Clients should handle custom types themselves.
030:             *
031:             * @param rsm
032:             * @param columnIndex
033:             * @return null if no converter could be found
034:             * @throws SQLException
035:             */
036:            public static ValueConverter getConverter(ResultSetMetaData rsm,
037:                    int columnIndex) throws SQLException {
038:                String classname = rsm.getColumnClassName(columnIndex);
039:                String dbTypeName = rsm.getColumnTypeName(columnIndex);
040:                int precision = rsm.getPrecision(columnIndex);
041:                int scale = rsm.getScale(columnIndex);
042:                int sqlType = rsm.getColumnType(columnIndex);
043:
044:                if (sqlType == Types.INTEGER
045:                        || classname.equalsIgnoreCase("java.lang.Integer")
046:                        || (classname.equalsIgnoreCase("java.math.BigDecimal")
047:                                && precision == 10 && scale == 0))
048:                    return INTEGER_MAPPER;
049:
050:                if (classname.equalsIgnoreCase("java.math.BigDecimal"))
051:                    return DOUBLE_MAPPER;
052:
053:                if (classname.equalsIgnoreCase("java.sql.Timestamp"))
054:                    return DATE_MAPPER;
055:
056:                if (classname.equalsIgnoreCase("java.String"))
057:                    return STRING_MAPPER;
058:
059:                // default is string
060:                return STRING_MAPPER;
061:            }
062:
063:            public static class IntegerConverter implements  ValueConverter {
064:                public AttributeType getType() {
065:                    return AttributeType.INTEGER;
066:                }
067:
068:                public Object getValue(ResultSet rs, int columnIndex)
069:                        throws SQLException {
070:                    return new Integer(rs.getInt(columnIndex));
071:                }
072:            }
073:
074:            public static class DoubleConverter implements  ValueConverter {
075:                public AttributeType getType() {
076:                    return AttributeType.DOUBLE;
077:                }
078:
079:                public Object getValue(ResultSet rs, int columnIndex)
080:                        throws SQLException {
081:                    return new Double(rs.getDouble(columnIndex));
082:                }
083:            }
084:
085:            public static class StringConverter implements  ValueConverter {
086:                public AttributeType getType() {
087:                    return AttributeType.STRING;
088:                }
089:
090:                public Object getValue(ResultSet rs, int columnIndex)
091:                        throws SQLException {
092:                    return rs.getString(columnIndex);
093:                }
094:            }
095:
096:            public static class DateConverter implements  ValueConverter {
097:                public AttributeType getType() {
098:                    return AttributeType.DATE;
099:                }
100:
101:                public Object getValue(ResultSet rs, int columnIndex)
102:                        throws SQLException {
103:                    return rs.getDate(columnIndex);
104:                }
105:            }
106:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.