Source Code Cross Referenced for DefaultLobHandler.java in  » J2EE » spring-framework-2.5 » org » springframework » jdbc » support » lob » 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 » J2EE » spring framework 2.5 » org.springframework.jdbc.support.lob 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2002-2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.jdbc.support.lob;
018:
019:        import java.io.InputStream;
020:        import java.io.Reader;
021:        import java.sql.PreparedStatement;
022:        import java.sql.ResultSet;
023:        import java.sql.SQLException;
024:
025:        import org.apache.commons.logging.Log;
026:        import org.apache.commons.logging.LogFactory;
027:
028:        /**
029:         * Default implementation of the {@link LobHandler} interface. Invokes
030:         * the direct accessor methods that <code>java.sql.ResultSet</code>
031:         * and <code>java.sql.PreparedStatement</code> offer.
032:         *
033:         * <p>This LobHandler should work for any JDBC driver that is JDBC compliant
034:         * in terms of the spec's suggestions regarding simple BLOB and CLOB handling.
035:         * This does not apply to Oracle 9i, and only to a limited degree to Oracle 10g!
036:         * As a consequence, use {@link OracleLobHandler} for accessing Oracle BLOBs/CLOBs.
037:         *
038:         * @author Juergen Hoeller
039:         * @since 04.12.2003
040:         * @see #setStreamAsLob
041:         * @see java.sql.ResultSet#getBytes
042:         * @see java.sql.ResultSet#getBinaryStream
043:         * @see java.sql.ResultSet#getString
044:         * @see java.sql.ResultSet#getAsciiStream
045:         * @see java.sql.ResultSet#getCharacterStream
046:         * @see java.sql.PreparedStatement#setBytes
047:         * @see java.sql.PreparedStatement#setBinaryStream
048:         * @see java.sql.PreparedStatement#setString
049:         * @see java.sql.PreparedStatement#setAsciiStream
050:         * @see java.sql.PreparedStatement#setCharacterStream
051:         */
052:        public class DefaultLobHandler extends AbstractLobHandler {
053:
054:            protected final Log logger = LogFactory.getLog(getClass());
055:
056:            private boolean streamAsLob = false;
057:
058:            /**
059:             * Specify whether a submitted binary stream / character stream
060:             * should be passed to the JDBC driver as explicit LOB content,
061:             * using the JDBC 4.0 <code>setBlob</code> / <code>setClob</code>
062:             * method with a stream argument.
063:             * <p>Default is "false", using the common JDBC 2.0 <code>setBinaryStream</code>
064:             * / <code>setCharacterStream</code> method for setting the content.
065:             * Switch this to "true" for explicit JDBC 4.0 usage, provided that
066:             * your JDBC driver actually supports those JDBC 4.0 operations.
067:             * @see java.sql.PreparedStatement#setBlob(int, java.io.InputStream, long)
068:             * @see java.sql.PreparedStatement#setClob(int, java.io.Reader, long)
069:             * @see java.sql.PreparedStatement#setBinaryStream(int, java.io.InputStream, int)
070:             * @see java.sql.PreparedStatement#setCharacterStream(int, java.io.Reader, int)
071:             */
072:            public void setStreamAsLob(boolean streamAsLob) {
073:                this .streamAsLob = streamAsLob;
074:            }
075:
076:            public byte[] getBlobAsBytes(ResultSet rs, int columnIndex)
077:                    throws SQLException {
078:                logger.debug("Returning BLOB as bytes");
079:                return rs.getBytes(columnIndex);
080:            }
081:
082:            public InputStream getBlobAsBinaryStream(ResultSet rs,
083:                    int columnIndex) throws SQLException {
084:                logger.debug("Returning BLOB as binary stream");
085:                return rs.getBinaryStream(columnIndex);
086:            }
087:
088:            public String getClobAsString(ResultSet rs, int columnIndex)
089:                    throws SQLException {
090:                logger.debug("Returning CLOB as string");
091:                return rs.getString(columnIndex);
092:            }
093:
094:            public InputStream getClobAsAsciiStream(ResultSet rs,
095:                    int columnIndex) throws SQLException {
096:                logger.debug("Returning CLOB as ASCII stream");
097:                return rs.getAsciiStream(columnIndex);
098:            }
099:
100:            public Reader getClobAsCharacterStream(ResultSet rs, int columnIndex)
101:                    throws SQLException {
102:                logger.debug("Returning CLOB as character stream");
103:                return rs.getCharacterStream(columnIndex);
104:            }
105:
106:            public LobCreator getLobCreator() {
107:                logger.debug("Creating new DefaultLobCreator");
108:                return new DefaultLobCreator();
109:            }
110:
111:            protected class DefaultLobCreator implements  LobCreator {
112:
113:                public void setBlobAsBytes(PreparedStatement ps,
114:                        int paramIndex, byte[] content) throws SQLException {
115:
116:                    ps.setBytes(paramIndex, content);
117:                    if (logger.isDebugEnabled()) {
118:                        logger
119:                                .debug(content != null ? "Set bytes for BLOB with length "
120:                                        + content.length
121:                                        : "Set BLOB to null");
122:                    }
123:                }
124:
125:                public void setBlobAsBinaryStream(PreparedStatement ps,
126:                        int paramIndex, InputStream binaryStream,
127:                        int contentLength) throws SQLException {
128:
129:                    if (streamAsLob) {
130:                        ps.setBlob(paramIndex, binaryStream, contentLength);
131:                    } else {
132:                        ps.setBinaryStream(paramIndex, binaryStream,
133:                                contentLength);
134:                    }
135:                    if (logger.isDebugEnabled()) {
136:                        logger
137:                                .debug(binaryStream != null ? "Set binary stream for BLOB with length "
138:                                        + contentLength
139:                                        : "Set BLOB to null");
140:                    }
141:                }
142:
143:                public void setClobAsString(PreparedStatement ps,
144:                        int paramIndex, String content) throws SQLException {
145:
146:                    ps.setString(paramIndex, content);
147:                    if (logger.isDebugEnabled()) {
148:                        logger
149:                                .debug(content != null ? "Set string for CLOB with length "
150:                                        + content.length()
151:                                        : "Set CLOB to null");
152:                    }
153:                }
154:
155:                public void setClobAsAsciiStream(PreparedStatement ps,
156:                        int paramIndex, InputStream asciiStream,
157:                        int contentLength) throws SQLException {
158:
159:                    ps.setAsciiStream(paramIndex, asciiStream, contentLength);
160:                    if (logger.isDebugEnabled()) {
161:                        logger
162:                                .debug(asciiStream != null ? "Set ASCII stream for CLOB with length "
163:                                        + contentLength
164:                                        : "Set CLOB to null");
165:                    }
166:                }
167:
168:                public void setClobAsCharacterStream(PreparedStatement ps,
169:                        int paramIndex, Reader characterStream,
170:                        int contentLength) throws SQLException {
171:
172:                    if (streamAsLob) {
173:                        ps.setClob(paramIndex, characterStream, contentLength);
174:                    } else {
175:                        ps.setCharacterStream(paramIndex, characterStream,
176:                                contentLength);
177:                    }
178:                    if (logger.isDebugEnabled()) {
179:                        logger
180:                                .debug(characterStream != null ? "Set character stream for CLOB with length "
181:                                        + contentLength
182:                                        : "Set CLOB to null");
183:                    }
184:                }
185:
186:                public void close() {
187:                    logger.debug("Closing DefaultLobCreator");
188:                    // nothing to do here
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.