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