1. /*
  2. * Copyright 2002-2004 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. package org.springframework.jdbc.support.nativejdbc;
  17. import java.sql.Connection;
  18. import java.sql.PreparedStatement;
  19. import java.sql.SQLException;
  20. import org.enhydra.jdbc.core.CoreConnection;
  21. import org.enhydra.jdbc.core.CorePreparedStatement;
  22. /**
  23. * Implementation of the NativeJdbcExtractor interface for ObjectWeb's XAPool.
  24. * Returns underlying native Connections and native PreparedStatements to
  25. * application code instead of XAPool's wrapper implementations; unwraps the
  26. * Connection for native Statements and native CallableStatements.
  27. * The returned JDBC classes can then safely be cast, e.g. to OracleResultSet.
  28. *
  29. * <p>This NativeJdbcExtractor can be set just to <i>allow</i> working with
  30. * an XAPool DataSource: If a given object is not an XAPool wrapper, it will
  31. * be returned as-is.
  32. *
  33. * @author Juergen Hoeller
  34. * @since 06.02.2004
  35. */
  36. public class XAPoolNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
  37. /**
  38. * Return true, as CoreStatement does not allow access to the
  39. * underlying Connection.
  40. */
  41. public boolean isNativeConnectionNecessaryForNativeStatements() {
  42. return true;
  43. }
  44. /**
  45. * Return true, as CoreCallableStatement does not allow access to the
  46. * underlying Connection.
  47. */
  48. public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
  49. return true;
  50. }
  51. public Connection getNativeConnection(Connection con) throws SQLException {
  52. if (con instanceof CoreConnection) {
  53. return ((CoreConnection) con).con;
  54. }
  55. return con;
  56. }
  57. public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException {
  58. if (ps instanceof CorePreparedStatement) {
  59. return ((CorePreparedStatement) ps).ps;
  60. }
  61. return ps;
  62. }
  63. }