Source Code Cross Referenced for BasicRowProcessor.java in  » Database-JDBC-Connection-Pool » Database-Utilities » org » apache » commons » dbutils » 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 » Database Utilities » org.apache.commons.dbutils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.dbutils;
018:
019:        import java.sql.ResultSet;
020:        import java.sql.ResultSetMetaData;
021:        import java.sql.SQLException;
022:        import java.util.HashMap;
023:        import java.util.Iterator;
024:        import java.util.List;
025:        import java.util.Map;
026:
027:        /**
028:         * Basic implementation of the <code>RowProcessor</code> interface.
029:         * 
030:         * <p>
031:         * This class is thread-safe.
032:         * </p>
033:         * 
034:         * @see RowProcessor
035:         */
036:        public class BasicRowProcessor implements  RowProcessor {
037:
038:            /**
039:             * The default BeanProcessor instance to use if not supplied in the
040:             * constructor.
041:             */
042:            private static final BeanProcessor defaultConvert = new BeanProcessor();
043:
044:            /**
045:             * The Singleton instance of this class.
046:             */
047:            private static final BasicRowProcessor instance = new BasicRowProcessor();
048:
049:            /**
050:             * Returns the Singleton instance of this class.
051:             *
052:             * @return The single instance of this class.
053:             * @deprecated Create instances with the constructors instead.  This will 
054:             * be removed after DbUtils 1.1.
055:             */
056:            public static BasicRowProcessor instance() {
057:                return instance;
058:            }
059:
060:            /**
061:             * Use this to process beans.
062:             */
063:            private BeanProcessor convert = null;
064:
065:            /**
066:             * BasicRowProcessor constructor.  Bean processing defaults to a 
067:             * BeanProcessor instance.
068:             */
069:            public BasicRowProcessor() {
070:                this (defaultConvert);
071:            }
072:
073:            /**
074:             * BasicRowProcessor constructor.
075:             * @param convert The BeanProcessor to use when converting columns to 
076:             * bean properties.
077:             * @since DbUtils 1.1
078:             */
079:            public BasicRowProcessor(BeanProcessor convert) {
080:                super ();
081:                this .convert = convert;
082:            }
083:
084:            /**
085:             * Convert a <code>ResultSet</code> row into an <code>Object[]</code>.
086:             * This implementation copies column values into the array in the same 
087:             * order they're returned from the <code>ResultSet</code>.  Array elements
088:             * will be set to <code>null</code> if the column was SQL NULL.
089:             *
090:             * @see org.apache.commons.dbutils.RowProcessor#toArray(java.sql.ResultSet)
091:             */
092:            public Object[] toArray(ResultSet rs) throws SQLException {
093:                ResultSetMetaData meta = rs.getMetaData();
094:                int cols = meta.getColumnCount();
095:                Object[] result = new Object[cols];
096:
097:                for (int i = 0; i < cols; i++) {
098:                    result[i] = rs.getObject(i + 1);
099:                }
100:
101:                return result;
102:            }
103:
104:            /**
105:             * Convert a <code>ResultSet</code> row into a JavaBean.  This 
106:             * implementation delegates to a BeanProcessor instance.
107:             * @see org.apache.commons.dbutils.RowProcessor#toBean(java.sql.ResultSet, java.lang.Class)
108:             * @see org.apache.commons.dbutils.BeanProcessor#toBean(java.sql.ResultSet, java.lang.Class) 
109:             */
110:            public Object toBean(ResultSet rs, Class type) throws SQLException {
111:                return this .convert.toBean(rs, type);
112:            }
113:
114:            /**
115:             * Convert a <code>ResultSet</code> into a <code>List</code> of JavaBeans.  
116:             * This implementation delegates to a BeanProcessor instance. 
117:             * @see org.apache.commons.dbutils.RowProcessor#toBeanList(java.sql.ResultSet, java.lang.Class)
118:             * @see org.apache.commons.dbutils.BeanProcessor#toBeanList(java.sql.ResultSet, java.lang.Class)
119:             */
120:            public List toBeanList(ResultSet rs, Class type)
121:                    throws SQLException {
122:                return this .convert.toBeanList(rs, type);
123:            }
124:
125:            /**
126:             * Convert a <code>ResultSet</code> row into a <code>Map</code>.  This 
127:             * implementation returns a <code>Map</code> with case insensitive column
128:             * names as keys.  Calls to <code>map.get("COL")</code> and 
129:             * <code>map.get("col")</code> return the same value.
130:             * @see org.apache.commons.dbutils.RowProcessor#toMap(java.sql.ResultSet)
131:             */
132:            public Map toMap(ResultSet rs) throws SQLException {
133:                Map result = new CaseInsensitiveHashMap();
134:                ResultSetMetaData rsmd = rs.getMetaData();
135:                int cols = rsmd.getColumnCount();
136:
137:                for (int i = 1; i <= cols; i++) {
138:                    result.put(rsmd.getColumnName(i), rs.getObject(i));
139:                }
140:
141:                return result;
142:            }
143:
144:            /**
145:             * A Map that converts all keys to lowercase Strings for case insensitive
146:             * lookups.  This is needed for the toMap() implementation because 
147:             * databases don't consistenly handle the casing of column names. 
148:             */
149:            private static class CaseInsensitiveHashMap extends HashMap {
150:
151:                /**
152:                 * @see java.util.Map#containsKey(java.lang.Object)
153:                 */
154:                public boolean containsKey(Object key) {
155:                    return super .containsKey(key.toString().toLowerCase());
156:                }
157:
158:                /**
159:                 * @see java.util.Map#get(java.lang.Object)
160:                 */
161:                public Object get(Object key) {
162:                    return super .get(key.toString().toLowerCase());
163:                }
164:
165:                /**
166:                 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
167:                 */
168:                public Object put(Object key, Object value) {
169:                    return super .put(key.toString().toLowerCase(), value);
170:                }
171:
172:                /**
173:                 * @see java.util.Map#putAll(java.util.Map)
174:                 */
175:                public void putAll(Map m) {
176:                    Iterator iter = m.keySet().iterator();
177:                    while (iter.hasNext()) {
178:                        Object key = iter.next();
179:                        Object value = m.get(key);
180:                        this .put(key, value);
181:                    }
182:                }
183:
184:                /**
185:                 * @see java.util.Map#remove(java.lang.Object)
186:                 */
187:                public Object remove(Object key) {
188:                    return super.remove(key.toString().toLowerCase());
189:                }
190:            }
191:
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.