From ffa6212b407ff8e4ae74d3ada5a74bc2823f9aed Mon Sep 17 00:00:00 2001 From: Vlad Mihalcea Date: Tue, 12 Jul 2016 09:32:06 +0300 Subject: [PATCH] Fix code style issues --- .../testing/transaction/TransactionUtil.java | 379 ++++++++++-------- 1 file changed, 207 insertions(+), 172 deletions(-) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java b/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java index 7807ed2560..de153227ed 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil.java @@ -22,197 +22,232 @@ import org.hibernate.Transaction; */ public class TransactionUtil { - /** - * Hibernate transaction function - * @param function result - */ - @FunctionalInterface - public interface HibernateTransactionFunction extends Function { - /** - * Before transaction completion function - */ - default void beforeTransactionCompletion() { + /** + * Hibernate transaction function + * + * @param function result + */ + @FunctionalInterface + public interface HibernateTransactionFunction + extends Function { + /** + * Before transaction completion function + */ + default void beforeTransactionCompletion() { - } + } - /** - * After transaction completion function - */ - default void afterTransactionCompletion() { + /** + * After transaction completion function + */ + default void afterTransactionCompletion() { - } - } + } + } - /** - * Hibernate transaction function without return value - */ - @FunctionalInterface - public interface HibernateTransactionConsumer extends Consumer { - /** - * Before transaction completion function - */ - default void beforeTransactionCompletion() { + /** + * Hibernate transaction function without return value + */ + @FunctionalInterface + public interface HibernateTransactionConsumer extends Consumer { + /** + * Before transaction completion function + */ + default void beforeTransactionCompletion() { - } + } - /** - * After transaction completion function - */ - default void afterTransactionCompletion() { + /** + * After transaction completion function + */ + default void afterTransactionCompletion() { - } - } + } + } - /** - * JPA transaction function - * @param function result - */ - @FunctionalInterface - public interface JPATransactionFunction extends Function { - /** - * Before transaction completion function - */ - default void beforeTransactionCompletion() { + /** + * JPA transaction function + * + * @param function result + */ + @FunctionalInterface + public interface JPATransactionFunction + extends Function { + /** + * Before transaction completion function + */ + default void beforeTransactionCompletion() { - } + } - /** - * After transaction completion function - */ - default void afterTransactionCompletion() { + /** + * After transaction completion function + */ + default void afterTransactionCompletion() { - } - } + } + } - /** - * JPA transaction function without return value - */ - @FunctionalInterface - public interface JPATransactionVoidFunction extends Consumer { - /** - * Before transaction completion function - */ - default void beforeTransactionCompletion() { + /** + * JPA transaction function without return value + */ + @FunctionalInterface + public interface JPATransactionVoidFunction + extends Consumer { + /** + * Before transaction completion function + */ + default void beforeTransactionCompletion() { - } + } - /** - * After transaction completion function - */ - default void afterTransactionCompletion() { + /** + * After transaction completion function + */ + default void afterTransactionCompletion() { - } - } + } + } - /** - * Execute function in a JPA transaction - * @param factorySupplier EntityManagerFactory supplier - * @param function function - * @param result type - * @return result - */ - public static T doInJPA(Supplier factorySupplier, JPATransactionFunction function) { - T result = null; - EntityManager entityManager = null; - EntityTransaction txn = null; - try { - entityManager = factorySupplier.get().createEntityManager(); - function.beforeTransactionCompletion(); - txn = entityManager.getTransaction(); - txn.begin(); - result = function.apply(entityManager); - txn.commit(); - } catch (Throwable e) { - if ( txn != null && txn.isActive()) txn.rollback(); - throw e; - } finally { - function.afterTransactionCompletion(); - if (entityManager != null) { - entityManager.close(); - } - } - return result; - } + /** + * Execute function in a JPA transaction + * + * @param factorySupplier EntityManagerFactory supplier + * @param function function + * @param result type + * + * @return result + */ + public static T doInJPA( + Supplier factorySupplier, + JPATransactionFunction function) { + T result = null; + EntityManager entityManager = null; + EntityTransaction txn = null; + try { + entityManager = factorySupplier.get().createEntityManager(); + function.beforeTransactionCompletion(); + txn = entityManager.getTransaction(); + txn.begin(); + result = function.apply( entityManager ); + txn.commit(); + } + catch ( Throwable e ) { + if ( txn != null && txn.isActive() ) { + txn.rollback(); + } + throw e; + } + finally { + function.afterTransactionCompletion(); + if ( entityManager != null ) { + entityManager.close(); + } + } + return result; + } - /** - * Execute function in a JPA transaction without return value - * @param factorySupplier EntityManagerFactory supplier - * @param function function - */ - public static void doInJPA(Supplier factorySupplier, JPATransactionVoidFunction function) { - EntityManager entityManager = null; - EntityTransaction txn = null; - try { - entityManager = factorySupplier.get().createEntityManager(); - function.beforeTransactionCompletion(); - txn = entityManager.getTransaction(); - txn.begin(); - function.accept(entityManager); - txn.commit(); - } catch (Throwable e) { - if ( txn != null && txn.isActive()) txn.rollback(); - throw e; - } finally { - function.afterTransactionCompletion(); - if (entityManager != null) { - entityManager.close(); - } - } - } + /** + * Execute function in a JPA transaction without return value + * + * @param factorySupplier EntityManagerFactory supplier + * @param function function + */ + public static void doInJPA( + Supplier factorySupplier, + JPATransactionVoidFunction function) { + EntityManager entityManager = null; + EntityTransaction txn = null; + try { + entityManager = factorySupplier.get().createEntityManager(); + function.beforeTransactionCompletion(); + txn = entityManager.getTransaction(); + txn.begin(); + function.accept( entityManager ); + txn.commit(); + } + catch ( Throwable e ) { + if ( txn != null && txn.isActive() ) { + txn.rollback(); + } + throw e; + } + finally { + function.afterTransactionCompletion(); + if ( entityManager != null ) { + entityManager.close(); + } + } + } - /** - * Execute function in a Hibernate transaction - * @param factorySupplier EntityManagerFactory supplier - * @param function function - * @param result type - * @return result - */ - public static T doInHibernate(Supplier factorySupplier, HibernateTransactionFunction function) { - T result = null; - Session session = null; - Transaction txn = null; - try { - session = factorySupplier.get().openSession(); - function.beforeTransactionCompletion(); - txn = session.beginTransaction(); + /** + * Execute function in a Hibernate transaction + * + * @param factorySupplier EntityManagerFactory supplier + * @param function function + * @param result type + * + * @return result + */ + public static T doInHibernate( + Supplier factorySupplier, + HibernateTransactionFunction function) { + T result = null; + Session session = null; + Transaction txn = null; + try { + session = factorySupplier.get().openSession(); + function.beforeTransactionCompletion(); + txn = session.beginTransaction(); - result = function.apply(session); - txn.commit(); - } catch (Throwable e) { - if ( txn != null ) txn.rollback(); - throw e; - } finally { - function.afterTransactionCompletion(); - if (session != null) { - session.close(); - } - } - return result; - } + result = function.apply( session ); + txn.commit(); + } + catch ( Throwable e ) { + if ( txn != null ) { + txn.rollback(); + } + throw e; + } + finally { + function.afterTransactionCompletion(); + if ( session != null ) { + session.close(); + } + } + return result; + } - /** - * Execute function in a JPA transaction without return value - * @param factorySupplier EntityManagerFactory supplier - * @param function function - */ - public static void doInHibernate(Supplier factorySupplier, HibernateTransactionConsumer function) { - Session session = null; - Transaction txn = null; - try { - session = factorySupplier.get().openSession(); - function.beforeTransactionCompletion(); - txn = session.beginTransaction(); + /** + * Execute function in a JPA transaction without return value + * + * @param factorySupplier EntityManagerFactory supplier + * @param function function + */ + public static void doInHibernate( + Supplier factorySupplier, + HibernateTransactionConsumer function) { + Session session = null; + Transaction txn = null; + try { + session = factorySupplier.get().openSession(); + function.beforeTransactionCompletion(); + txn = session.beginTransaction(); - function.accept(session); - txn.commit(); - } catch (Throwable e) { - if ( txn != null ) txn.rollback(); - throw e; - } finally { - function.afterTransactionCompletion(); - if (session != null) { - session.close(); - } - } - } + function.accept( session ); + txn.commit(); + } + catch ( Throwable e ) { + if ( txn != null ) { + txn.rollback(); + } + throw e; + } + finally { + function.afterTransactionCompletion(); + if ( session != null ) { + session.close(); + } + } + } }