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.CallableStatement;
  18. import java.sql.Connection;
  19. import java.sql.PreparedStatement;
  20. import java.sql.SQLException;
  21. import java.sql.Statement;
  22. import org.jboss.resource.adapter.jdbc.WrappedCallableStatement;
  23. import org.jboss.resource.adapter.jdbc.WrappedConnection;
  24. import org.jboss.resource.adapter.jdbc.WrappedPreparedStatement;
  25. import org.jboss.resource.adapter.jdbc.WrappedStatement;
  26. /**
  27. * Implementation of the NativeJdbcExtractor interface for the JBoss 3.2
  28. * connection pool. Returns the underlying native Connection, Statement,
  29. * etc to application code instead of JBoss' wrapper implementations.
  30. * The returned JDBC classes can then safely be cast, e.g. to OracleConnection.
  31. *
  32. * <p>This NativeJdbcExtractor can be set just to <i>allow</i> working with
  33. * a JBoss connection pool: If a given object is not a JBoss wrapper,
  34. * it will be returned as-is.
  35. *
  36. * @author Juergen Hoeller
  37. * @since 03.01.2004
  38. */
  39. public class JBossNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
  40. public Connection getNativeConnection(Connection con) throws SQLException {
  41. if (con instanceof WrappedConnection) {
  42. return ((WrappedConnection) con).getUnderlyingConnection();
  43. }
  44. return con;
  45. }
  46. public Statement getNativeStatement(Statement stmt) throws SQLException {
  47. if (stmt instanceof WrappedStatement) {
  48. return ((WrappedStatement) stmt).getUnderlyingStatement();
  49. }
  50. return stmt;
  51. }
  52. public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException {
  53. if (ps instanceof WrappedPreparedStatement) {
  54. return (PreparedStatement) ((WrappedPreparedStatement) ps).getUnderlyingStatement();
  55. }
  56. return ps;
  57. }
  58. public CallableStatement getNativeCallableStatement(CallableStatement cs) throws SQLException {
  59. if (cs instanceof WrappedCallableStatement) {
  60. return (CallableStatement) ((WrappedCallableStatement) cs).getUnderlyingStatement();
  61. }
  62. return cs;
  63. }
  64. }