@Test public void testUnsuccessfulExecutionWithoutTransaction() { DefaultExecution<Integer> execution = new DefaultExecution<>(null, factory); assertThrows(RuntimeException.class, () -> execution.execute(entityManager -> { throw new RuntimeException(); })); }
@Override public T execute(@NonNull Function<EntityManager, T> function) throws SQLException { DefaultTransactionData data = null; EntityManager entityManager = sessionFactory.createEntityManager(); try { data = checkAndBeginTransaction(entityManager); T response = function.apply(entityManager); checkAndCommit(data, entityManager); entityManager.close(); return response; } catch (Exception e) { handleException(entityManager, data); throw e; } }
DefaultExecution implements Execution<T> { @Override public T execute(@NonNull Function<EntityManager, T> function) throws SQLException { DefaultTransactionData data = null; EntityManager entityManager = sessionFactory.createEntityManager(); try { data = checkAndBeginTransaction(entityManager); T response = function.apply(entityManager); checkAndCommit(data, entityManager); entityManager.close(); return response; } catch (Exception e) { handleException(entityManager, data); throw e; } } }
DefaultExecution implements Execution<T> { @Override public T execute(@NonNull Function<EntityManager, T> function) throws SQLException { DefaultTransactionData data = null; EntityManager entityManager = sessionFactory.createEntityManager(); try { data = checkAndBeginTransaction(entityManager); T response = function.apply(entityManager); checkAndCommit(data, entityManager); entityManager.close(); return response; } catch (Exception e) { handleException(entityManager, data); throw e; } }  }
DefaultExecution implements Execution<T> { @Override public T execute(@NonNull Function<EntityManager, T> function) throws SQLException { DefaultTransactionData data = null; EntityManager entityManager = sessionFactory.createEntityManager(); try { data = checkAndBeginTransaction(entityManager); T response = function.apply(entityManager); checkAndCommit(data, entityManager); entityManager.close(); return response; } catch (Exception e) { handleException(entityManager, data); throw e; } }  @Override T execute(@NonNull Function<EntityManager, T> function); }
DefaultExecution implements Execution<T> { @Override public T execute(@NonNull Function<EntityManager, T> function) throws SQLException { DefaultTransactionData data = null; EntityManager entityManager = sessionFactory.createEntityManager(); try { data = checkAndBeginTransaction(entityManager); T response = function.apply(entityManager); checkAndCommit(data, entityManager); entityManager.close(); return response; } catch (Exception e) { handleException(entityManager, data); throw e; } }  @Override T execute(@NonNull Function<EntityManager, T> function);  }