1 16 17 package org.springframework.jdbc.support.nativejdbc; 18 19 import java.sql.CallableStatement ; 20 import java.sql.Connection ; 21 import java.sql.DatabaseMetaData ; 22 import java.sql.PreparedStatement ; 23 import java.sql.ResultSet ; 24 import java.sql.SQLException ; 25 import java.sql.Statement ; 26 27 import org.springframework.jdbc.datasource.DataSourceUtils; 28 29 59 public abstract class NativeJdbcExtractorAdapter implements NativeJdbcExtractor { 60 61 64 public boolean isNativeConnectionNecessaryForNativeStatements() { 65 return false; 66 } 67 68 71 public boolean isNativeConnectionNecessaryForNativePreparedStatements() { 72 return false; 73 } 74 75 78 public boolean isNativeConnectionNecessaryForNativeCallableStatements() { 79 return false; 80 } 81 82 94 public Connection getNativeConnection(Connection con) throws SQLException { 95 if (con == null) { 96 return null; 97 } 98 Connection targetCon = DataSourceUtils.getTargetConnection(con); 99 Connection nativeCon = doGetNativeConnection(targetCon); 100 if (nativeCon == targetCon) { 101 DatabaseMetaData metaData = targetCon.getMetaData(); 105 if (metaData != null) { 108 Connection metaCon = metaData.getConnection(); 109 if (metaCon != targetCon) { 110 nativeCon = doGetNativeConnection(metaCon); 113 } 114 } 115 } 116 return nativeCon; 117 } 118 119 122 protected Connection doGetNativeConnection(Connection con) throws SQLException { 123 return con; 124 } 125 126 131 public Connection getNativeConnectionFromStatement(Statement stmt) throws SQLException { 132 if (stmt == null) { 133 return null; 134 } 135 return getNativeConnection(stmt.getConnection()); 136 } 137 138 141 public Statement getNativeStatement(Statement stmt) throws SQLException { 142 return stmt; 143 } 144 145 148 public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException { 149 return ps; 150 } 151 152 155 public CallableStatement getNativeCallableStatement(CallableStatement cs) throws SQLException { 156 return cs; 157 } 158 159 162 public ResultSet getNativeResultSet(ResultSet rs) throws SQLException { 163 return rs; 164 } 165 166 } 167 | Popular Tags |