Source Code Cross Referenced for org_postgresql_Driver.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » database » types » databasedrivers » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.database.types.databasedrivers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: org_postgresql_Driver.java 3695 2007-03-16 09:26:50Z gbevin $
007:         */
008:        package com.uwyn.rife.database.types.databasedrivers;
009:
010:        import java.sql.*;
011:
012:        import com.uwyn.rife.database.types.SqlArrays;
013:        import com.uwyn.rife.database.types.SqlConversion;
014:        import com.uwyn.rife.database.types.SqlNull;
015:        import com.uwyn.rife.database.types.databasedrivers.Common;
016:        import com.uwyn.rife.tools.ClassUtils;
017:        import com.uwyn.rife.tools.StringUtils;
018:        import java.math.BigDecimal;
019:        import java.util.Calendar;
020:        import java.util.Date;
021:
022:        public class org_postgresql_Driver extends Common implements 
023:                SqlConversion {
024:            public String getSqlValue(Object value) {
025:                // handle the null value
026:                if (null == value || SqlNull.NULL == value) {
027:                    return SqlNull.NULL.toString();
028:                }
029:                // make sure that strings are escaped correctly
030:                else if (value instanceof  CharSequence) {
031:                    if (0 == ((CharSequence) value).length()) {
032:                        return "''";
033:                    } else {
034:                        return "'" + StringUtils.encodeSql(value.toString())
035:                                + "'";
036:                    }
037:                } else if (value instanceof  Character) {
038:                    if (((Character) value).charValue() == 0) {
039:                        return SqlNull.NULL.toString();
040:                    } else {
041:                        return "'" + StringUtils.encodeSql(value.toString())
042:                                + "'";
043:                    }
044:                }
045:                // handle the numbers
046:                else if (ClassUtils.isNumeric(value.getClass())) {
047:                    return value.toString();
048:                }
049:                // handle the time / date types
050:                else if (value instanceof  Time) {
051:                    return "'" + StringUtils.encodeSql(value.toString()) + "'";
052:                } else if (value instanceof  Timestamp) {
053:                    return "'" + StringUtils.encodeSql(value.toString()) + "'";
054:                } else if (value instanceof  java.sql.Date) {
055:                    return "'" + StringUtils.encodeSql(value.toString()) + "'";
056:                } else if (value instanceof  Date) {
057:                    return "'"
058:                            + StringUtils.encodeSql(new Timestamp(
059:                                    ((Date) value).getTime()).toString()) + "'";
060:                } else if (value instanceof  Calendar) {
061:                    return "'"
062:                            + StringUtils.encodeSql(new Timestamp(
063:                                    ((Calendar) value).getTime().getTime())
064:                                    .toString()) + "'";
065:                }
066:                // make sure that the Boolean type is correctly caught
067:                else if (value instanceof  Boolean) {
068:                    if (((Boolean) value).booleanValue()) {
069:                        return "true";
070:                    } else {
071:                        return "false";
072:                    }
073:                }
074:                // make sure that the object arrays are correctly caught
075:                else if (value instanceof  Object[]) {
076:                    return SqlArrays.convertArray((Object[]) value);
077:                }
078:                // just return the other types through their toString() method
079:                else {
080:                    return "'" + StringUtils.encodeSql(value.toString()) + "'";
081:                }
082:            }
083:
084:            protected Object retrieveFieldObject(ResultSet resultSet,
085:                    int columnNumber, int type) throws SQLException {
086:                assert resultSet != null;
087:                assert columnNumber > 0;
088:
089:                Object result = null;
090:
091:                if (type == Types.BIT || type == Types.BOOLEAN) {
092:                    boolean value = resultSet.getBoolean(columnNumber);
093:                    if (!resultSet.wasNull()) {
094:                        result = Boolean.valueOf(value);
095:                    }
096:                } else if (type == Types.TINYINT) {
097:                    byte value = resultSet.getByte(columnNumber);
098:                    if (!resultSet.wasNull()) {
099:                        result = new Byte(value);
100:                    }
101:                } else if (type == Types.SMALLINT || type == Types.INTEGER) {
102:                    int value = resultSet.getInt(columnNumber);
103:                    if (!resultSet.wasNull()) {
104:                        result = new Integer(value);
105:                    }
106:                } else if (type == Types.BIGINT) {
107:                    long value = resultSet.getLong(columnNumber);
108:                    if (!resultSet.wasNull()) {
109:                        result = new Long(value);
110:                    }
111:                } else if (type == Types.CHAR || type == Types.VARCHAR
112:                        || type == Types.LONGVARCHAR) {
113:                    result = resultSet.getString(columnNumber);
114:                } else if (type == Types.DATE) {
115:                    result = resultSet.getDate(columnNumber);
116:                } else if (type == Types.TIME) {
117:                    result = resultSet.getTime(columnNumber);
118:                } else if (type == Types.TIMESTAMP) {
119:                    result = resultSet.getTimestamp(columnNumber);
120:                } else if (type == Types.NUMERIC || type == Types.DECIMAL) {
121:                    result = resultSet.getBigDecimal(columnNumber);
122:                } else if (type == Types.DOUBLE || type == Types.FLOAT
123:                        || type == Types.REAL) {
124:                    double value = resultSet.getDouble(columnNumber);
125:                    if (!resultSet.wasNull()) {
126:                        result = new Double(value);
127:                    }
128:                } else if (type == Types.BLOB) {
129:                    result = resultSet.getBlob(columnNumber);
130:                } else if (type == Types.CLOB) {
131:                    result = resultSet.getClob(columnNumber);
132:                } else if (type == Types.REF) {
133:                    result = resultSet.getRef(columnNumber);
134:                } else if (type == Types.JAVA_OBJECT || type == Types.OTHER) {
135:                    result = resultSet.getObject(columnNumber);
136:                } else if (type == Types.ARRAY) {
137:                    result = resultSet.getArray(columnNumber);
138:                } else if (type == Types.BINARY || type == Types.LONGVARBINARY
139:                        || type == Types.VARBINARY) {
140:                    result = resultSet.getBinaryStream(columnNumber);
141:                }
142:
143:                return result;
144:            }
145:
146:            public String getSqlType(Class type, int precision, int scale) {
147:                // handle character types
148:                if (type == String.class || type == StringBuilder.class
149:                        || type == StringBuffer.class) {
150:                    if (precision < 0) {
151:                        return "TEXT";
152:                    } else {
153:                        return "VARCHAR(" + precision + ")";
154:                    }
155:                } else if (type == Character.class || type == char.class) {
156:                    if (precision < 0) {
157:                        return "CHAR";
158:                    } else {
159:                        return "CHAR(" + precision + ")";
160:                    }
161:                }
162:                // handle the time / date types
163:                else if (type == Time.class) {
164:                    return "TIME";
165:                } else if (type == java.sql.Date.class) {
166:                    return "DATE";
167:                } else if (type == Timestamp.class || type == Date.class
168:                        || type == Calendar.class) {
169:                    return "TIMESTAMP";
170:                }
171:                // make sure that the Boolean type is correctly caught
172:                else if (type == Boolean.class || type == boolean.class) {
173:                    return "BOOLEAN";
174:                }
175:                // make sure that the Integer types are correctly caught
176:                else if (type == Byte.class || type == byte.class
177:                        || type == Short.class || type == short.class) {
178:                    return "SMALLINT";
179:                } else if (type == Integer.class || type == int.class) {
180:                    return "INTEGER";
181:                } else if (type == Long.class || type == long.class) {
182:                    return "BIGINT";
183:                }
184:                // make sure that the Float types are correctly caught
185:                else if (type == Double.class || type == double.class
186:                        || type == Float.class || type == float.class) {
187:                    return "FLOAT";
188:                }
189:                // make sure that the BigDecimal type is correctly caught
190:                else if (type == BigDecimal.class) {
191:                    if (precision < 0) {
192:                        return "NUMERIC";
193:                    } else if (scale < 0) {
194:                        return "NUMERIC(" + precision + ")";
195:                    } else {
196:                        return "NUMERIC(" + precision + "," + scale + ")";
197:                    }
198:                }
199:                // make sure that the Blob type is correctly caught
200:                else if (type == Blob.class || type == byte[].class) {
201:                    return "BYTEA";
202:                }
203:                // make sure that the Clob type is correctly caught
204:                else if (type == Clob.class) {
205:                    return "TEXT";
206:                } else {
207:                    String result = handleCommonSqlType(type, precision, scale);
208:                    if (result != null) {
209:                        return result;
210:                    }
211:
212:                    // just return a TEXT type in which the object's toString value will be stored
213:                    return "TEXT";
214:                }
215:            }
216:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.