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.ResultSet;
  21. import java.sql.SQLException;
  22. import java.sql.Statement;
  23. /**
  24. * Abstract adapter class for the NativeJdbcExtractor interface,
  25. * for simplified implementation of basic extractors.
  26. * Returns the passed-in JDBC objects on all methods.
  27. *
  28. * <p>The <code>getNativeConnectionFromStatement</code> method is implemented
  29. * to simply delegate to <code>getNativeConnection</code> with the Statement's
  30. * Connection. This is what most extractor implementations will stick to,
  31. * unless there's a more efficient version for a specific pool.
  32. *
  33. * @author Juergen Hoeller
  34. * @since 02.06.2004
  35. * @see #getNativeConnectionFromStatement
  36. * @see #getNativeConnection
  37. */
  38. public abstract class NativeJdbcExtractorAdapter implements NativeJdbcExtractor {
  39. /**
  40. * Return false by default.
  41. */
  42. public boolean isNativeConnectionNecessaryForNativeStatements() {
  43. return false;
  44. }
  45. /**
  46. * Return false by default.
  47. */
  48. public boolean isNativeConnectionNecessaryForNativePreparedStatements() {
  49. return false;
  50. }
  51. /**
  52. * Return false by default.
  53. */
  54. public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
  55. return false;
  56. }
  57. /**
  58. * Not able to unwrap: return passed-in Connection.
  59. */
  60. public Connection getNativeConnection(Connection con) throws SQLException {
  61. return con;
  62. }
  63. /**
  64. * Retrieve the Connection via the Statement's Connection.
  65. * @see #getNativeConnection
  66. * @see Statement#getConnection
  67. */
  68. public Connection getNativeConnectionFromStatement(Statement stmt) throws SQLException {
  69. return getNativeConnection(stmt.getConnection());
  70. }
  71. /**
  72. * Not able to unwrap: return passed-in Statement.
  73. */
  74. public Statement getNativeStatement(Statement stmt) throws SQLException {
  75. return stmt;
  76. }
  77. /**
  78. * Not able to unwrap: return passed-in PreparedStatement.
  79. */
  80. public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException {
  81. return ps;
  82. }
  83. /**
  84. * Not able to unwrap: return passed-in CallableStatement.
  85. */
  86. public CallableStatement getNativeCallableStatement(CallableStatement cs) throws SQLException {
  87. return cs;
  88. }
  89. /**
  90. * Not able to unwrap: return passed-in ResultSet.
  91. */
  92. public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
  93. return rs;
  94. }
  95. }