TransactionFactory.java

  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. import java.sql.Connection;
  18. import java.util.Properties;

  19. import javax.sql.DataSource;

  20. import org.apache.ibatis.session.TransactionIsolationLevel;

  21. /**
  22.  * Creates {@link Transaction} instances.
  23.  *
  24.  * @author Clinton Begin
  25.  */
  26. public interface TransactionFactory {

  27.   /**
  28.    * Sets transaction factory custom properties.
  29.    * @param props
  30.    *          the new properties
  31.    */
  32.   default void setProperties(Properties props) {
  33.     // NOP
  34.   }

  35.   /**
  36.    * Creates a {@link Transaction} out of an existing connection.
  37.    * @param conn Existing database connection
  38.    * @return Transaction
  39.    * @since 3.1.0
  40.    */
  41.   Transaction newTransaction(Connection conn);

  42.   /**
  43.    * Creates a {@link Transaction} out of a datasource.
  44.    * @param dataSource DataSource to take the connection from
  45.    * @param level Desired isolation level
  46.    * @param autoCommit Desired autocommit
  47.    * @return Transaction
  48.    * @since 3.1.0
  49.    */
  50.   Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit);

  51. }