unexpose the ServiceRegistry on SqmCreationContext + SqlAstCreationContext

This commit is contained in:
Gavin King 2024-09-10 14:49:36 +02:00
parent 25d0922ff9
commit 0c3b8fd819
9 changed files with 30 additions and 33 deletions

View File

@ -403,4 +403,9 @@ public class SessionFactoryDelegatingImpl implements SessionFactoryImplementor,
public <T> List<EntityGraph<? super T>> findEntityGraphsByType(Class<T> entityClass) {
return delegate.findEntityGraphsByType(entityClass);
}
@Override
public Class<?> classForName(String className) {
return delegate.classForName( className );
}
}

View File

@ -111,7 +111,6 @@ public interface SessionFactoryImplementor
*
* @return The factory's ServiceRegistry
*/
@Override
ServiceRegistryImplementor getServiceRegistry();
/**

View File

@ -458,8 +458,7 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
private static SessionFactoryServiceRegistry getServiceRegistry(
SessionFactoryOptions options,
SessionFactoryImplementor self) {
return options
.getServiceRegistry()
return options.getServiceRegistry()
.requireService( SessionFactoryServiceRegistryFactory.class )
// it is not great how we pass in an instance to
// an incompletely-initialized instance here:
@ -1704,6 +1703,12 @@ public class SessionFactoryImpl extends QueryParameterBindingTypeResolverImpl im
return schemaManager;
}
@Override
public Class<?> classForName(String className) {
return serviceRegistry.requireService( ClassLoaderService.class )
.classForName( className );
}
private enum Status {
OPEN,
CLOSING,

View File

@ -13,7 +13,6 @@ import java.util.List;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.metamodel.model.domain.EntityDomainType;
import org.hibernate.query.criteria.JpaSelection;
@ -69,8 +68,6 @@ public class FullyQualifiedReflectivePathTerminal<E>
private Function<SemanticQueryWalker<?>, ?> resolveTerminalSemantic() {
return semanticQueryWalker -> {
final SqmCreationContext creationContext = creationState.getCreationContext();
final ClassLoaderService cls =
creationContext.getServiceRegistry().requireService( ClassLoaderService.class );
final String fullPath = getFullPath();
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -85,7 +82,7 @@ public class FullyQualifiedReflectivePathTerminal<E>
// See if it is a Class FQN
try {
final Class<?> namedClass = cls.classForName( fullPath );
final Class<?> namedClass = creationContext.classForName( fullPath );
if ( namedClass != null ) {
return semanticQueryWalker.visitFullyQualifiedClass( namedClass );
}
@ -99,7 +96,7 @@ public class FullyQualifiedReflectivePathTerminal<E>
final String parentFullPath = getParent().getFullPath();
try {
final Class<?> namedClass = cls.classForName( parentFullPath );
final Class<?> namedClass = creationContext.classForName( parentFullPath );
if ( namedClass != null ) {
return createEnumOrFieldLiteral( namedClass );
}

View File

@ -32,7 +32,6 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.dialect.function.SqlColumn;
import org.hibernate.grammars.hql.HqlLexer;
@ -1553,17 +1552,12 @@ public class SemanticQueryBuilder<R> extends HqlParserBaseVisitor<Object> implem
}
private JavaType<?> resolveInstantiationTargetJtd(String className) {
final Class<?> targetJavaType = classForName( creationContext.getJpaMetamodel().qualifyImportableName( className ) );
return creationContext.getJpaMetamodel()
.getTypeConfiguration()
.getJavaTypeRegistry()
final String qualifiedName = creationContext.getJpaMetamodel().qualifyImportableName( className );
final Class<?> targetJavaType = creationContext.classForName( qualifiedName );
return creationContext.getTypeConfiguration().getJavaTypeRegistry()
.resolveDescriptor( targetJavaType );
}
private Class<?> classForName(String className) {
return creationContext.getServiceRegistry().requireService( ClassLoaderService.class ).classForName( className );
}
@Override
public SqmDynamicInstantiationArgument<?> visitInstantiationArgument(HqlParser.InstantiationArgumentContext ctx) {
final HqlParser.VariableContext variable = ctx.variable();

View File

@ -10,7 +10,6 @@ import org.hibernate.Incubating;
import org.hibernate.query.BindingContext;
import org.hibernate.query.spi.QueryEngine;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.service.ServiceRegistry;
/**
* The context in which all SQM creations occur.
@ -25,7 +24,10 @@ public interface SqmCreationContext extends BindingContext {
return getQueryEngine().getCriteriaBuilder();
}
default ServiceRegistry getServiceRegistry() {
return getJpaMetamodel().getServiceRegistry();
}
/**
* @apiNote Avoid calling this method, since {@link Class}
* objects are not available to the query validator
* in Hibernate Processor at compilation time.
*/
Class<?> classForName(String className);
}

View File

@ -9,7 +9,6 @@ package org.hibernate.sql.ast.spi;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.query.BindingContext;
import org.hibernate.service.ServiceRegistry;
/**
* The "context" in which creation of SQL AST occurs. Provides
@ -28,11 +27,6 @@ public interface SqlAstCreationContext extends BindingContext {
*/
MappingMetamodelImplementor getMappingMetamodel();
/**
* Access to Services
*/
ServiceRegistry getServiceRegistry();
/**
* When creating {@link org.hibernate.sql.results.graph.Fetch} references,
* defines a limit to how deep we should join for fetches.

View File

@ -15,7 +15,6 @@ import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.model.domain.JpaMetamodel;
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.sql.ast.spi.SqlAstCreationContext;
import org.hibernate.sql.exec.spi.Callback;
@ -92,11 +91,6 @@ public abstract class BaseSqmUnitTest
return sessionFactory().getJpaMetamodel();
}
@Override
public ServiceRegistry getServiceRegistry() {
return sessionFactory().getServiceRegistry();
}
@Override
public Integer getMaximumFetchDepth() {
return sessionFactory().getMaximumFetchDepth();

View File

@ -24,6 +24,7 @@ import org.hibernate.boot.model.relational.Database;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.boot.registry.internal.StandardServiceRegistryImpl;
import org.hibernate.boot.spi.BootstrapContext;
@ -364,6 +365,12 @@ public abstract class MockSessionFactory
return serviceRegistry;
}
@Override
public Class<?> classForName(String className) {
return serviceRegistry.requireService( ClassLoaderService.class )
.classForName( className );
}
@Override
public JdbcServices getJdbcServices() {
return MockJdbcServicesInitiator.jdbcServices;