View Javadoc
1   /*
2    *    Copyright 2009-2021 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.apache.ibatis.transaction;
17  
18  import java.sql.Connection;
19  import java.sql.SQLException;
20  
21  /**
22   * Wraps a database connection.
23   * Handles the connection lifecycle that comprises: its creation, preparation, commit/rollback and close.
24   *
25   * @author Clinton Begin
26   */
27  public interface Transaction {
28  
29    /**
30     * Retrieve inner database connection.
31     * @return DataBase connection
32     * @throws SQLException
33     *           the SQL exception
34     */
35    Connection getConnection() throws SQLException;
36  
37    /**
38     * Commit inner database connection.
39     * @throws SQLException
40     *           the SQL exception
41     */
42    void commit() throws SQLException;
43  
44    /**
45     * Rollback inner database connection.
46     * @throws SQLException
47     *           the SQL exception
48     */
49    void rollback() throws SQLException;
50  
51    /**
52     * Close inner database connection.
53     * @throws SQLException
54     *           the SQL exception
55     */
56    void close() throws SQLException;
57  
58    /**
59     * Get transaction timeout if set.
60     *
61     * @return the timeout
62     * @throws SQLException
63     *           the SQL exception
64     */
65    Integer getTimeout() throws SQLException;
66  
67  }