Class TransactionUtil


  • public class TransactionUtil
    extends java.lang.Object
    • Constructor Detail

      • TransactionUtil

        public TransactionUtil()
    • 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 supplier
        function - function
        properties - 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 supplier
        function - 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 supplier
        function - function
        properties - properties for entity manager bootstrapping
      • 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 supplier
        function - 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 supplier
        function - 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 supplier
        tenant - tenant
        function - 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 supplier
        tenant - tenant
        function - 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 supplier
        function - 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 supplier
        function - 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 new ServiceRegistry and create a new JDBC Connection in auto-commit mode. A new JDBC Statement is created and passed to the supplied callback.
        Parameters:
        consumer - Statement callback to execute statements in auto-commit mode
        settings - Settings to build a new ServiceRegistry
      • doInAutoCommit

        public static void doInAutoCommit​(java.util.function.Consumer<java.sql.Statement> consumer)
        Use the default settings for building a new ServiceRegistry and create a new JDBC Connection in auto-commit mode. A new JDBC Statement 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 new ServiceRegistry and create a new JDBC Connection in auto-commit mode. The supplied statements will be executed using the previously created connection
        Parameters:
        settings - Settings to build a new ServiceRegistry
        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 new ServiceRegistry and create a new JDBC Connection 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