1 16 17 package org.springframework.jdbc.support.nativejdbc; 18 19 import java.lang.reflect.Method ; 20 import java.sql.Connection ; 21 import java.sql.SQLException ; 22 23 import org.apache.commons.logging.Log; 24 import org.apache.commons.logging.LogFactory; 25 26 import org.springframework.util.ReflectionUtils; 27 28 50 public class WebSphereNativeJdbcExtractor extends NativeJdbcExtractorAdapter { 51 52 private static final String JDBC_ADAPTER_CONNECTION_NAME_5 = "com.ibm.ws.rsadapter.jdbc.WSJdbcConnection"; 53 54 private static final String JDBC_ADAPTER_UTIL_NAME_5 = "com.ibm.ws.rsadapter.jdbc.WSJdbcUtil"; 55 56 private static final String CONNECTION_PROXY_NAME_4 = "com.ibm.ejs.cm.proxy.ConnectionProxy"; 57 58 59 protected final Log logger = LogFactory.getLog(getClass()); 60 61 private Class webSphere5ConnectionClass; 62 63 private Class webSphere4ConnectionClass; 64 65 private Method webSphere5NativeConnectionMethod; 66 67 private Method webSphere4PhysicalConnectionMethod; 68 69 70 74 public WebSphereNativeJdbcExtractor() { 75 try { 77 logger.debug("Trying WebSphere 5 Connection: " + JDBC_ADAPTER_CONNECTION_NAME_5); 78 this.webSphere5ConnectionClass = getClass().getClassLoader().loadClass(JDBC_ADAPTER_CONNECTION_NAME_5); 79 Class jdbcAdapterUtilClass = getClass().getClassLoader().loadClass(JDBC_ADAPTER_UTIL_NAME_5); 80 this.webSphere5NativeConnectionMethod = 81 jdbcAdapterUtilClass.getMethod("getNativeConnection", new Class [] {this.webSphere5ConnectionClass}); 82 } 83 catch (Exception ex) { 84 logger.debug("Could not find WebSphere 5 connection pool classes", ex); 85 } 86 87 try { 90 logger.debug("Trying WebSphere 4 Connection: " + CONNECTION_PROXY_NAME_4); 91 this.webSphere4ConnectionClass = getClass().getClassLoader().loadClass(CONNECTION_PROXY_NAME_4); 92 this.webSphere4PhysicalConnectionMethod = 93 this.webSphere4ConnectionClass.getMethod("getPhysicalConnection", (Class []) null); 94 } 95 catch (Exception ex) { 96 logger.debug("Could not find WebSphere 4 connection pool classes", ex); 97 } 98 } 99 100 101 104 public boolean isNativeConnectionNecessaryForNativeStatements() { 105 return true; 106 } 107 108 111 public boolean isNativeConnectionNecessaryForNativePreparedStatements() { 112 return true; 113 } 114 115 118 public boolean isNativeConnectionNecessaryForNativeCallableStatements() { 119 return true; 120 } 121 122 125 protected Connection doGetNativeConnection(Connection con) throws SQLException { 126 if (this.webSphere5ConnectionClass != null && 128 this.webSphere5ConnectionClass.isAssignableFrom(con.getClass())) { 129 return (Connection ) ReflectionUtils.invokeMethod( 131 this.webSphere5NativeConnectionMethod, null, new Object [] {con}); 132 } 133 134 else if (this.webSphere4ConnectionClass != null && 136 this.webSphere4ConnectionClass.isAssignableFrom(con.getClass())) { 137 return (Connection ) ReflectionUtils.invokeMethod(this.webSphere4PhysicalConnectionMethod, con); 139 } 140 141 else { 143 if (logger.isDebugEnabled()) { 144 logger.debug("Connection [" + con + "] is not a WebSphere 5/4 connection, returning as-is"); 145 } 146 return con; 147 } 148 } 149 150 } 151 | Popular Tags |