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.orm.ibatis;
  17. import java.sql.Connection;
  18. import java.sql.SQLException;
  19. import com.ibatis.db.sqlmap.MappedStatement;
  20. /**
  21. * Callback interface for data access code that works on an iBATIS Database Layer
  22. * MappedStatement. To be used with SqlMapTemplate's execute method, assumably
  23. * often as anonymous classes within a method implementation.
  24. *
  25. * <p>NOTE: The SqlMap/MappedStatement API is the one to use with iBATIS SQL Maps 1.x.
  26. * The SqlMapClient/SqlMapSession API is only available with SQL Maps 2.
  27. *
  28. * @author Juergen Hoeller
  29. * @since 28.11.2003
  30. */
  31. public interface SqlMapCallback {
  32. /**
  33. * Gets called by SqlMapTemplate.execute with an active JDBC Connection. Does not
  34. * need to care about the lifecycle of the Connection or handling transactions.
  35. *
  36. * <p>If called without a thread-bound JDBC transaction (initiated by
  37. * DataSourceTransactionManager), the code will simply get executed on the
  38. * underlying JDBC connection with its transactional semantics. If using
  39. * a JTA-aware DataSource, the JDBC connection and thus the callback code
  40. * will be transactional if a JTA transaction is active.
  41. *
  42. * <p>Allows for returning a result object created within the callback, i.e.
  43. * a domain object or a collection of domain objects. Note that there's
  44. * special support for single step actions: see SqlMapTemplate.
  45. * A thrown RuntimeException is treated as application exception, it gets
  46. * propagated to the caller of the template.
  47. *
  48. * @param stmt the iBATIS Database Layer mapped statement
  49. * @param con the JDBC Connection to work on
  50. * @return a result object, or null if none
  51. * @throws SQLException if thrown by MappedStatement methods
  52. * @see SqlMapTemplate#execute
  53. * @see SqlMapTemplate#executeQueryForList
  54. * @see SqlMapTemplate#executeQueryForMap
  55. * @see SqlMapTemplate#executeUpdate
  56. * @see org.springframework.jdbc.datasource.DataSourceTransactionManager
  57. */
  58. Object doInMappedStatement(MappedStatement stmt, Connection con) throws SQLException;
  59. }