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


001:        /*
002:         * Copyright 2002-2006 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.nativejdbc;
018:
019:        import java.lang.reflect.Method;
020:        import java.sql.Connection;
021:        import java.sql.SQLException;
022:
023:        import com.mchange.v2.c3p0.C3P0ProxyConnection;
024:
025:        import org.springframework.util.ReflectionUtils;
026:
027:        /**
028:         * Implementation of the NativeJdbcExtractor interface for the C3P0 connection pool.
029:         *
030:         * <p>Returns underlying native Connections to application code instead of C3P0's
031:         * wrapper implementations; unwraps the Connection for native Statements.
032:         * The returned JDBC classes can then safely be cast, e.g. to
033:         * <code>oracle.jdbc.OracleConnection</code>.
034:         *
035:         * <p>This NativeJdbcExtractor can be set just to <i>allow</i> working with
036:         * a C3P0 DataSource: If a given object is not a C3P0 wrapper, it will be
037:         * returned as-is.
038:         *
039:         * <p>Note that this class requires C3P0 0.8.5 or later; for earlier C3P0 versions,
040:         * use SimpleNativeJdbcExtractor (which won't work for C3P0 0.8.5 or later).
041:         *
042:         * @author Juergen Hoeller
043:         * @since 1.1.5
044:         * @see com.mchange.v2.c3p0.C3P0ProxyConnection#rawConnectionOperation
045:         * @see SimpleNativeJdbcExtractor
046:         */
047:        public class C3P0NativeJdbcExtractor extends NativeJdbcExtractorAdapter {
048:
049:            private final Method getRawConnectionMethod;
050:
051:            /**
052:             * This method is not meant to be used directly; it rather serves
053:             * as callback method for C3P0's "rawConnectionOperation" API.
054:             * @param con a native Connection handle
055:             * @return the native Connection handle, as-is
056:             */
057:            public static Connection getRawConnection(Connection con) {
058:                return con;
059:            }
060:
061:            public C3P0NativeJdbcExtractor() {
062:                try {
063:                    this .getRawConnectionMethod = getClass().getMethod(
064:                            "getRawConnection",
065:                            new Class[] { Connection.class });
066:                } catch (NoSuchMethodException ex) {
067:                    throw new IllegalStateException(
068:                            "Internal error in C3P0NativeJdbcExtractor: "
069:                                    + ex.getMessage());
070:                }
071:            }
072:
073:            public boolean isNativeConnectionNecessaryForNativeStatements() {
074:                return true;
075:            }
076:
077:            public boolean isNativeConnectionNecessaryForNativePreparedStatements() {
078:                return true;
079:            }
080:
081:            public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
082:                return true;
083:            }
084:
085:            /**
086:             * Retrieve the Connection via C3P0's <code>rawConnectionOperation</code> API,
087:             * using the <code>getRawConnection</code> as callback to get access to the
088:             * raw Connection (which is otherwise not directly supported by C3P0).
089:             * @see #getRawConnection
090:             */
091:            protected Connection doGetNativeConnection(Connection con)
092:                    throws SQLException {
093:                if (con instanceof  C3P0ProxyConnection) {
094:                    C3P0ProxyConnection cpCon = (C3P0ProxyConnection) con;
095:                    try {
096:                        return (Connection) cpCon
097:                                .rawConnectionOperation(
098:                                        this .getRawConnectionMethod,
099:                                        null,
100:                                        new Object[] { C3P0ProxyConnection.RAW_CONNECTION });
101:                    } catch (SQLException ex) {
102:                        throw ex;
103:                    } catch (Exception ex) {
104:                        ReflectionUtils.handleReflectionException(ex);
105:                    }
106:                }
107:                return con;
108:            }
109:
110:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.