From f25ed96df63c5d673a9a411a50cf826311c55ea4 Mon Sep 17 00:00:00 2001 From: Steve Ebersole Date: Fri, 24 May 2019 16:49:08 -0500 Subject: [PATCH] 6 - SQM based on JPA type system --- .../hibernate/boot/model/package-info.java | 17 ++++ .../internal/InflightRuntimeMetamodel.java | 56 +++++++++++ .../internal/RuntimeModelCreationProcess.java | 99 +++++++++++++++++++ .../domain/internal/AttributeFactory.java | 2 +- .../domain/internal/DomainMetamodelImpl.java | 34 +------ .../domain/internal/JpaMetamodelImpl.java | 51 ++++++---- .../metamodel/spi/DomainMetamodel.java | 24 ++--- .../metamodel/spi/MetamodelImplementor.java | 4 +- .../hql/internal/SemanticQueryBuilder.java | 26 ++--- .../sqm/produce/spi/SqmCreationContext.java | 4 +- .../sqm/tree/expression/LiteralHelper.java | 12 ++- 11 files changed, 244 insertions(+), 85 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/boot/model/package-info.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/package-info.java b/hibernate-core/src/main/java/org/hibernate/boot/model/package-info.java new file mode 100644 index 0000000000..6caeda0681 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/package-info.java @@ -0,0 +1,17 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * 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 defining Hibernate's boot-time metamodel, which is an + * incrementally built understanding of the application's domain + * model (its entities, attributes, etc). + * + * Ultimately, as part of the process of creating the + * {@link org.hibernate.SessionFactory}, Hibernate will interpret + * this boot metamodel to its runtime metamodel. + */ +package org.hibernate.boot.model; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java new file mode 100644 index 0000000000..711c4c4cb3 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/InflightRuntimeMetamodel.java @@ -0,0 +1,56 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * 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.metamodel.internal; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.hibernate.EntityNameResolver; +import org.hibernate.metamodel.model.domain.EmbeddableDomainType; +import org.hibernate.metamodel.model.domain.EntityDomainType; +import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType; +import org.hibernate.persister.collection.CollectionPersister; +import org.hibernate.persister.entity.EntityPersister; +import org.hibernate.type.spi.TypeConfiguration; + +/** + * @author Steve Ebersole + */ +public class InflightRuntimeMetamodel { + + private final TypeConfiguration typeConfiguration; + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Hibernate metamodel + + private final Map entityPersisterMap = new HashMap<>(); + private Map entityProxyInterfaceMap; + private Map collectionPersisterMap; + private Map> collectionRolesByEntityParticipant; + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // JPA metamodel + + private final Map> jpaEntityTypeMap = new HashMap<>(); + private Map> jpaMappedSuperclassTypeMap; + private Map> embeddableDescriptorMap; + + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // Misc + + private final Map nameToImportNameMap = new HashMap<>(); + private Set entityNameResolvers; + + + public InflightRuntimeMetamodel(TypeConfiguration typeConfiguration) { + this.typeConfiguration = typeConfiguration; + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java new file mode 100644 index 0000000000..4d25b3cf50 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/RuntimeModelCreationProcess.java @@ -0,0 +1,99 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * 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.metamodel.internal; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.boot.spi.BootstrapContext; +import org.hibernate.boot.spi.MetadataBuildingContext; +import org.hibernate.boot.spi.MetadataImplementor; +import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.metamodel.spi.MetamodelImplementor; + +/** + * Responsible for interpreting the Hibernate boot metamodel into + * its runtime metamodel + * + * @see org.hibernate.boot.model + * @see org.hibernate.metamodel + * + * @author Steve Ebersole + */ +public class RuntimeModelCreationProcess { + + // todo (6.0) : look at removing reliance on SessionFactory here as well. Just pass in what we need. + // See RuntimeModelCreationContext. Ultimately we will need SessionFactory to create the persisters + // + // todo (6.0) : ^^ A running list of what we use from SessionFactory: + // - ServiceRegistry + // - Properties + // - Cache (to prime, so we could use a functional interface) + // - Database dropping support for auto-schema-tooling (again, could be functional interface - in fact if ultimately is in terms of how we do that) + // - Creation of named entity-graphs + // - Access to IdentifierGenerators, though we could manage this as part of the DomainMetamodel (and logically maybe that is where it belongs) + // - SessionFactoryOptions + // - BytecodeProvider + // - JpaCompliance + // + // Ultimately the idea here is to build the `InflightRuntimeMetamodel` and pass that along to + // the JpaMetamodel and DomainMetamodel. At a high-level; the details may be to instead + // build the `InflightRuntimeMetamodel` and use the collected information individually to + // each - e.g.: + // ```` + // new JpaMetamodel( + // inflightRuntimeMetamodel.getJpaEntityTypes(), + // inflightRuntimeMetamodel.getJpaEmbeddableTypes, + // ... + // ); + // ```` + // + // ^^ Possibly account for either, e.g.: + // ```` + // class JpaMetamodelImpl implements JpaMetamodel { + // static JpaMetamodelImpl create( + // InflightRuntimeMetamodel inflightRuntimeMetamodel, + // ... ) { + // return new JpaMetamodel( + // inflightRuntimeMetamodel.getJpaEntityTypes(), + // inflightRuntimeMetamodel.getJpaEmbeddableTypes, + // ... + // ); + // } + // } + // ```` + + + /** + * Perform the runtime metamodel creation based on the information obtained during + * the first phase of booting, returning the + */ + public static MetamodelImplementor execute( + SessionFactoryImplementor sessionFactory, + BootstrapContext bootstrapContext, + MetadataBuildingContext metadataBuildingContext, + MetadataImplementor bootMetamodel) { + return new RuntimeModelCreationProcess( sessionFactory, bootstrapContext, metadataBuildingContext ).execute(); + } + + private final SessionFactoryImplementor sessionFactory; + private final BootstrapContext bootstrapContext; + private final MetadataBuildingContext metadataBuildingContext; + + public RuntimeModelCreationProcess( + SessionFactoryImplementor sessionFactory, + BootstrapContext bootstrapContext, + MetadataBuildingContext metadataBuildingContext) { + this.sessionFactory = sessionFactory; + this.bootstrapContext = bootstrapContext; + this.metadataBuildingContext = metadataBuildingContext; + } + + + public MetamodelImplementor execute() { + final InflightRuntimeMetamodel inflightRuntimeMetamodel = new InflightRuntimeMetamodel( bootstrapContext.getTypeConfiguration() ); + throw new NotYetImplementedFor6Exception(); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AttributeFactory.java index 4eb6efccea..7311537018 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AttributeFactory.java @@ -302,7 +302,7 @@ public class AttributeFactory { PersistentClass persistentClass = context.getPersistentClassHostingProperties( (MappedSuperclassTypeImpl) ownerType ); return context.getMetamodel() - .resolveEntityPersister( persistentClass.getClassName() ) + .findEntityDescriptor( persistentClass.getClassName() ) .getEntityMetamodel(); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java index 06138cfb99..75289ac81c 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/DomainMetamodelImpl.java @@ -91,7 +91,6 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento // private final Map, MappedSuperclassType> jpaMappedSuperclassTypeMap = new ConcurrentHashMap<>(); // private final Set> jpaEmbeddableTypes = new CopyOnWriteArraySet<>(); private final Map entityProxyInterfaceMap = new ConcurrentHashMap<>(); - private final Map imports = new ConcurrentHashMap<>(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -160,7 +159,6 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento public void initialize( MetadataImplementor mappingMetadata, JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting) { - this.imports.putAll( mappingMetadata.getImports() ); primeSecondLevelCacheRegions( mappingMetadata ); @@ -405,7 +403,7 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento } @Override - public EntityPersister resolveEntityPersister(Object entity) { + public EntityPersister determineEntityPersister(Object entity) { return findEntityDescriptor(entity.getClass()); } @@ -511,32 +509,6 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento return getJpaMetamodel().entity( entityName ); } - @Override - public String getImportedClassName(String className) { - String result = imports.get( className ); - if ( result == null ) { - try { - sessionFactory.getServiceRegistry().getService( ClassLoaderService.class ).classForName( className ); - imports.put( className, className ); - return className; - } - catch (ClassLoadingException cnfe) { - imports.put( className, INVALID_IMPORT ); - return null; - } - } - else { - // explicitly check for same instance - //noinspection StringEquality - if ( result == INVALID_IMPORT ) { - return null; - } - else { - return result; - } - } - } - @Override public String[] getImplementors(String className) throws MappingException { // computeIfAbsent() can be a contention point and we expect all the values to be in the map at some point so @@ -606,10 +578,6 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento return entityPersister; } - public String getImportedName(String name){ - return imports.get( name ); - } - @Override public void visitCollectionDescriptors(Consumer action){ collectionPersisterMap.values().forEach( action ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java index 8f83060998..eddfe2045d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java @@ -65,17 +65,17 @@ public class JpaMetamodelImpl implements JpaMetamodel { private final Map> entityDescriptorMap = new ConcurrentHashMap<>(); private final Map> strictEntityDescriptorMap = new ConcurrentHashMap<>(); + private final Map, MappedSuperclassType> mappedSuperclassTypeMap = new ConcurrentHashMap<>(); private final Map> embeddableDescriptorMap = new ConcurrentHashMap<>(); - private final Set> embeddableDescriptors = new CopyOnWriteArraySet<>(); - - private final Map> polymorphicEntityReferenceMap = new ConcurrentHashMap<>(); private final Map nameToImportNameMap = new ConcurrentHashMap<>(); private final transient Map entityGraphMap = new ConcurrentHashMap<>(); + private final Map> polymorphicEntityReferenceMap = new ConcurrentHashMap<>(); + public JpaMetamodelImpl(TypeConfiguration typeConfiguration) { this.typeConfiguration = typeConfiguration; } @@ -85,8 +85,7 @@ public class JpaMetamodelImpl implements JpaMetamodel { MetadataImplementor mappingMetadata, SqmCriteriaNodeBuilder criteriaBuilder, JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting, - JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting - ) { + JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) { if ( jpaMetaModelPopulationSetting != JpaMetaModelPopulationSetting.DISABLED ) { MetadataContext context = new MetadataContext( metamodel, @@ -104,14 +103,16 @@ public class JpaMetamodelImpl implements JpaMetamodel { context.wrapUp(); - strictEntityDescriptorMap.putAll( context.getEntityTypeMap() ); - this.embeddableDescriptors.addAll( context.getEmbeddableTypeSet() ); - for ( EmbeddableDomainType embeddable : embeddableDescriptors ) { - this.embeddableDescriptorMap.put( embeddable.getJavaType(), embeddable ); - } + this.nameToImportNameMap.putAll( mappingMetadata.getImports() ); + + this.strictEntityDescriptorMap.putAll( context.getEntityTypeMap() ); this.entityDescriptorMap.putAll( context.getEntityTypesByEntityName() ); this.mappedSuperclassTypeMap.putAll( context.getMappedSuperclassTypeMap() ); + for ( EmbeddableDomainType embeddable : context.getEmbeddableTypeSet() ) { + this.embeddableDescriptorMap.put( embeddable.getJavaType(), embeddable ); + } + applyNamedEntityGraphs( mappingMetadata.getNamedEntityGraphs().values() ); } } @@ -297,6 +298,7 @@ public class JpaMetamodelImpl implements JpaMetamodel { @Override public EntityDomainType entity(String entityName) { + //noinspection unchecked return (EntityDomainType) entityDescriptorMap.get( entityName ); } @@ -321,6 +323,7 @@ public class JpaMetamodelImpl implements JpaMetamodel { } @Override + @SuppressWarnings("unchecked") public void visitManagedTypes(Consumer> action) { visitEntityTypes( (Consumer) action ); visitEmbeddables( (Consumer) action ); @@ -334,16 +337,18 @@ public class JpaMetamodelImpl implements JpaMetamodel { @Override public void visitRootEntityTypes(Consumer> action) { - entityDescriptorMap.values().forEach( entityDomainType -> { - if ( entityDomainType.getSuperType() == null ) { - action.accept( entityDomainType ); - } - } ); + entityDescriptorMap.values().forEach( + entityDomainType -> { + if ( entityDomainType.getSuperType() == null ) { + action.accept( entityDomainType ); + } + } + ); } @Override public void visitEmbeddables(Consumer> action) { - embeddableDescriptors.forEach( action ); + embeddableDescriptorMap.values().forEach( action ); } @Override @@ -358,6 +363,7 @@ public class JpaMetamodelImpl implements JpaMetamodel { if ( type == null ) { throw new IllegalArgumentException( "Not a managed type: " + cls ); } + //noinspection unchecked return (ManagedDomainType) type; } @@ -367,6 +373,7 @@ public class JpaMetamodelImpl implements JpaMetamodel { if ( entityType == null ) { throw new IllegalArgumentException( "Not an entity: " + cls ); } + //noinspection unchecked return (EntityDomainType) entityType; } @@ -376,18 +383,19 @@ public class JpaMetamodelImpl implements JpaMetamodel { if ( embeddableType == null ) { throw new IllegalArgumentException( "Not an embeddable: " + cls ); } + //noinspection unchecked return (EmbeddableDomainType) embeddableType; } @Override public Set> getManagedTypes() { final int setSize = CollectionHelper.determineProperSizing( - entityDescriptorMap.size() + mappedSuperclassTypeMap.size() + embeddableDescriptors.size() + entityDescriptorMap.size() + mappedSuperclassTypeMap.size() + embeddableDescriptorMap.size() ); final Set> managedTypes = new HashSet<>( setSize ); managedTypes.addAll( entityDescriptorMap.values() ); managedTypes.addAll( mappedSuperclassTypeMap.values() ); - managedTypes.addAll( embeddableDescriptors ); + managedTypes.addAll( embeddableDescriptorMap.values() ); return managedTypes; } @@ -398,7 +406,7 @@ public class JpaMetamodelImpl implements JpaMetamodel { @Override public Set> getEmbeddables() { - return new HashSet<>( embeddableDescriptors ); + return new HashSet<>( embeddableDescriptorMap.values() ); } @Override @@ -415,6 +423,7 @@ public class JpaMetamodelImpl implements JpaMetamodel { @Override public RootGraphImplementor findEntityGraphByName(String name) { + //noinspection unchecked return entityGraphMap.get( name ); } @@ -428,12 +437,14 @@ public class JpaMetamodelImpl implements JpaMetamodel { final List> results = new ArrayList<>(); for ( EntityGraph entityGraph : entityGraphMap.values() ) { - if ( !RootGraphImplementor.class.isInstance( entityGraph ) ) { + if ( !(entityGraph instanceof RootGraphImplementor) ) { continue; } final RootGraphImplementor egi = (RootGraphImplementor) entityGraph; + //noinspection unchecked if ( egi.appliesTo( entityType ) ) { + //noinspection unchecked results.add( egi ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/DomainMetamodel.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/DomainMetamodel.java index 48fda9f45e..c77a466d58 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/DomainMetamodel.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/DomainMetamodel.java @@ -24,31 +24,33 @@ import org.hibernate.type.spi.TypeConfiguration; * @author Steve Ebersole */ public interface DomainMetamodel { - TypeConfiguration getTypeConfiguration(); JpaMetamodel getJpaMetamodel(); - default EntityPersister resolveEntityPersister(EntityDomainType domainType) { - return findEntityDescriptor( domainType.getHibernateEntityName() ); + default TypeConfiguration getTypeConfiguration() { + return getJpaMetamodel().getTypeConfiguration(); } - EntityPersister resolveEntityPersister(Object entity); + /** + * Given an (assumed) entity instance, determine its descriptor + * + * @see org.hibernate.EntityNameResolver + */ + EntityPersister determineEntityPersister(Object entity); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Entity descriptors - /** - * Given a JPA entity domain type, get the associated Hibernate entity descriptor - */ - default EntityPersister resolveEntityDescriptor(EntityDomainType entityDomainType){ - return resolveEntityPersister( entityDomainType ); - } - /** * Visit all entity mapping descriptors defined in the model */ void visitEntityDescriptors(Consumer action); + /** + * Given a JPA entity domain type, get the associated Hibernate entity descriptor + */ + EntityPersister resolveEntityDescriptor(EntityDomainType entityDomainType); + /** * Get an entity mapping descriptor based on its Hibernate entity-name * diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java index beac971f92..6e7a91e52d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/MetamodelImplementor.java @@ -28,9 +28,11 @@ import org.hibernate.type.spi.TypeConfiguration; * Hibernate extension to the JPA {@link Metamodel} contract * * @author Steve Ebersole + * + * @deprecated (since 6.0) - Prefer {@link org.hibernate.metamodel.spi.DomainMetamodel} */ @Deprecated -public interface MetamodelImplementor extends Metamodel { +public interface MetamodelImplementor extends DomainMetamodel, Metamodel { /** * Access to the TypeConfiguration in effect for this SessionFactory/Metamodel * diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java index fadcec9664..09f34d1339 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java @@ -592,7 +592,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre if ( ctx.dynamicInstantiationTarget().MAP() != null ) { if ( mapJavaTypeDescriptor == null ) { - mapJavaTypeDescriptor = creationContext.getDomainModel() + mapJavaTypeDescriptor = creationContext.getJpaMetamodel() .getTypeConfiguration() .getJavaTypeDescriptorRegistry() .getDescriptor( Map.class ); @@ -604,7 +604,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre } else if ( ctx.dynamicInstantiationTarget().LIST() != null ) { if ( listJavaTypeDescriptor == null ) { - listJavaTypeDescriptor = creationContext.getDomainModel() + listJavaTypeDescriptor = creationContext.getJpaMetamodel() .getTypeConfiguration() .getJavaTypeDescriptorRegistry() .getDescriptor( List.class ); @@ -618,7 +618,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre final String className = ctx.dynamicInstantiationTarget().dotIdentifierSequence().getText(); try { final Class targetJavaType = classForName( className ); - final JavaTypeDescriptor jtd = creationContext.getDomainModel() + final JavaTypeDescriptor jtd = creationContext.getJpaMetamodel() .getTypeConfiguration() .getJavaTypeDescriptorRegistry() .resolveDescriptor( targetJavaType ); @@ -836,7 +836,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre log.debugf( "Attempting to resolve path [%s] as entity reference...", entityName ); EntityDomainType reference = null; try { - reference = creationContext.getDomainModel().entity( entityName ); + reference = creationContext.getJpaMetamodel().entity( entityName ); } catch (Exception ignore) { } @@ -889,7 +889,9 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre log.debugf( "Handling root path - %s", name ); - final EntityDomainType entityDescriptor = getCreationContext().getDomainModel().resolveHqlEntityReference( name ); + final EntityDomainType entityDescriptor = getCreationContext().getJpaMetamodel().resolveHqlEntityReference( + name + ); if ( entityDescriptor instanceof SqmPolymorphicRootDescriptor ) { if ( getCreationOptions().useStrictJpaCompliance() ) { @@ -965,7 +967,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre SqmTreeCreationLogger.LOGGER.debugf( "Handling root path - %s", name ); - final EntityDomainType entityDescriptor = getCreationContext().getDomainModel().resolveHqlEntityReference( name ); + final EntityDomainType entityDescriptor = getCreationContext().getJpaMetamodel().resolveHqlEntityReference( name ); if ( entityDescriptor instanceof SqmPolymorphicRootDescriptor ) { throw new SemanticException( "Unmapped polymorphic reference cannot be used as a CROSS JOIN target" ); @@ -1339,7 +1341,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre BinaryArithmeticOperator.ADD, (SqmExpression) ctx.expression( 0 ).accept( this ), (SqmExpression) ctx.expression( 1 ).accept( this ), - creationContext.getDomainModel(), + creationContext.getJpaMetamodel(), creationContext.getNodeBuilder() ); } @@ -1354,7 +1356,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre BinaryArithmeticOperator.SUBTRACT, (SqmExpression) ctx.expression( 0 ).accept( this ), (SqmExpression) ctx.expression( 1 ).accept( this ), - creationContext.getDomainModel(), + creationContext.getJpaMetamodel(), creationContext.getNodeBuilder() ); } @@ -1369,7 +1371,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre BinaryArithmeticOperator.MULTIPLY, (SqmExpression) ctx.expression( 0 ).accept( this ), (SqmExpression) ctx.expression( 1 ).accept( this ), - creationContext.getDomainModel(), + creationContext.getJpaMetamodel(), creationContext.getNodeBuilder() ); } @@ -1385,7 +1387,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre BinaryArithmeticOperator.DIVIDE, (SqmExpression) ctx.expression( 0 ).accept( this ), (SqmExpression) ctx.expression( 1 ).accept( this ), - creationContext.getDomainModel(), + creationContext.getJpaMetamodel(), creationContext.getNodeBuilder() ); } @@ -1790,7 +1792,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre private BasicDomainType resolveExpressableTypeBasic(Class javaType) { //noinspection unchecked - return creationContext.getDomainModel().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); + return creationContext.getJpaMetamodel().getTypeConfiguration().standardBasicTypeForJavaType( javaType ); } @Override @@ -2736,7 +2738,7 @@ public class SemanticQueryBuilder extends HqlParserBaseVisitor implements SqmCre public SqmPath visitTreatedNavigablePath(HqlParser.TreatedNavigablePathContext ctx) { final SqmPath sqmPath = consumeManagedTypeReference( ctx.path() ); final String treatTargetName = ctx.dotIdentifierSequence().getText(); - final EntityDomainType treatTarget = getCreationContext().getDomainModel().entity( treatTargetName ); + final EntityDomainType treatTarget = getCreationContext().getJpaMetamodel().entity( treatTargetName ); SqmPath result = resolveTreatedPath( sqmPath, treatTarget ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/spi/SqmCreationContext.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/spi/SqmCreationContext.java index 468943dd98..476a278d4c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/spi/SqmCreationContext.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/produce/spi/SqmCreationContext.java @@ -22,13 +22,13 @@ public interface SqmCreationContext { /** * Access to the domain model metadata */ - JpaMetamodel getDomainModel(); + JpaMetamodel getJpaMetamodel(); /** * Access to the ServiceRegistry for the context */ default ServiceRegistry getServiceRegistry() { - return getDomainModel().getServiceRegistry(); + return getJpaMetamodel().getServiceRegistry(); } QueryEngine getQueryEngine(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/LiteralHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/LiteralHelper.java index 281983d04c..8f3ecdc972 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/LiteralHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/LiteralHelper.java @@ -15,6 +15,8 @@ import java.time.LocalTime; import org.hibernate.query.spi.QueryEngine; import org.hibernate.query.sqm.produce.spi.SqmCreationState; +import org.hibernate.type.StandardBasicTypes; +import org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor; /** * @author Steve Ebersole @@ -22,12 +24,12 @@ import org.hibernate.query.sqm.produce.spi.SqmCreationState; public class LiteralHelper { public static SqmLiteral timestampLiteralFrom(String literalText, SqmCreationState creationState) { final Timestamp literal = Timestamp.valueOf( - LocalDateTime.from( JdbcTimestampJavaDescriptor.FORMATTER.parse( literalText ) ) + LocalDateTime.from( JdbcTimestampTypeDescriptor.FORMATTER.parse( literalText ) ) ); return new SqmLiteral<>( literal, - creationState.getCreationContext().getDomainModel().getTypeConfiguration().getBasicTypeRegistry().getBasicType( Timestamp.class ), + creationState.getCreationContext().getJpaMetamodel().getTypeConfiguration().standardBasicTypeForJavaType( Timestamp.class ), creationState.getCreationContext().getQueryEngine().getCriteriaBuilder() ); } @@ -43,7 +45,7 @@ public class LiteralHelper { public static SqmLiteral integerLiteral(int value, QueryEngine queryEngine) { return new SqmLiteral<>( value, - StandardSpiBasicTypes.INTEGER, + StandardBasicTypes.INTEGER, queryEngine.getCriteriaBuilder() ); } @@ -54,7 +56,7 @@ public class LiteralHelper { return new SqmLiteral<>( literal, - creationState.getCreationContext().getDomainModel().getTypeConfiguration().getBasicTypeRegistry().getBasicType( Date.class ), + creationState.getCreationContext().getJpaMetamodel().getTypeConfiguration().getBasicTypeRegistry().getBasicType( Date.class ), creationState.getCreationContext().getQueryEngine().getCriteriaBuilder() ); } @@ -65,7 +67,7 @@ public class LiteralHelper { return new SqmLiteral<>( literal, - creationState.getCreationContext().getDomainModel().getTypeConfiguration().getBasicTypeRegistry().getBasicType( Time.class ), + creationState.getCreationContext().getJpaMetamodel().getTypeConfiguration().getBasicTypeRegistry().getBasicType( Time.class ), creationState.getCreationContext().getQueryEngine().getCriteriaBuilder() ); }