Source Code Cross Referenced for DefaultConverter.java in  » Database-ORM » ProjectJulp » org » julp » 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 ORM » ProjectJulp » org.julp 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package org.julp;
002:
003:        import java.io.Serializable;
004:        import java.sql.ResultSet;
005:        import java.sql.SQLException;
006:
007:        public class DefaultConverter implements  Serializable, Converter {
008:
009:            protected transient ResultSet resultSet;
010:
011:            public DefaultConverter() {
012:            }
013:
014:            public DefaultConverter(ResultSet resultSet) {
015:                setResultSet(resultSet);
016:            }
017:
018:            public Object[] convert(String fieldClassName, String columnName)
019:                    throws SQLException {
020:                Object value = null;
021:                Object[] convertedValue = null;
022:                // So far there is support only for listed DataTypes. Feel free to add more...        
023:                if (fieldClassName == null) { //???
024:                    convertedValue = new Object[1];
025:                    value = resultSet.getObject(columnName);
026:                    convertedValue[0] = value;
027:                } else if (fieldClassName.equals("java.lang.String")) {
028:                    convertedValue = new String[1];
029:                    value = resultSet.getString(columnName);
030:                    if (resultSet.wasNull()) {
031:                        convertedValue[0] = (String) null;
032:                    } else {
033:                        convertedValue[0] = value;
034:                    }
035:                } else if (fieldClassName.equals("java.lang.Integer")) {
036:                    convertedValue = new Integer[1];
037:                    value = new Integer(resultSet.getInt(columnName));
038:                    if (resultSet.wasNull()) {
039:                        convertedValue[0] = (Integer) null;
040:                    } else {
041:                        convertedValue[0] = value;
042:                    }
043:                } else if (fieldClassName.equals("java.lang.Long")) {
044:                    convertedValue = new Long[1];
045:                    value = new Long(resultSet.getLong(columnName));
046:                    if (resultSet.wasNull()) {
047:                        convertedValue[0] = (Long) null;
048:                    } else {
049:                        convertedValue[0] = value;
050:                    }
051:                } else if (fieldClassName.equals("java.lang.Double")) {
052:                    convertedValue = new Double[1];
053:                    value = new Double(resultSet.getDouble(columnName));
054:                    if (resultSet.wasNull()) {
055:                        convertedValue[0] = (Double) null;
056:                    } else {
057:                        convertedValue[0] = value;
058:                    }
059:                } else if (fieldClassName.equals("java.lang.Float")) {
060:                    convertedValue = new Float[1];
061:                    value = new Float(resultSet.getFloat(columnName));
062:                    if (resultSet.wasNull()) {
063:                        convertedValue[0] = (Float) null;
064:                    } else {
065:                        convertedValue[0] = value;
066:                    }
067:                } else if (fieldClassName.equals("java.lang.Short")) {
068:                    convertedValue = new Short[1];
069:                    value = new Short(resultSet.getShort(columnName));
070:                    if (resultSet.wasNull()) {
071:                        convertedValue[0] = (Short) null;
072:                    } else {
073:                        convertedValue[0] = value;
074:                    }
075:                } else if (fieldClassName.equals("java.sql.Timestamp")) {
076:                    convertedValue = new java.sql.Timestamp[1];
077:                    value = (java.sql.Timestamp) resultSet
078:                            .getTimestamp(columnName);
079:                    if (resultSet.wasNull()) {
080:                        convertedValue[0] = (java.sql.Timestamp) null;
081:                    } else {
082:                        convertedValue[0] = value;
083:                    }
084:                } else if (fieldClassName.equals("java.sql.Time")) {
085:                    convertedValue = new java.sql.Time[1];
086:                    value = (java.sql.Time) resultSet.getTime(columnName);
087:                    if (resultSet.wasNull()) {
088:                        convertedValue[0] = (java.sql.Time) null;
089:                    } else {
090:                        convertedValue[0] = value;
091:                    }
092:                } else if (fieldClassName.equals("java.sql.Date")) {
093:                    convertedValue = new java.sql.Date[1];
094:                    value = (java.sql.Date) resultSet.getDate(columnName);
095:                    if (resultSet.wasNull()) {
096:                        convertedValue[0] = (java.sql.Date) null;
097:                    } else {
098:                        convertedValue[0] = value;
099:                    }
100:                } else if (fieldClassName.equals("java.util.Date")) {
101:                    convertedValue = new java.util.Date[1];
102:                    java.sql.Date d = resultSet.getDate(columnName);
103:                    if (resultSet.wasNull()) {
104:                        convertedValue[0] = (java.util.Date) null;
105:                    } else {
106:                        value = new java.util.Date(d.getTime());
107:                        convertedValue[0] = value;
108:                    }
109:                } else if (fieldClassName.equals("java.math.BigDecimal")) {
110:                    convertedValue = new java.math.BigDecimal[1];
111:                    value = resultSet.getBigDecimal(columnName);
112:                    if (resultSet.wasNull()) {
113:                        convertedValue[0] = (java.math.BigDecimal) null;
114:                    } else {
115:                        convertedValue[0] = value;
116:                    }
117:                } else if (fieldClassName.equals("java.math.BigInteger")) {
118:                    convertedValue = new java.math.BigInteger[1];
119:                    long longValue = 0;
120:                    longValue = resultSet.getLong(columnName);
121:                    if (resultSet.wasNull()) {
122:                        convertedValue[0] = (java.math.BigInteger) null;
123:                    } else {
124:                        value = java.math.BigInteger.valueOf(longValue);
125:                        convertedValue[0] = value;
126:                    }
127:                } else if (fieldClassName.equals("boolean")) {
128:                    convertedValue = new Boolean[1];
129:                    boolean booleanValue = false;
130:                    booleanValue = resultSet.getBoolean(columnName);
131:                    if (resultSet.wasNull()) {
132:                        convertedValue[0] = new Boolean(false);
133:                    } else {
134:                        value = new Boolean(booleanValue);
135:                        convertedValue[0] = value;
136:                    }
137:                } else if (fieldClassName.equals("byte")) {
138:                    convertedValue = new Byte[1];
139:                    byte byteValue = 0;
140:                    byteValue = resultSet.getByte(columnName);
141:                    if (resultSet.wasNull()) {
142:                        byte emptyByte = 0;
143:                        convertedValue[0] = new Byte(emptyByte);
144:                    } else {
145:                        value = new Byte(byteValue);
146:                        convertedValue[0] = value;
147:                    }
148:                } else if (fieldClassName.equals("char")) {
149:                    convertedValue = new Character[1];
150:                    String stringValue = null;
151:                    stringValue = resultSet.getString(columnName);
152:                    if (resultSet.wasNull()) {
153:                        char emptyChar = '\u0000';
154:                        convertedValue[0] = new Character(emptyChar);
155:                    } else {
156:                        value = new Character(stringValue.charAt(0));
157:                        convertedValue[0] = value;
158:                    }
159:                } else if (fieldClassName.equals("double")) {
160:                    convertedValue = new Double[1];
161:                    double doubleValue = 0.0;
162:                    doubleValue = resultSet.getDouble(columnName);
163:                    if (resultSet.wasNull()) {
164:                        convertedValue[0] = new Double(0.0);
165:                    } else {
166:                        value = new Double(doubleValue);
167:                        convertedValue[0] = value;
168:                    }
169:                } else if (fieldClassName.equals("float")) {
170:                    convertedValue = new Float[1];
171:                    float floatValue = 0;
172:                    floatValue = resultSet.getFloat(columnName);
173:                    if (resultSet.wasNull()) {
174:                        convertedValue[0] = new Float(0.0);
175:                    } else {
176:                        value = new Float(floatValue);
177:                        convertedValue[0] = value;
178:                    }
179:                } else if (fieldClassName.equals("int")) {
180:                    convertedValue = new Integer[1];
181:                    int intValue = 0;
182:                    intValue = resultSet.getInt(columnName);
183:                    if (resultSet.wasNull()) {
184:                        convertedValue[0] = new Integer(0);
185:                    } else {
186:                        value = new Integer(intValue);
187:                        convertedValue[0] = value;
188:                    }
189:                } else if (fieldClassName.equals("long")) {
190:                    convertedValue = new Long[1];
191:                    long longValue = 0;
192:                    longValue = resultSet.getLong(columnName);
193:                    if (resultSet.wasNull()) {
194:                        convertedValue[0] = new Long(0);
195:                    } else {
196:                        value = new Long(longValue);
197:                        convertedValue[0] = value;
198:                    }
199:                } else if (fieldClassName.equals("short")) {
200:                    convertedValue = new Short[1];
201:                    short shortValue = 0;
202:                    shortValue = resultSet.getShort(columnName);
203:                    if (resultSet.wasNull()) {
204:                        short s = 0;
205:                        convertedValue[0] = new Short(s);
206:                    } else {
207:                        value = new Short(shortValue);
208:                        convertedValue[0] = value;
209:                    }
210:                } else if (fieldClassName.equals("java.lang.Boolean")) {
211:                    convertedValue = new Boolean[1];
212:                    boolean booleanValue = false;
213:                    booleanValue = resultSet.getBoolean(columnName);
214:                    if (resultSet.wasNull()) {
215:                        convertedValue[0] = new Boolean(false);
216:                    } else {
217:                        value = new Boolean(booleanValue);
218:                        convertedValue[0] = value;
219:                    }
220:                } else if (fieldClassName.equals("java.lang.Character")) {
221:                    convertedValue = new Character[1];
222:                    String stringValue = null;
223:                    stringValue = resultSet.getString(columnName);
224:                    if (resultSet.wasNull()) {
225:                        char emptyChar = '\u0000';
226:                        convertedValue[0] = new Character(emptyChar);
227:                    } else {
228:                        value = new Character(stringValue.charAt(0));
229:                        convertedValue[0] = value;
230:                    }
231:                } else {
232:                    convertedValue = new Object[1];
233:                    value = resultSet.getObject(columnName);
234:                    convertedValue[0] = value;
235:                }
236:                return convertedValue;
237:            }
238:
239:            public ResultSet getResultSet() {
240:                return resultSet;
241:            }
242:
243:            public void setResultSet(ResultSet resultSet) {
244:                this.resultSet = resultSet;
245:            }
246:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.