TransactionFactory.java

  1. /*
  2.  *    Copyright 2009-2024 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. 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.    *
  30.    * @param props
  31.    *          the new properties
  32.    */
  33.   default void setProperties(Properties props) {
  34.     // NOP
  35.   }

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

  47.   /**
  48.    * Creates a {@link Transaction} out of a datasource.
  49.    *
  50.    * @param dataSource
  51.    *          DataSource to take the connection from
  52.    * @param level
  53.    *          Desired isolation level
  54.    * @param autoCommit
  55.    *          Desired autocommit
  56.    *
  57.    * @return Transaction
  58.    *
  59.    * @since 3.1.0
  60.    */
  61.   Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit);

  62. }