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.SQLException;
  18. import com.ibatis.sqlmap.client.SqlMapExecutor;
  19. /**
  20. * Callback interface for data access code that works on an iBATIS Database Layer
  21. * SqlMapSession. To be used with SqlMapClientTemplate's execute method,
  22. * assumably often as anonymous classes within a method implementation.
  23. *
  24. * <p>NOTE: The SqlMapClient/SqlMapSession API is the API of iBATIS SQL Maps 2.
  25. * With SQL Maps 1.x, the SqlMap/MappedStatement API has to be used.
  26. *
  27. * @author Juergen Hoeller
  28. * @since 24.02.2004
  29. */
  30. public interface SqlMapClientCallback {
  31. /**
  32. * Gets called by SqlMapClientTemplate.execute with an active SqlMapSession.
  33. * Does not need to care about activating or closing the session,
  34. * 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 SqlMapClientTemplate.
  45. * A thrown RuntimeException is treated as application exception, it gets
  46. * propagated to the caller of the template.
  47. *
  48. * @param executor an active iBATIS SqlMapSession, passed-in as
  49. * SqlMapExecutor interface here to avoid manual lifecycle handling
  50. * @return a result object, or null if none
  51. * @throws SQLException if throw my the iBATIS SQL Maps API
  52. * @see SqlMapClientTemplate#execute
  53. * @see SqlMapClientTemplate#queryForList
  54. * @see SqlMapClientTemplate#queryForMap
  55. * @see SqlMapClientTemplate#queryForObject
  56. * @see SqlMapClientTemplate#insert
  57. * @see SqlMapClientTemplate#update
  58. * @see SqlMapClientTemplate#delete
  59. * @see org.springframework.jdbc.datasource.DataSourceTransactionManager
  60. */
  61. Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException;
  62. }