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 com.mchange.v2.c3p0.C3P0ProxyConnection; 24 25 import org.springframework.util.ReflectionUtils; 26 27 47 public class C3P0NativeJdbcExtractor extends NativeJdbcExtractorAdapter { 48 49 private final Method getRawConnectionMethod; 50 51 52 58 public static Connection getRawConnection(Connection con) { 59 return con; 60 } 61 62 63 public C3P0NativeJdbcExtractor() { 64 try { 65 this.getRawConnectionMethod = getClass().getMethod("getRawConnection", new Class [] {Connection .class}); 66 } 67 catch (NoSuchMethodException ex) { 68 throw new IllegalStateException ("Internal error in C3P0NativeJdbcExtractor: " + ex.getMessage()); 69 } 70 } 71 72 73 public boolean isNativeConnectionNecessaryForNativeStatements() { 74 return true; 75 } 76 77 public boolean isNativeConnectionNecessaryForNativePreparedStatements() { 78 return true; 79 } 80 81 public boolean isNativeConnectionNecessaryForNativeCallableStatements() { 82 return true; 83 } 84 85 91 protected Connection doGetNativeConnection(Connection con) throws SQLException { 92 if (con instanceof C3P0ProxyConnection) { 93 C3P0ProxyConnection cpCon = (C3P0ProxyConnection) con; 94 try { 95 return (Connection ) cpCon.rawConnectionOperation( 96 this.getRawConnectionMethod, null, new Object [] {C3P0ProxyConnection.RAW_CONNECTION}); 97 } 98 catch (SQLException ex) { 99 throw ex; 100 } 101 catch (Exception ex) { 102 ReflectionUtils.handleReflectionException(ex); 103 } 104 } 105 return con; 106 } 107 108 } 109 | Popular Tags |