All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.ebeaninternal.server.transaction.TransactionFactory Maven / Gradle / Ivy

There is a newer version: 15.8.0
Show newest version
package io.ebeaninternal.server.transaction;

import io.ebean.util.JdbcClose;
import io.ebeaninternal.api.SpiTransaction;

import jakarta.persistence.PersistenceException;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Creates transactions with implementations for basic mode and multi-tenancy mode.
 */
abstract class TransactionFactory {

  final TransactionManager manager;

  TransactionFactory(TransactionManager manager) {
    this.manager = manager;
  }

  /**
   * Return a new query only transaction.
   *
   * @param tenantId  The tenantId for lazy loading queries.
   * @param useMaster Explicitly use the master data source rather than read only data source
   */
  abstract SpiTransaction createReadOnlyTransaction(Object tenantId, boolean useMaster);

  /**
   * Return a new transaction.
   */
  abstract SpiTransaction createTransaction(boolean explicit, int isolationLevel);

  /**
   * Set the Transaction Isolation level if required.
   */
  final SpiTransaction setIsolationLevel(SpiTransaction t, boolean explicit, int isolationLevel) {
    if (isolationLevel > -1) {
      Connection connection = t.internalConnection();
      try {
        connection.setTransactionIsolation(isolationLevel);
      } catch (SQLException e) {
        JdbcClose.close(connection);
        throw new PersistenceException(e);
      }
    }
    return t;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy