1 /* 2 * Copyright 2002-2005 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.springframework.jdbc.support.nativejdbc; 18 19 import java.sql.Connection; 20 import java.sql.PreparedStatement; 21 import java.sql.SQLException; 22 23 import org.enhydra.jdbc.core.CoreConnection; 24 import org.enhydra.jdbc.core.CorePreparedStatement; 25 26 /** 27 * Implementation of the NativeJdbcExtractor interface for ObjectWeb's XAPool. 28 * 29 * <p>Returns underlying native Connections and native PreparedStatements to 30 * application code instead of XAPool's wrapper implementations; unwraps the 31 * Connection for native Statements and native CallableStatements. 32 * The returned JDBC classes can then safely be cast, e.g. to 33 * <code>oracle.jdbc.OracleConnection</code>. 34 * 35 * <p>This NativeJdbcExtractor can be set just to <i>allow</i> working with 36 * an XAPool DataSource: If a given object is not an XAPool wrapper, it will 37 * be returned as-is. 38 * 39 * @author Juergen Hoeller 40 * @since 06.02.2004 41 */ 42 public class XAPoolNativeJdbcExtractor extends NativeJdbcExtractorAdapter { 43 44 /** 45 * Return <code>true</code>, as CoreStatement does not allow access to the 46 * underlying Connection. 47 */ 48 public boolean isNativeConnectionNecessaryForNativeStatements() { 49 return true; 50 } 51 52 /** 53 * Return <code>true</code>, as CoreCallableStatement does not allow access to the 54 * underlying Connection. 55 */ 56 public boolean isNativeConnectionNecessaryForNativeCallableStatements() { 57 return true; 58 } 59 60 protected Connection doGetNativeConnection(Connection con) throws SQLException { 61 if (con instanceof CoreConnection) { 62 return ((CoreConnection) con).con; 63 } 64 return con; 65 } 66 67 public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException { 68 if (ps instanceof CorePreparedStatement) { 69 return ((CorePreparedStatement) ps).ps; 70 } 71 return ps; 72 } 73 74 } 75