01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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
43: NativeJdbcExtractorAdapter {
44:
45: /**
46: * Return <code>true</code>, as CoreStatement does not allow access to the
47: * underlying Connection.
48: */
49: public boolean isNativeConnectionNecessaryForNativeStatements() {
50: return true;
51: }
52:
53: /**
54: * Return <code>true</code>, as CoreCallableStatement does not allow access to the
55: * underlying Connection.
56: */
57: public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
58: return true;
59: }
60:
61: protected Connection doGetNativeConnection(Connection con)
62: throws SQLException {
63: if (con instanceof CoreConnection) {
64: return ((CoreConnection) con).con;
65: }
66: return con;
67: }
68:
69: public PreparedStatement getNativePreparedStatement(
70: PreparedStatement ps) throws SQLException {
71: if (ps instanceof CorePreparedStatement) {
72: return ((CorePreparedStatement) ps).ps;
73: }
74: return ps;
75: }
76:
77: }
|