From 5aea8bcf6a690660e8072babcadc8454aa2a42e6 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Thu, 29 Aug 2019 20:39:14 -0500 Subject: [PATCH] 6 - SQM based on JPA type system Completed rebase on master (from the point just after HHH-11147 work) - fixed compilation failures --- ...stractDelegatingSessionFactoryOptions.java | 5 - .../boot/spi/SessionFactoryOptions.java | 10 -- .../spi/SharedSessionContractImplementor.java | 15 -- .../org/hibernate/internal/SessionImpl.java | 15 -- .../main/java/org/hibernate/query/Query.java | 170 +++++++++--------- .../MapKeyCustomEnumTypeTest.java | 2 +- .../lazy/StatelessQueryScrollingTest.java | 4 +- .../lazy/proxy/FetchGraphTest.java | 6 +- .../StatelessSessionFetchingTest.java | 8 +- .../junit4/BaseCoreFunctionalTestCase.java | 4 - .../BaseNonConfigCoreFunctionalTestCase.java | 6 - .../testing/transaction/TransactionUtil2.java | 59 ------ 12 files changed, 93 insertions(+), 211 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java index ed70a1b5b9..16507bb3ff 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/AbstractDelegatingSessionFactoryOptions.java @@ -455,11 +455,6 @@ public class AbstractDelegatingSessionFactoryOptions implements SessionFactoryOp return delegate().isUseOfJdbcNamedParametersEnabled(); } - @Override - public Integer getNonJpaNativeQueryOrdinalParameterBase() { - return delegate().getNonJpaNativeQueryOrdinalParameterBase(); - } - @Override public SqmFunctionRegistry getSqmFunctionRegistry() { return delegate().getSqmFunctionRegistry(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java b/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java index 6d69631013..09dc4abfb6 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/spi/SessionFactoryOptions.java @@ -319,16 +319,6 @@ public interface SessionFactoryOptions { SqmFunctionRegistry getSqmFunctionRegistry(); - /** - * See {@link org.hibernate.cfg.AvailableSettings#NATIVE_QUERY_ORDINAL_PARAMETER_BASE} and - * {@link org.hibernate.boot.SessionFactoryBuilder#applyNonJpaNativeQueryOrdinalParameterBase(Integer)} for details. - * - * @return The base integer for ordinal parameters - * - * @since 6.0 - */ - Integer getNonJpaNativeQueryOrdinalParameterBase(); - /** * Controls whether Hibernate should try to map named parameter names * specified in a {@link org.hibernate.procedure.ProcedureCall} or diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java index 98e5079ffd..8e4d8e0be6 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/SharedSessionContractImplementor.java @@ -12,7 +12,6 @@ import java.util.List; import java.util.UUID; import javax.persistence.FlushModeType; import javax.persistence.TransactionRequiredException; -import javax.persistence.criteria.Selection; import org.hibernate.CacheMode; import org.hibernate.FlushMode; @@ -28,10 +27,8 @@ import org.hibernate.engine.jdbc.spi.JdbcCoordinator; import org.hibernate.engine.jdbc.spi.JdbcServices; import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification; import org.hibernate.internal.util.config.ConfigurationHelper; -import org.hibernate.jpa.spi.HibernateEntityManagerImplementor; import org.hibernate.loader.custom.CustomQuery; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.query.spi.QueryImplementor; import org.hibernate.query.spi.QueryProducerImplementor; import org.hibernate.query.spi.ScrollableResultsImplementor; import org.hibernate.resource.jdbc.spi.JdbcSessionOwner; @@ -467,18 +464,6 @@ public interface SharedSessionContractImplementor sessionJdbcBatchSize; } - /** - * @deprecated (since 5.2) - see deprecation note on - * org.hibernate.jpa.spi.HibernateEntityManagerImplementor#createQuery(java.lang.String, java.lang.Class, javax.persistence.criteria.Selection, org.hibernate.jpa.spi.HibernateEntityManagerImplementor.QueryOptions) - * @return The typed query - */ - @Deprecated - QueryImplementor createQuery( - String jpaqlString, - Class resultClass, - Selection selection, - HibernateEntityManagerImplementor.QueryOptions queryOptions); - /** * This is similar to {@link #getPersistenceContext()}, with * two main differences: diff --git a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java index 8af576ca48..d577c171fc 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/SessionImpl.java @@ -17,8 +17,6 @@ import java.sql.Clob; import java.sql.Connection; import java.sql.NClob; import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; @@ -38,10 +36,6 @@ import javax.persistence.PersistenceException; import javax.persistence.PessimisticLockScope; import javax.persistence.StoredProcedureQuery; import javax.persistence.TransactionRequiredException; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaDelete; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.CriteriaUpdate; import org.hibernate.CacheMode; import org.hibernate.Filter; @@ -75,8 +69,6 @@ import org.hibernate.engine.internal.StatefulPersistenceContext; import org.hibernate.engine.jdbc.LobCreator; import org.hibernate.engine.jdbc.NonContextualLobCreator; import org.hibernate.engine.jdbc.spi.JdbcCoordinator; -import org.hibernate.engine.query.spi.NativeSQLQueryPlan; -import org.hibernate.engine.query.spi.sql.NativeSQLQuerySpecification; import org.hibernate.engine.spi.ActionQueue; import org.hibernate.engine.spi.EffectiveEntityGraph; import org.hibernate.engine.spi.EntityEntry; @@ -137,7 +129,6 @@ import org.hibernate.jpa.internal.util.ConfigurationHelper; import org.hibernate.jpa.internal.util.FlushModeTypeHelper; import org.hibernate.jpa.internal.util.LockModeTypeHelper; import org.hibernate.jpa.internal.util.LockOptionsHelper; -import org.hibernate.loader.custom.CustomLoader; import org.hibernate.loader.custom.CustomQuery; import org.hibernate.metamodel.spi.MetamodelImplementor; import org.hibernate.persister.entity.EntityPersister; @@ -147,15 +138,9 @@ import org.hibernate.procedure.ProcedureCall; import org.hibernate.procedure.spi.NamedCallableQueryMemento; import org.hibernate.proxy.HibernateProxy; import org.hibernate.proxy.LazyInitializer; -import org.hibernate.query.ImmutableEntityUpdateQueryHandlingMode; import org.hibernate.query.Query; import org.hibernate.query.UnknownSqlResultSetMappingException; -import org.hibernate.query.spi.QueryImplementor; import org.hibernate.query.spi.ScrollableResultsImplementor; -import org.hibernate.query.sqm.internal.QuerySqmImpl; -import org.hibernate.query.sqm.tree.SqmStatement; -import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; -import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; import org.hibernate.resource.transaction.TransactionRequiredForJoinException; import org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl; import org.hibernate.resource.transaction.spi.TransactionCoordinator; diff --git a/hibernate-core/src/main/java/org/hibernate/query/Query.java b/hibernate-core/src/main/java/org/hibernate/query/Query.java index 7c823bb9f8..cfe11e8d6d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/Query.java +++ b/hibernate-core/src/main/java/org/hibernate/query/Query.java @@ -4,7 +4,6 @@ * License: GNU Lesser General Public License (LGPL), version 2.1 or later * See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html */ - package org.hibernate.query; import java.time.Instant; @@ -14,7 +13,6 @@ import java.time.ZonedDateTime; import java.util.Calendar; import java.util.Collection; import java.util.Date; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Optional; @@ -34,13 +32,11 @@ import org.hibernate.NonUniqueResultException; import org.hibernate.ScrollMode; import org.hibernate.ScrollableResults; import org.hibernate.SharedSessionContract; -import org.hibernate.engine.spi.SharedSessionContractImplementor; import org.hibernate.graph.GraphSemantic; import org.hibernate.graph.RootGraph; import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.query.spi.QueryOptions; import org.hibernate.transform.ResultTransformer; -import org.hibernate.type.Type; /** * Represents an HQL/JPQL query or a compiled Criteria query. Also acts as the Hibernate @@ -552,35 +548,35 @@ public interface Query extends TypedQuery, CommonQueryContract { */ Query setParameterList(int position, Collection values, Class type); - /** - * Bind multiple values to a named query parameter. This is useful for binding - * a list of values to an expression such as foo.bar in (:value_list). - * - * @param name the name of the parameter - * @param values a collection of values to list - * @param type the Hibernate type of the values - * - * @return {@code this}, for method chaining - * - * @deprecated Use {@link #setParameterList(String, Collection, AllowableParameterType)} - */ +// /** +// * Bind multiple values to a named query parameter. This is useful for binding +// * a list of values to an expression such as foo.bar in (:value_list). +// * +// * @param name the name of the parameter +// * @param values a collection of values to list +// * @param type the Hibernate type of the values +// * +// * @return {@code this}, for method chaining +// * +// * @deprecated Use {@link #setParameterList(String, Collection, AllowableParameterType)} +// */ // @Deprecated // default Query setParameterList(String name, Collection values, Type type){ // return setParameter( name, values, (AllowableParameterType) type ); // } - /** - * Bind multiple values to a named query parameter. This is useful for binding - * a list of values to an expression such as foo.bar in (:value_list). - * - * @param position the parameter positional label - * @param values a collection of values to list - * @param type the Hibernate type of the values - * - * @return {@code this}, for method chaining - * - * @deprecated Use {@link #setParameterList(String, Collection, AllowableParameterType)} - */ +// /** +// * Bind multiple values to a named query parameter. This is useful for binding +// * a list of values to an expression such as foo.bar in (:value_list). +// * +// * @param position the parameter positional label +// * @param values a collection of values to list +// * @param type the Hibernate type of the values +// * +// * @return {@code this}, for method chaining +// * +// * @deprecated Use {@link #setParameterList(String, Collection, AllowableParameterType)} +// */ // @Deprecated // default Query setParameterList(int position, Collection values, Type type){ // return setParameter( position, values, (AllowableParameterType) type ); @@ -610,35 +606,35 @@ public interface Query extends TypedQuery, CommonQueryContract { */ Query setParameterList(int position, Collection values, AllowableParameterType type); - /** - * Bind multiple values to a named query parameter. This is useful for binding - * a list of values to an expression such as foo.bar in (:value_list). - * - * @param name the name of the parameter - * @param values a collection of values to list - * @param type the Hibernate type of the values - * - * @return {@code this}, for method chaining - * - * @deprecated Use {@link #setParameterList(String, Object[], AllowableParameterType)} - */ - @Deprecated +// /** +// * Bind multiple values to a named query parameter. This is useful for binding +// * a list of values to an expression such as foo.bar in (:value_list). +// * +// * @param name the name of the parameter +// * @param values a collection of values to list +// * @param type the Hibernate type of the values +// * +// * @return {@code this}, for method chaining +// * +// * @deprecated Use {@link #setParameterList(String, Object[], AllowableParameterType)} +// */ +// @Deprecated // default Query setParameterList(String name, Object[] values, Type type){ // return setParameter( name, values, (AllowableParameterType)type ); // } - /** - * Bind multiple values to a named query parameter. This is useful for binding - * a list of values to an expression such as foo.bar in (:value_list). - * - * @param position the parameter positional label - * @param values a collection of values to list - * @param type the Hibernate type of the values - * - * @return {@code this}, for method chaining - * - * @deprecated Use {@link #setParameterList(String, Object[], AllowableParameterType)} - */ +// /** +// * Bind multiple values to a named query parameter. This is useful for binding +// * a list of values to an expression such as foo.bar in (:value_list). +// * +// * @param position the parameter positional label +// * @param values a collection of values to list +// * @param type the Hibernate type of the values +// * +// * @return {@code this}, for method chaining +// * +// * @deprecated Use {@link #setParameterList(String, Object[], AllowableParameterType)} +// */ // @Deprecated // default Query setParameterList(int position, Object[] values, Type type){ // return setParameter( position, values, (AllowableParameterType)type ); @@ -722,50 +718,50 @@ public interface Query extends TypedQuery, CommonQueryContract { // deprecations - /** - * Bind a named query parameter using the supplied Type - * - * @param name the name of the parameter - * @param val the possibly-null parameter value - * @param type the Hibernate type - * - * @return {@code this}, for method chaining - * - * @deprecated Use {@link #setParameter(String, Object, AllowableParameterType)} - */ +// /** +// * Bind a named query parameter using the supplied Type +// * +// * @param name the name of the parameter +// * @param val the possibly-null parameter value +// * @param type the Hibernate type +// * +// * @return {@code this}, for method chaining +// * +// * @deprecated Use {@link #setParameter(String, Object, AllowableParameterType)} +// */ // @Deprecated // default Query setParameter(String name, Object val, Type type){ // return setParameter( name, val, (AllowableParameterType) type ); // } - /** - * Bind a value to a JDBC-style query parameter. - * - * @param position the position of the parameter in the query - * string, numbered from 0. - * @param val the possibly-null parameter value - * @param type the Hibernate type - * - * @return {@code this}, for method chaining - * - * @deprecated Use {@link #setParameter(int, Object, AllowableParameterType)} - */ +// /** +// * Bind a value to a JDBC-style query parameter. +// * +// * @param position the position of the parameter in the query +// * string, numbered from 0. +// * @param val the possibly-null parameter value +// * @param type the Hibernate type +// * +// * @return {@code this}, for method chaining +// * +// * @deprecated Use {@link #setParameter(int, Object, AllowableParameterType)} +// */ // @Deprecated // default Query setParameter(int position, Object val, Type type) { // return setParameter( position, val, (AllowableParameterType) type ); // } - /** - * Bind a query parameter using the supplied Type - * - * @param parameter The query parameter memento - * @param val the possibly-null parameter value - * @param type the Hibernate type - * - * @return {@code this}, for method chaining - * - * @deprecated Use {@link #setParameter(QueryParameter, Object, AllowableParameterType)} - */ +// /** +// * Bind a query parameter using the supplied Type +// * +// * @param parameter The query parameter memento +// * @param val the possibly-null parameter value +// * @param type the Hibernate type +// * +// * @return {@code this}, for method chaining +// * +// * @deprecated Use {@link #setParameter(QueryParameter, Object, AllowableParameterType)} +// */ // @Deprecated // default

Query setParameter(QueryParameter

parameter, P val, Type type){ // return setParameter( parameter, val, (AllowableParameterType) type ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/custom_mapkey/MapKeyCustomEnumTypeTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/custom_mapkey/MapKeyCustomEnumTypeTest.java index 326f22d049..5e1e258f70 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/custom_mapkey/MapKeyCustomEnumTypeTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/enumerated/custom_mapkey/MapKeyCustomEnumTypeTest.java @@ -204,7 +204,7 @@ public class MapKeyCustomEnumTypeTest extends BaseNonConfigCoreFunctionalTestCas Object param) { assertNotEquals( 0, expected.id ); - EntityMapEnum found = inTransactionReturn( + EntityMapEnum found = fromTransaction( session -> { CriteriaBuilder criteriaBuilder = session.getCriteriaBuilder(); CriteriaQuery criteria = criteriaBuilder.createQuery( EntityMapEnum.class ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/StatelessQueryScrollingTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/StatelessQueryScrollingTest.java index 2aa0d1cdf4..dd93185979 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/StatelessQueryScrollingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/StatelessQueryScrollingTest.java @@ -51,7 +51,7 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest final Query query = statelessSession.createQuery( "from Task t join fetch t.resource join fetch t.user" ); scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY ); while ( scrollableResults.next() ) { - Task taskRef = (Task) scrollableResults.get( 0 ); + Task taskRef = (Task) scrollableResults.get(); assertTrue( Hibernate.isInitialized( taskRef ) ); assertTrue( Hibernate.isInitialized( taskRef.getUser() ) ); assertTrue( Hibernate.isInitialized( taskRef.getResource() ) ); @@ -86,7 +86,7 @@ public class StatelessQueryScrollingTest extends BaseNonConfigCoreFunctionalTest scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY ); } while ( scrollableResults.next() ) { - Producer producer = (Producer) scrollableResults.get( 0 ); + Producer producer = (Producer) scrollableResults.get(); assertTrue( Hibernate.isInitialized( producer ) ); assertTrue( Hibernate.isPropertyInitialized( producer, "products" ) ); assertTrue( Hibernate.isInitialized( producer.getProducts() ) ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/proxy/FetchGraphTest.java b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/proxy/FetchGraphTest.java index 10ec469f9e..244a728601 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/proxy/FetchGraphTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/lazy/proxy/FetchGraphTest.java @@ -140,7 +140,7 @@ public class FetchGraphTest extends BaseNonConfigCoreFunctionalTestCase { final ScrollableResults scrollableResults = session.createQuery( qry ).scroll(); while ( scrollableResults.next() ) { - System.out.println( "Got entity : " + scrollableResults.get( 0 ) ); + System.out.println( "Got entity : " + scrollableResults.get() ); } } ); @@ -156,7 +156,7 @@ public class FetchGraphTest extends BaseNonConfigCoreFunctionalTestCase { final ScrollableResults scrollableResults = session.createQuery( qry ).scroll(); while ( scrollableResults.next() ) { - System.out.println( "Got entity : " + scrollableResults.get( 0 ) ); + System.out.println( "Got entity : " + scrollableResults.get() ); } } ); @@ -167,7 +167,7 @@ public class FetchGraphTest extends BaseNonConfigCoreFunctionalTestCase { final ScrollableResults scrollableResults = session.createQuery( qry ).scroll(); while ( scrollableResults.next() ) { - System.out.println( "Got entity : " + scrollableResults.get( 0 ) ); + System.out.println( "Got entity : " + scrollableResults.get() ); } } ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java b/hibernate-core/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java index 1b058e74e5..3b9547d8b1 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/stateless/fetching/StatelessSessionFetchingTest.java @@ -10,7 +10,6 @@ import java.util.Date; import java.util.Locale; import org.hibernate.Hibernate; -import org.hibernate.Query; import org.hibernate.ScrollMode; import org.hibernate.ScrollableResults; import org.hibernate.Session; @@ -21,6 +20,7 @@ import org.hibernate.cfg.Configuration; import org.hibernate.dialect.DB2Dialect; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.internal.util.StringHelper; +import org.hibernate.query.Query; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -133,7 +133,7 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase { final Query query = ss.createQuery( "from Task t join fetch t.resource join fetch t.user"); final ScrollableResults scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY); while ( scrollableResults.next() ) { - Task taskRef = (Task) scrollableResults.get( 0 ); + Task taskRef = (Task) ( (Object[]) scrollableResults.get() )[0]; assertTrue( Hibernate.isInitialized( taskRef ) ); assertTrue( Hibernate.isInitialized( taskRef.getUser() ) ); assertTrue( Hibernate.isInitialized( taskRef.getResource() ) ); @@ -180,7 +180,7 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase { final Query query = session.createQuery( "from Task t join fetch t.resource join fetch t.user"); final ScrollableResults scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY ); while ( scrollableResults.next() ) { - Task taskRef = (Task) scrollableResults.get( 0 ); + Task taskRef = (Task) ( (Object[]) scrollableResults.get() )[0]; assertTrue( Hibernate.isInitialized( taskRef ) ); assertTrue( Hibernate.isInitialized( taskRef.getUser() ) ); assertTrue( Hibernate.isInitialized( taskRef.getResource() ) ); @@ -238,7 +238,7 @@ public class StatelessSessionFetchingTest extends BaseCoreFunctionalTestCase { scrollableResults = query.scroll( ScrollMode.FORWARD_ONLY ); } while ( scrollableResults.next() ) { - Producer producer = (Producer) scrollableResults.get( 0 ); + Producer producer = (Producer) ( (Object[]) scrollableResults.get() )[0]; assertTrue( Hibernate.isInitialized( producer ) ); assertTrue( Hibernate.isInitialized( producer.getProducts() ) ); diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index 970d989df5..6d813712de 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -511,10 +511,6 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { TransactionUtil2.inTransaction( sessionFactory(), action ); } - protected R inTransactionReturn(Function function) { - return TransactionUtil2.inTransactionReturn( sessionFactory(), function ); - } - protected void inTransaction(SessionImplementor session, Consumer action) { TransactionUtil2.inTransaction( session, action ); } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java index 8460d49eed..7a9640806f 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseNonConfigCoreFunctionalTestCase.java @@ -582,9 +582,3 @@ public class BaseNonConfigCoreFunctionalTestCase extends BaseUnitTestCase { return TransactionUtil2.fromTransaction( sessionFactory(), action ); } } - - public R inTransactionReturn(Function action) { - log.trace( "#inTransaction(action)" ); - return TransactionUtil2.inTransactionReturn( sessionFactory(), action ); - } -} diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil2.java b/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil2.java index 6d00da838c..8f0c967944 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil2.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/transaction/TransactionUtil2.java @@ -85,65 +85,6 @@ public class TransactionUtil2 { ); } - public static R inTransactionReturn(SessionFactoryImplementor factory, Function action) { - log.trace( "#inTransaction(factory, action)" ); - - return inSessionReturn( - factory, - session -> inTransactionReturn( session, action ) - ); - } - - public static R inTransactionReturn(SessionImplementor session, Function action) { - log.trace( "inTransaction(session,action)" ); - - final Transaction txn = session.beginTransaction(); - log.trace( "Started transaction" ); - R result = null; - try { - log.trace( "Calling action in txn" ); - result = action.apply( session ); - log.trace( "Called action - in txn" ); - - if ( !txn.isActive() ) { - throw new TransactionManagementException( ACTION_COMPLETED_TXN ); - } - } - catch (Exception e) { - // an error happened in the action - if ( ! txn.isActive() ) { - log.warn( ACTION_COMPLETED_TXN, e ); - } - else { - log.trace( "Rolling back transaction due to action error" ); - try { - txn.rollback(); - log.trace( "Rolled back transaction due to action error" ); - } - catch (Exception inner) { - log.trace( "Rolling back transaction due to action error failed; throwing original error" ); - } - } - - throw e; - } - - // action completed with no errors - attempt to commit the transaction allowing - // any RollbackException to propagate. Note that when we get here we know the - // txn is active - - log.trace( "Committing transaction after successful action execution" ); - try { - txn.commit(); - log.trace( "Committing transaction after successful action execution - success" ); - } - catch (Exception e) { - log.trace( "Committing transaction after successful action execution - failure" ); - throw e; - } - return result; - } - public static void inTransaction(SessionImplementor session, Consumer action) { log.trace( "inTransaction(session,action)" );