Class TransactionUtil
- java.lang.Object
-
- org.hibernate.testing.transaction.TransactionUtil
-
public class TransactionUtil extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TransactionUtil.HibernateTransactionConsumer
Hibernate transaction function without return valuestatic interface
TransactionUtil.HibernateTransactionFunction<T>
Hibernate transaction functionstatic interface
TransactionUtil.JDBCTransactionFunction<T>
JDBC transaction functionstatic interface
TransactionUtil.JDBCTransactionVoidFunction
JDBC transaction function without return valuestatic interface
TransactionUtil.JPATransactionFunction<T>
JPA transaction functionstatic interface
TransactionUtil.JPATransactionVoidFunction
JPA transaction function without return value
-
Constructor Summary
Constructors Constructor Description TransactionUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
doInAutoCommit(java.lang.String... statements)
Use the default settings for building a newServiceRegistry
and create a new JDBCConnection
in auto-commit mode.static void
doInAutoCommit(java.util.function.Consumer<java.sql.Statement> consumer)
Use the default settings for building a newServiceRegistry
and create a new JDBCConnection
in auto-commit mode.static void
doInAutoCommit(java.util.function.Consumer<java.sql.Statement> consumer, java.util.Map settings)
Use the supplied settings for building a newServiceRegistry
and create a new JDBCConnection
in auto-commit mode.static void
doInAutoCommit(java.util.Map settings, java.lang.String... statements)
Use the supplied settings for building a newServiceRegistry
and create a new JDBCConnection
in auto-commit mode.static void
doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, java.lang.String tenant, java.util.function.Consumer<Session> function)
Execute function in a Hibernate transaction without return value and for a given tenantstatic <R> R
doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, java.lang.String tenant, java.util.function.Function<Session,R> function)
Execute function in a Hibernate transaction for a given tenant and return a valuestatic void
doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, java.util.function.Consumer<Session> function)
static void
doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, TransactionUtil.HibernateTransactionConsumer function)
Execute function in a Hibernate transaction without return valuestatic <T> T
doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, TransactionUtil.HibernateTransactionFunction<T> function)
Execute function in a Hibernate transactionstatic void
doInHibernateSessionBuilder(java.util.function.Supplier<SessionBuilder> sessionBuilderSupplier, TransactionUtil.HibernateTransactionConsumer function)
Execute function in a Hibernate transaction without return valuestatic <T> T
doInHibernateSessionBuilder(java.util.function.Supplier<SessionBuilder> sessionBuilderSupplier, TransactionUtil.HibernateTransactionFunction<T> function)
Execute function in a Hibernate transactionstatic <T> T
doInJPA(java.util.function.Supplier<EntityManagerFactory> factorySupplier, TransactionUtil.JPATransactionFunction<T> function)
Execute function in a JPA transactionstatic <T> T
doInJPA(java.util.function.Supplier<EntityManagerFactory> factorySupplier, TransactionUtil.JPATransactionFunction<T> function, java.util.Map properties)
Execute function in a JPA transactionstatic void
doInJPA(java.util.function.Supplier<EntityManagerFactory> factorySupplier, TransactionUtil.JPATransactionVoidFunction function)
Execute function in a JPA transaction without return valuestatic void
doInJPA(java.util.function.Supplier<EntityManagerFactory> factorySupplier, TransactionUtil.JPATransactionVoidFunction function, java.util.Map properties)
Execute function in a JPA transaction without return valuestatic <T> T
doWithJDBC(ServiceRegistry serviceRegistry, TransactionUtil.JDBCTransactionFunction<T> function)
static void
doWithJDBC(ServiceRegistry serviceRegistry, TransactionUtil.JDBCTransactionVoidFunction function)
static void
setJdbcTimeout(Session session)
Set Session or Statement timeoutstatic void
setJdbcTimeout(Session session, long millis)
Set Session or Statement timeout
-
-
-
Method Detail
-
doInHibernate
public static void doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, java.util.function.Consumer<Session> function)
-
doInJPA
public static <T> T doInJPA(java.util.function.Supplier<EntityManagerFactory> factorySupplier, TransactionUtil.JPATransactionFunction<T> function, java.util.Map properties)
Execute function in a JPA transaction- Type Parameters:
T
- result type- Parameters:
factorySupplier
- EntityManagerFactory supplierfunction
- functionproperties
- properties for entity manager bootstrapping- Returns:
- result
-
doInJPA
public static <T> T doInJPA(java.util.function.Supplier<EntityManagerFactory> factorySupplier, TransactionUtil.JPATransactionFunction<T> function)
Execute function in a JPA transaction- Type Parameters:
T
- result type- Parameters:
factorySupplier
- EntityManagerFactory supplierfunction
- function- Returns:
- result
-
doInJPA
public static void doInJPA(java.util.function.Supplier<EntityManagerFactory> factorySupplier, TransactionUtil.JPATransactionVoidFunction function, java.util.Map properties)
Execute function in a JPA transaction without return value- Parameters:
factorySupplier
- EntityManagerFactory supplierfunction
- functionproperties
- properties for entity manager bootstrapping
-
doInJPA
public static void doInJPA(java.util.function.Supplier<EntityManagerFactory> factorySupplier, TransactionUtil.JPATransactionVoidFunction function)
Execute function in a JPA transaction without return value- Parameters:
factorySupplier
- EntityManagerFactory supplierfunction
- function
-
doInHibernate
public static <T> T doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, TransactionUtil.HibernateTransactionFunction<T> function)
Execute function in a Hibernate transaction- Type Parameters:
T
- result type- Parameters:
factorySupplier
- SessionFactory supplierfunction
- function- Returns:
- result
-
doInHibernate
public static void doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, TransactionUtil.HibernateTransactionConsumer function)
Execute function in a Hibernate transaction without return value- Parameters:
factorySupplier
- SessionFactory supplierfunction
- function
-
doInHibernate
public static void doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, java.lang.String tenant, java.util.function.Consumer<Session> function)
Execute function in a Hibernate transaction without return value and for a given tenant- Parameters:
factorySupplier
- SessionFactory suppliertenant
- tenantfunction
- function
-
doInHibernate
public static <R> R doInHibernate(java.util.function.Supplier<SessionFactory> factorySupplier, java.lang.String tenant, java.util.function.Function<Session,R> function)
Execute function in a Hibernate transaction for a given tenant and return a value- Parameters:
factorySupplier
- SessionFactory suppliertenant
- tenantfunction
- function- Returns:
- result
-
doInHibernateSessionBuilder
public static <T> T doInHibernateSessionBuilder(java.util.function.Supplier<SessionBuilder> sessionBuilderSupplier, TransactionUtil.HibernateTransactionFunction<T> function)
Execute function in a Hibernate transaction- Type Parameters:
T
- result type- Parameters:
sessionBuilderSupplier
- SessionFactory supplierfunction
- function- Returns:
- result
-
doInHibernateSessionBuilder
public static void doInHibernateSessionBuilder(java.util.function.Supplier<SessionBuilder> sessionBuilderSupplier, TransactionUtil.HibernateTransactionConsumer function)
Execute function in a Hibernate transaction without return value- Parameters:
sessionBuilderSupplier
- SessionFactory supplierfunction
- function
-
setJdbcTimeout
public static void setJdbcTimeout(Session session)
Set Session or Statement timeout- Parameters:
session
- Hibernate Session
-
setJdbcTimeout
public static void setJdbcTimeout(Session session, long millis)
Set Session or Statement timeout- Parameters:
session
- Hibernate Session
-
doInAutoCommit
public static void doInAutoCommit(java.util.function.Consumer<java.sql.Statement> consumer, java.util.Map settings)
Use the supplied settings for building a newServiceRegistry
and create a new JDBCConnection
in auto-commit mode. A new JDBCStatement
is created and passed to the supplied callback.- Parameters:
consumer
-Statement
callback to execute statements in auto-commit modesettings
- Settings to build a newServiceRegistry
-
doInAutoCommit
public static void doInAutoCommit(java.util.function.Consumer<java.sql.Statement> consumer)
Use the default settings for building a newServiceRegistry
and create a new JDBCConnection
in auto-commit mode. A new JDBCStatement
is created and passed to the supplied callback.- Parameters:
consumer
-Statement
callback to execute statements in auto-commit mode
-
doInAutoCommit
public static void doInAutoCommit(java.util.Map settings, java.lang.String... statements)
Use the supplied settings for building a newServiceRegistry
and create a new JDBCConnection
in auto-commit mode. The supplied statements will be executed using the previously created connection- Parameters:
settings
- Settings to build a newServiceRegistry
statements
- statements to be executed in auto-commit mode
-
doInAutoCommit
public static void doInAutoCommit(java.lang.String... statements)
Use the default settings for building a newServiceRegistry
and create a new JDBCConnection
in auto-commit mode. The supplied statements will be executed using the previously created connection- Parameters:
statements
- statements to be executed in auto-commit mode
-
doWithJDBC
public static void doWithJDBC(ServiceRegistry serviceRegistry, TransactionUtil.JDBCTransactionVoidFunction function) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
doWithJDBC
public static <T> T doWithJDBC(ServiceRegistry serviceRegistry, TransactionUtil.JDBCTransactionFunction<T> function) throws java.sql.SQLException
- Throws:
java.sql.SQLException
-
-