From 8f5d5fd14cd88e2dbab99bab1532b1ee2516e917 Mon Sep 17 00:00:00 2001 From: Gavin Date: Thu, 13 Apr 2023 14:29:18 +0200 Subject: [PATCH] make some methods protected for the benefit of HR misc minor changes --- .../AbstractSharedSessionContract.java | 22 +++++----- .../internal/StatelessSessionImpl.java | 40 +++++++++---------- ...SingleIdEntityLoaderProvidedQueryImpl.java | 2 +- .../query/sql/internal/NativeQueryImpl.java | 1 + .../query/sql/spi/NativeQueryImplementor.java | 1 + 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java index 952ecb88a0..518332e496 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/AbstractSharedSessionContract.java @@ -726,7 +726,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont return query; } - private HqlInterpretation interpretHql(String hql, Class resultType) { + protected HqlInterpretation interpretHql(String hql, Class resultType) { final QueryEngine queryEngine = getFactory().getQueryEngine(); return queryEngine.getInterpretationCache() .resolveHqlInterpretation( @@ -736,13 +736,13 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont ); } - private static void checkSelectionQuery(String hql, HqlInterpretation hqlInterpretation) { + protected static void checkSelectionQuery(String hql, HqlInterpretation hqlInterpretation) { if ( !( hqlInterpretation.getSqmStatement() instanceof SqmSelectStatement ) ) { throw new IllegalSelectQueryException( "Expecting a selection query, but found `" + hql + "`", hql); } } - private static void checkResultType(Class expectedResultType, SqmSelectionQueryImpl query) { + protected static void checkResultType(Class expectedResultType, SqmSelectionQueryImpl query) { final Class resultType = query.getResultType(); if ( !expectedResultType.isAssignableFrom( resultType ) ) { throw new QueryTypeMismatchException( @@ -841,6 +841,11 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont // the clashing signatures declared by the supertypes public NativeQueryImplementor createNativeQuery(String sqlString, Class resultClass) { final NativeQueryImpl query = createNativeQuery( sqlString ); + addResultType( resultClass, query ); + return query; + } + + protected void addResultType(Class resultClass, NativeQueryImplementor query) { if ( Tuple.class.equals( resultClass ) ) { query.setTupleTransformer( new NativeQueryTupleTransformer() ); } @@ -850,7 +855,6 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont else if ( resultClass != Object.class && resultClass != Object[].class ) { query.addResultTypeClass( resultClass ); } - return query; } @Override @@ -1020,7 +1024,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont } } - private NativeQueryImplementor createNativeQueryImplementor(Class resultType, NamedNativeQueryMemento memento) { + protected NativeQueryImplementor createNativeQueryImplementor(Class resultType, NamedNativeQueryMemento memento) { final NativeQueryImplementor query = resultType == null ? memento.toQuery(this ) : memento.toQuery(this, resultType ); @@ -1031,7 +1035,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont return query; } - private SqmQueryImplementor createSqmQueryImplementor(Class resultType, NamedSqmQueryMemento memento) { + protected SqmQueryImplementor createSqmQueryImplementor(Class resultType, NamedSqmQueryMemento memento) { final SqmQueryImplementor query = memento.toQuery( this, resultType ); if ( isEmpty( query.getComment() ) ) { query.setComment( "dynamic query" ); @@ -1078,7 +1082,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont return query; } - private static void checkMutationQuery(String hqlString, SqmStatement sqmStatement) { + protected static void checkMutationQuery(String hqlString, SqmStatement sqmStatement) { if ( !( sqmStatement instanceof SqmDmlStatement ) ) { throw new IllegalMutationQueryException( "Expecting a mutation query, but found `" + hqlString + "`" ); } @@ -1102,7 +1106,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont ); } - private NativeQueryImplementor createNativeQueryImplementor(String queryName, NamedNativeQueryMemento memento) { + protected NativeQueryImplementor createNativeQueryImplementor(String queryName, NamedNativeQueryMemento memento) { final NativeQueryImplementor query = memento.toQuery( this ); final Boolean isUnequivocallySelect = query.isSelectQuery(); if ( isUnequivocallySelect == TRUE ) { @@ -1118,7 +1122,7 @@ public abstract class AbstractSharedSessionContract implements SharedSessionCont return query; } - private SqmQueryImplementor createSqmQueryImplementor(String queryName, NamedSqmQueryMemento memento) { + protected SqmQueryImplementor createSqmQueryImplementor(String queryName, NamedSqmQueryMemento memento) { final SqmQueryImplementor query = memento.toQuery( this ); final SqmStatement sqmStatement = query.getSqmStatement(); if ( !( sqmStatement instanceof SqmDmlStatement ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java index e33d35feaf..adbd824668 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/StatelessSessionImpl.java @@ -23,6 +23,7 @@ import org.hibernate.engine.internal.StatefulPersistenceContext; import org.hibernate.engine.spi.EntityKey; import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.engine.spi.PersistenceContext; +import org.hibernate.engine.spi.PersistentAttributeInterceptable; import org.hibernate.engine.spi.PersistentAttributeInterceptor; import org.hibernate.engine.transaction.internal.jta.JtaStatusHelper; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; @@ -185,9 +186,8 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen public Object get(String entityName, Object id, LockMode lockMode) { checkOpen(); - final EntityPersister entityDescriptor = getEntityPersister( entityName ); - final Object result = entityDescriptor.load( id, null, getNullSafeLockMode( lockMode ), this ); - + final Object result = getEntityPersister( entityName ) + .load( id, null, getNullSafeLockMode( lockMode ), this ); if ( temporaryPersistenceContext.isLoadFinished() ) { temporaryPersistenceContext.clear(); } @@ -291,7 +291,7 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen // first, try to load it from the temp PC associated to this SS final PersistenceContext persistenceContext = getPersistenceContext(); - Object loaded = persistenceContext.getEntity( entityKey ); + final Object loaded = persistenceContext.getEntity( entityKey ); if ( loaded != null ) { // we found it in the temp PC. Should indicate we are in the midst of processing a result set // containing eager fetches via join fetch @@ -305,8 +305,8 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen // first, check to see if we can use "bytecode proxies" final EntityMetamodel entityMetamodel = persister.getEntityMetamodel(); - final BytecodeEnhancementMetadata bytecodeEnhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata(); - if ( bytecodeEnhancementMetadata.isEnhancedForLazyLoading() ) { + final BytecodeEnhancementMetadata enhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata(); + if ( enhancementMetadata.isEnhancedForLazyLoading() ) { // if the entity defines a HibernateProxy factory, see if there is an // existing proxy associated with the PC - and if so, use it @@ -331,10 +331,10 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen LOG.debug( "Creating a HibernateProxy for to-one association with subclasses to honor laziness" ); return createProxy( entityKey ); } - return bytecodeEnhancementMetadata.createEnhancedProxy( entityKey, false, this ); + return enhancementMetadata.createEnhancedProxy( entityKey, false, this ); } else if ( !entityMetamodel.hasSubclasses() ) { - return bytecodeEnhancementMetadata.createEnhancedProxy( entityKey, false, this ); + return enhancementMetadata.createEnhancedProxy( entityKey, false, this ); } // If we get here, then the entity class has subclasses and there is no HibernateProxy factory. // The entity will get loaded below. @@ -374,16 +374,16 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen @Override public void fetch(Object association) { checkOpen(); - PersistenceContext persistenceContext = getPersistenceContext(); + final PersistenceContext persistenceContext = getPersistenceContext(); final LazyInitializer initializer = extractLazyInitializer( association ); if ( initializer != null ) { if ( initializer.isUninitialized() ) { - String entityName = initializer.getEntityName(); - Object id = initializer.getIdentifier(); - initializer.setSession(this); + final String entityName = initializer.getEntityName(); + final Object id = initializer.getIdentifier(); + initializer.setSession( this ); persistenceContext.beforeLoad(); try { - Object entity = initializer.getImplementation(); //forces the load to occur + final Object entity = initializer.getImplementation(); //forces the load to occur if ( entity==null ) { getFactory().getEntityNotFoundDelegate().handleEntityNotFound( entityName, id ); } @@ -399,9 +399,9 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen } } else if ( isPersistentAttributeInterceptable( association ) ) { - final PersistentAttributeInterceptor interceptor = - asPersistentAttributeInterceptable( association ).$$_hibernate_getInterceptor(); - if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor) { + final PersistentAttributeInterceptable interceptable = asPersistentAttributeInterceptable( association ); + final PersistentAttributeInterceptor interceptor = interceptable.$$_hibernate_getInterceptor(); + if ( interceptor instanceof EnhancementAsProxyLazinessInterceptor ) { final EnhancementAsProxyLazinessInterceptor proxyInterceptor = (EnhancementAsProxyLazinessInterceptor) interceptor; proxyInterceptor.setSession( this ); @@ -419,18 +419,16 @@ public class StatelessSessionImpl extends AbstractSharedSessionContract implemen else if ( association instanceof PersistentCollection ) { final PersistentCollection persistentCollection = (PersistentCollection) association; if ( !persistentCollection.wasInitialized() ) { - - final CollectionPersister collectionDescriptor = getFactory().getRuntimeMetamodels() - .getMappingMetamodel() + final CollectionPersister collectionDescriptor = getFactory().getMappingMetamodel() .getCollectionDescriptor( persistentCollection.getRole() ); final Object key = persistentCollection.getKey(); persistenceContext.addUninitializedCollection( collectionDescriptor, persistentCollection, key ); - persistentCollection.setCurrentSession(this); + persistentCollection.setCurrentSession( this ); try { collectionDescriptor.initialize( key, this ); } finally { - persistentCollection.unsetSession(this); + persistentCollection.unsetSession( this ); if ( persistenceContext.isLoadFinished() ) { persistenceContext.clear(); } diff --git a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/SingleIdEntityLoaderProvidedQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/SingleIdEntityLoaderProvidedQueryImpl.java index 4f64be6e8f..73f24328f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/SingleIdEntityLoaderProvidedQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/ast/internal/SingleIdEntityLoaderProvidedQueryImpl.java @@ -62,7 +62,7 @@ public class SingleIdEntityLoaderProvidedQueryImpl implements SingleIdEntityL Boolean readOnly, SharedSessionContractImplementor session) { if ( entityInstance != null ) { - throw new UnsupportedOperationException( ); + throw new UnsupportedOperationException("null entity instance"); } return load( pkValue, lockOptions, readOnly, session ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java index 49089fd979..ec52a8db1f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/internal/NativeQueryImpl.java @@ -861,6 +861,7 @@ public class NativeQueryImpl : null; } + @Override public void addResultTypeClass(Class resultClass) { assert resultSetMapping.getNumberOfResultBuilders() == 0; registerBuilder( Builders.resultClassBuilder( resultClass, getSessionFactory() ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java index 59ced8e699..65afbf6e7d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sql/spi/NativeQueryImplementor.java @@ -315,5 +315,6 @@ public interface NativeQueryImplementor extends QueryImplementor, NativeQu @Override NativeQueryImplementor setProperties(@SuppressWarnings("rawtypes") Map bean); + void addResultTypeClass(Class resultClass); }