diff --git a/design/6-type-system-new-old.adoc b/design/6-type-system-new-old.adoc deleted file mode 100644 index f76a72438d..0000000000 --- a/design/6-type-system-new-old.adoc +++ /dev/null @@ -1,149 +0,0 @@ -= Type System - -The Hibernate "type system" is multi-layered.... - - -== JavaTypeDescriptor - -At the lowest level we have `JavaTypeDescriptor` which describes information about Java types -(`Class`). This level makes no distinctions based about the nature of the type. E.g. it does -not understand that `Person` is an entity. - - -== Domain type system (JPA/SQM) - -The JPA type system is an "unmapped" model, meaning that it has no mapping information - -no references to tables, columns, etc. The base contract for Hibernate's extension to the -JPA model is `org.hibernate.metamodel.model.domain.DomainType`. - -Hibernate's Semantic Query Model (SQM) is defined in terms of these JPA type extensions, -through the `org.hibernate.query.sqm.SqmExpressable` contract allowing parts of the application's -domain model to be used as part of an SQM tree. - - -[plantuml,SqmTypeSystem,png] -.Domain (JPA/SQM) type system -.... -@startuml -skinparam handwritten true - -interface DomainType -interface SimpleDomainType -interface BasicDomainType -interface AnyMappingDomainType -interface ManagedDomainType -interface EmbeddableDomainType -interface IdentifiableDomainType -interface EntityDomainType -interface MappedSuperclassDomainType - -interface SqmExpressable -interface SqmPathSource -interface PersistentAttribute -interface SingularPersistentAttribute -interface PluralPersistentAttribute - -DomainType <|-- SimpleDomainType -SimpleDomainType <|-- BasicDomainType -SimpleDomainType <|-- AnyMappingDomainType -SimpleDomainType <|-- ManagedDomainType -ManagedDomainType <|-- EmbeddableDomainType -ManagedDomainType <|-- IdentifiableDomainType -IdentifiableDomainType <|-- MappedSuperclassDomainType -IdentifiableDomainType <|-- EntityDomainType - -SqmExpressable <|-- DomainType -SqmExpressable <|-- SqmPathSource - -SqmPathSource <|-- EntityDomainType -SqmPathSource <|-- PersistentAttribute - -PersistentAttribute <|-- SingularPersistentAttribute -PersistentAttribute <|-- PluralPersistentAttribute - -@enduml -.... - - - -== Mapping model - -TBC... - -[plantuml,SqmTypeSystem,png] -.Mapping type system -.... -@startuml -skinparam handwritten true - -interface ValueMapping -interface BasicType -interface ModelPart -interface ModelPartContainer - -ValueMapping <|-- BasicType -ValueMapping <|-- ModelPart -ModelPartContainer <|-- EntityMapping -ModelPartContainer <|-- EmbeddableMapping -ModelPart <|-- EmbeddableMapping -ModelPart <|-- AttributeMapping -ModelPart <|-- EntityIdentifierMapping -ModelPart <|-- EntityVersionMapping -ModelPart <|-- EntityDiscriminatorMapping - - -@enduml -.... - -[source,JAVA] ----- -interface ValueMapping { - Type getMappingType(); - X getCapability(Class capabilityType); - ... -} - -interface ModelPart extends ValueMapping { - DomainResult createDomainResult(...); - void applySqlSelections(...); - ... -} - -interface ModelPartContainer extends ValueMapping { - void visitSubMappings(Consumer action); - ModelPart findSubPart(String name); - ModelPart resolveSubPart(String path); -} - -interface EntityMapping extends ModelPartContainer { - default EntityPersister getEntityPersister() { - return getCapability( EntityPersister.class ); - } - - default EntityIdentifierMapping getIdentifierMapping() { - return getCapability( EntityIdentifierMapping.class ); - } - - default EntityVersionMapping getVersionMapping() { - return getCapability( EntityVersionMapping.class ); - } - - default EntityDiscriminatorMapping getDiscriminatorMapping() { - return getCapability( EntityDiscriminatorMapping.class ); - } - - ... -} - -interface EmbeddableMapping extends ModelPart, ModelPartContainer { - ... -} ----- - - -`org.hibernate.metamodel.model.mapping` contract corollaries in `org.hibernate.persister.walking`: - -EntityMapping::EntityDefinition -EmbeddableMapping::CompositionDefinition -AttributeMapping::AttributeDefinition -EntityIdentifierMapping::EntityIdentifierDefinition diff --git a/design/type-system-domain.adoc b/design/type-system-domain.adoc new file mode 100644 index 0000000000..5550696a8c --- /dev/null +++ b/design/type-system-domain.adoc @@ -0,0 +1,53 @@ += Domain type system (JPA/SQM) + +The JPA type system is an "unmapped" model, meaning that it has no mapping information - +no references to tables, columns, etc. The base contract for Hibernate's extension to the +JPA model is `org.hibernate.metamodel.model.domain.DomainType`. + +Hibernate's Semantic Query Model (SQM) is defined in terms of these JPA type extensions, +through the `org.hibernate.query.sqm.SqmExpressable` contract allowing parts of the application's +domain model to be used as part of an SQM tree. + + +[plantuml,SqmTypeSystem,png] +.Domain (JPA/SQM) type system +.... +@startuml +skinparam handwritten true + +interface DomainType +interface SimpleDomainType +interface BasicDomainType +interface AnyMappingDomainType +interface ManagedDomainType +interface EmbeddableDomainType +interface IdentifiableDomainType +interface EntityDomainType +interface MappedSuperclassDomainType + +interface SqmExpressable +interface SqmPathSource +interface PersistentAttribute +interface SingularPersistentAttribute +interface PluralPersistentAttribute + +DomainType <|-- SimpleDomainType +SimpleDomainType <|-- BasicDomainType +SimpleDomainType <|-- AnyMappingDomainType +SimpleDomainType <|-- ManagedDomainType +ManagedDomainType <|-- EmbeddableDomainType +ManagedDomainType <|-- IdentifiableDomainType +IdentifiableDomainType <|-- MappedSuperclassDomainType +IdentifiableDomainType <|-- EntityDomainType + +SqmExpressable <|-- DomainType +SqmExpressable <|-- SqmPathSource + +SqmPathSource <|-- EntityDomainType +SqmPathSource <|-- PersistentAttribute + +PersistentAttribute <|-- SingularPersistentAttribute +PersistentAttribute <|-- PluralPersistentAttribute + +@enduml +.... diff --git a/design/type-system-mapping.adoc b/design/type-system-mapping.adoc new file mode 100644 index 0000000000..3c3fc2d648 --- /dev/null +++ b/design/type-system-mapping.adoc @@ -0,0 +1,95 @@ += Mapping model + +[plantuml,SqmTypeSystem,png] +.Mapping type system +.... +@startuml +skinparam handwritten true + +interface MappingType + +interface ValueMapping +interface BasicType +interface ModelPart +interface ModelPartContainer + +MappingType <|-- + +ValueMapping <|-- BasicType +ValueMapping <|-- ModelPart +ModelPartContainer <|-- EntityMapping +ModelPartContainer <|-- EmbeddableMapping +ModelPart <|-- EmbeddableMapping +ModelPart <|-- AttributeMapping +ModelPart <|-- EntityIdentifierMapping +ModelPart <|-- EntityVersionMapping +ModelPart <|-- EntityDiscriminatorMapping + + +@enduml +.... + +[source,JAVA] +---- +interface ValueMapping { + Type getMappingType(); + X getCapability(Class capabilityType); + ... +} + +interface ModelPart extends ValueMapping { + DomainResult createDomainResult(...); + void applySqlSelections(...); + ... +} + +interface ModelPartContainer extends ValueMapping { + void visitSubMappings(Consumer action); + ModelPart findSubPart(String name); + ModelPart resolveSubPart(String path); +} + +interface EntityMapping extends ModelPartContainer { + default EntityPersister getEntityPersister() { + return getCapability( EntityPersister.class ); + } + + default EntityIdentifierMapping getIdentifierMapping() { + return getCapability( EntityIdentifierMapping.class ); + } + + default EntityVersionMapping getVersionMapping() { + return getCapability( EntityVersionMapping.class ); + } + + default EntityDiscriminatorMapping getDiscriminatorMapping() { + return getCapability( EntityDiscriminatorMapping.class ); + } + + ... +} + +interface EmbeddableMapping extends ModelPart, ModelPartContainer { + ... +} +---- + + +== Relationship with legacy "persister walking" SPI + +`org.hibernate.metamodel.model.mapping` contract corollaries in `org.hibernate.persister.walking`: + +EntityMapping::EntityDefinition +EmbeddableMapping::CompositionDefinition +AttributeMapping::AttributeDefinition +EntityIdentifierMapping::EntityIdentifierDefinition + + +== AllowableParameterType + +`AllowableParameterType` is a contract that defines types that are valid for parameter binding in terms of an SQM query. + +AT some point this needs to be "resolved" to a ValueMapping/Type/Bindable when generating the SQL AST and executing. + +One option is to have the `AllowableParameterType` be resolved first to a `SqmExpressable` +`SqmExpressableAllowableParameterType#resolveSqmExpressable` \ No newline at end of file diff --git a/hibernate-core/src/main/java/org/hibernate/loader/spi/Loadable.java b/hibernate-core/src/main/java/org/hibernate/loader/spi/Loadable.java index 98f8f6e465..1b93dd194d 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/spi/Loadable.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/spi/Loadable.java @@ -9,7 +9,7 @@ package org.hibernate.loader.spi; import org.hibernate.LockMode; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.LoadQueryInfluencers; -import org.hibernate.metamodel.model.mapping.spi.ModelPart; +import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.query.NavigablePath; import org.hibernate.sql.ast.JoinType; import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java index 22dd0b9177..b2e4963577 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/AttributeFactory.java @@ -117,7 +117,8 @@ public class AttributeFactory { attributeMetadata.getMember(), false, false, - property.isOptional() + property.isOptional(), + metadataContext ); } @@ -159,7 +160,8 @@ public class AttributeFactory { property.getName(), determineSimpleType( attributeMetadata.getValueContext() ), attributeMetadata.getMember(), - attributeMetadata.getAttributeClassification() + attributeMetadata.getAttributeClassification(), + context ); } @@ -189,7 +191,8 @@ public class AttributeFactory { property.getName(), attributeMetadata.getAttributeClassification(), determineSimpleType( attributeMetadata.getValueContext() ), - attributeMetadata.getMember() + attributeMetadata.getMember(), + context ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index c7bebd2dfd..ff5a3c3caa 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -26,6 +26,8 @@ import org.hibernate.internal.EntityManagerMessageLogger; import org.hibernate.internal.HEMLogging; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.collections.CollectionHelper; +import org.hibernate.internal.util.collections.Stack; +import org.hibernate.internal.util.collections.StandardStack; import org.hibernate.mapping.Component; import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.MappedSuperclass; @@ -96,6 +98,8 @@ public class MetadataContext { private List stackOfPersistentClassesBeingProcessed = new ArrayList<>(); private DomainMetamodel metamodel; + private Stack containerRoleStack = new StandardStack<>(); + public MetadataContext( JpaMetamodel jpaMetamodel, RuntimeModelCreationContext runtimeModelCreationContext, @@ -129,6 +133,10 @@ public class MetadataContext { return metamodel; } + public Stack getContainerRoleStack() { + return containerRoleStack; + } + /** * Retrieves the {@linkplain Class java type} to {@link EntityTypeImpl} map. * @@ -249,29 +257,39 @@ public class MetadataContext { try { final EntityDomainType jpaMapping = entityTypesByPersistentClass.get( safeMapping ); - applyIdMetadata( safeMapping, jpaMapping ); - applyVersionAttribute( safeMapping, jpaMapping ); + containerRoleStack.push( jpaMapping.getMappingRole() ); - Iterator properties = safeMapping.getDeclaredPropertyIterator(); - while ( properties.hasNext() ) { - final Property property = properties.next(); - if ( property.getValue() == safeMapping.getIdentifierMapper() ) { - // property represents special handling for id-class mappings but we have already - // accounted for the embedded property mappings in #applyIdMetadata && - // #buildIdClassAttributes - continue; - } - if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) { - // skip the version property, it was already handled previously. - continue; - } - final PersistentAttribute attribute = attributeFactory.buildAttribute( jpaMapping, property ); - if ( attribute != null ) { - ( (AttributeContainer) jpaMapping ).getInFlightAccess().addAttribute( attribute ); + try { + applyIdMetadata( safeMapping, jpaMapping ); + applyVersionAttribute( safeMapping, jpaMapping ); + + Iterator properties = safeMapping.getDeclaredPropertyIterator(); + while ( properties.hasNext() ) { + final Property property = properties.next(); + if ( property.getValue() == safeMapping.getIdentifierMapper() ) { + // property represents special handling for id-class mappings but we have already + // accounted for the embedded property mappings in #applyIdMetadata && + // #buildIdClassAttributes + continue; + } + if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) { + // skip the version property, it was already handled previously. + continue; + } + final PersistentAttribute attribute = attributeFactory.buildAttribute( + jpaMapping, + property + ); + if ( attribute != null ) { + ( (AttributeContainer) jpaMapping ).getInFlightAccess().addAttribute( attribute ); + } } + + ( (AttributeContainer) jpaMapping ).getInFlightAccess().finishUp(); + } + finally { + containerRoleStack.pop(); } - - ( ( AttributeContainer) jpaMapping ).getInFlightAccess().finishUp(); if ( staticMetamodelScanEnabled ) { populateStaticMetamodel( jpaMapping ); @@ -291,22 +309,31 @@ public class MetadataContext { try { final MappedSuperclassDomainType jpaType = mappedSuperclassByMappedSuperclassMapping.get( safeMapping ); - applyIdMetadata( safeMapping, jpaType ); - applyVersionAttribute( safeMapping, jpaType ); + containerRoleStack.push( jpaType.getTypeName() ); - Iterator properties = safeMapping.getDeclaredPropertyIterator(); - while ( properties.hasNext() ) { - final Property property = properties.next(); - if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) { - // skip the version property, it was already handled previously. - continue; - } - final PersistentAttribute attribute = attributeFactory.buildAttribute( jpaType, property ); - if ( attribute != null ) { - ( ( AttributeContainer) jpaType ).getInFlightAccess().addAttribute( attribute ); + try { + + applyIdMetadata( safeMapping, jpaType ); + applyVersionAttribute( safeMapping, jpaType ); + + Iterator properties = safeMapping.getDeclaredPropertyIterator(); + while ( properties.hasNext() ) { + final Property property = properties.next(); + if ( safeMapping.isVersioned() && property == safeMapping.getVersion() ) { + // skip the version property, it was already handled previously. + continue; + } + final PersistentAttribute attribute = attributeFactory.buildAttribute( jpaType, property ); + if ( attribute != null ) { + ( (AttributeContainer) jpaType ).getInFlightAccess().addAttribute( attribute ); + } } + + ( (AttributeContainer) jpaType ).getInFlightAccess().finishUp(); + } + finally { + containerRoleStack.pop(); } - ( ( AttributeContainer) jpaType ).getInFlightAccess().finishUp(); if ( staticMetamodelScanEnabled ) { populateStaticMetamodel( jpaType ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/Bindable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/Bindable.java similarity index 98% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/Bindable.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/mapping/Bindable.java index 69559206d5..dab5adcf39 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/Bindable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/Bindable.java @@ -4,7 +4,7 @@ * 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.model.mapping.spi; +package org.hibernate.metamodel.mapping; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelExpressable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelExpressable.java new file mode 100644 index 0000000000..bbac20f582 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingModelExpressable.java @@ -0,0 +1,38 @@ +/* + * 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.mapping; + +import java.util.function.Consumer; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; +import org.hibernate.type.spi.TypeConfiguration; + +/** + * Something that can be expressable at the mapping model level. + * + * Generally this is used generation of SQL AST + * + * todo (6.0) : Better name? This one's a bit verbose. See description for clues + * + * @author Steve Ebersole + * @author Andrea Boriero + */ +public interface MappingModelExpressable { + JavaTypeDescriptor getExpressableJavaTypeDescriptor(); + + // todo (6.0) : others? + // Probably `org.hibernate.metamodel.mapping.Bindable` should be consumed here. Or at least exposed from here + // + // todo (6.0) : IMO `Bindable` should be consumed here and `Bindable` go away + + void visitJdbcTypes(Consumer action, TypeConfiguration typeConfiguration); + + default Bindable getBindable() { + throw new NotYetImplementedFor6Exception( getClass() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingType.java new file mode 100644 index 0000000000..200aa25431 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/MappingType.java @@ -0,0 +1,18 @@ +/* + * 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.mapping; + +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; + +/** + * Parts of the ModelPart hierarchy that are type descriptors, as opposed to attributes e.g. + * + * @author Steve Ebersole + */ +public interface MappingType extends ModelPart { + JavaTypeDescriptor getMappedJavaTypeDescriptor(); +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/ModelPart.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java similarity index 82% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/ModelPart.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java index e53b4b8f17..0d4d6aec37 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/ModelPart.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java @@ -4,13 +4,14 @@ * 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.model.mapping.spi; +package org.hibernate.metamodel.mapping; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.query.NavigablePath; +import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * Describes a mapping of related to any part of the app's domain model - e.g. @@ -21,13 +22,14 @@ import org.hibernate.sql.results.spi.DomainResultProducer; * * @author Steve Ebersole */ -public interface ModelPart extends ValueMapping { +public interface ModelPart extends MappingModelExpressable { /** * Create a DomainResult for a specific reference to this ModelPart. */ default DomainResult createDomainResult( NavigablePath navigablePath, + TableGroup tableGroup, String resultVariable, DomainResultCreationState creationState) { throw new NotYetImplementedFor6Exception( getClass() ); @@ -38,6 +40,7 @@ public interface ModelPart extends ValueMapping { */ default void applySqlSelections( NavigablePath navigablePath, + TableGroup tableGroup, DomainResultCreationState creationState) { throw new NotYetImplementedFor6Exception( getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/ValueMappingContainer.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPartContainer.java similarity index 80% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/ValueMappingContainer.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPartContainer.java index ed0e0c446f..a310047cda 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/ValueMappingContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPartContainer.java @@ -4,7 +4,7 @@ * 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.model.mapping.spi; +package org.hibernate.metamodel.mapping; import java.util.function.Consumer; @@ -15,18 +15,18 @@ import org.hibernate.NotYetImplementedFor6Exception; * * @author Steve Ebersole */ -public interface ValueMappingContainer extends ModelPart { +public interface ModelPartContainer extends ModelPart { /** * Find a sub-ValueMapping by name */ - default ValueMapping findValueMapping(String name){ + default ModelPart findSubPart(String name){ throw new NotYetImplementedFor6Exception( getClass() ); } /** * Visit all of this container's sub-ValueMappings */ - default void visitValueMappings(Consumer consumer){ + default void visitSubParts(Consumer consumer){ throw new NotYetImplementedFor6Exception( getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/SqlExpressable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/SqlExpressable.java similarity index 91% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/SqlExpressable.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/mapping/SqlExpressable.java index 52346bdbcb..cbebf4f239 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/SqlExpressable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/SqlExpressable.java @@ -4,7 +4,7 @@ * 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.model.mapping.spi; +package org.hibernate.metamodel.mapping; /** * Unifying contract for things that are capable of being an expression in diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/SqlExpressableType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/SqlExpressableType.java similarity index 95% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/SqlExpressableType.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/mapping/SqlExpressableType.java index 5c54e56ffd..da656e899a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/SqlExpressableType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/SqlExpressableType.java @@ -4,7 +4,7 @@ * 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.model.mapping.spi; +package org.hibernate.metamodel.mapping; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/ValueMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ValueMapping.java similarity index 72% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/ValueMapping.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ValueMapping.java index ab34e69bfe..e9fe3c7f80 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/spi/ValueMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ValueMapping.java @@ -4,13 +4,14 @@ * 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.model.mapping.spi; +package org.hibernate.metamodel.mapping; import java.util.Locale; +import java.util.function.Consumer; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.sql.ast.ValueMappingExpressable; import org.hibernate.type.Type; +import org.hibernate.type.spi.TypeConfiguration; /** * Describes a mapping related to any part of the app's domain model - e.g. @@ -22,23 +23,7 @@ import org.hibernate.type.Type; * * @author Steve Ebersole */ -public interface ValueMapping extends ValueMappingExpressable { - - /** - * Get the Type associated with this mapping - */ - default Type getValueType() { - throw new NotYetImplementedFor6Exception( getClass() ); - } - - default Bindable getBindable() { - throw new NotYetImplementedFor6Exception( getClass() ); - } - - @Override - default ValueMapping getExpressableValueMapping() { - return this; - } +public interface ValueMapping extends MappingModelExpressable { /** * Treat operation. Asks the ValueMapping to treat itself as the diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/package-info.java b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/package-info.java similarity index 68% rename from hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/package-info.java rename to hibernate-core/src/main/java/org/hibernate/metamodel/mapping/package-info.java index 9b9a84a3b4..540473693b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/mapping/package-info.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/mapping/package-info.java @@ -9,7 +9,6 @@ * Hibernate's run-time mapping model * * @implNote At the moment, most of this mapping model is defined in the - * {@link org.hibernate.persister} package. The intention is to move - * all run-time mapping model contracts here. + * {@link org.hibernate.persister} package. */ -package org.hibernate.metamodel.model.mapping; +package org.hibernate.metamodel.mapping; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/spi/ConvertibleValueMapping.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/spi/ConvertibleValueMapping.java index 6326be7233..c47cc95de1 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/spi/ConvertibleValueMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/convert/spi/ConvertibleValueMapping.java @@ -6,14 +6,14 @@ */ package org.hibernate.metamodel.model.convert.spi; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; +import org.hibernate.metamodel.mapping.ModelPart; /** * Describes a part of the domain model to which a value converter can be applied * * @author Steve Ebersole */ -public interface ConvertibleValueMapping extends ValueMapping { +public interface ConvertibleValueMapping extends ModelPart { /** * Get the value converter associated with this value mapping. May * return {@code null} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java index 9961297736..bec5189fc0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/AbstractIdentifiableType.java @@ -15,6 +15,7 @@ import javax.persistence.metamodel.SingularAttribute; import org.hibernate.metamodel.model.domain.internal.AttributeContainer; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; +import org.hibernate.type.spi.TypeConfiguration; /** * Defines commonality for the JPA {@link IdentifiableType} types. JPA defines @@ -268,6 +269,18 @@ public abstract class AbstractIdentifiableType } } + @Override + public void visitJdbcTypes(Consumer action, TypeConfiguration typeConfiguration) { + id.visitJdbcTypes( action, typeConfiguration ); + + if ( versionAttribute != null ) { + versionAttribute.visitJdbcTypes( action, typeConfiguration ); + } + + visitAttributes( + attribute -> attribute.visitJdbcTypes( action, typeConfiguration ) + ); + } /** * For used to retrieve the declared version when populating the static metamodel. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PersistentAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PersistentAttribute.java index 0dca52b856..f2c904c570 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PersistentAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/PersistentAttribute.java @@ -9,6 +9,7 @@ package org.hibernate.metamodel.model.domain; import javax.persistence.metamodel.Attribute; import org.hibernate.metamodel.AttributeClassification; +import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** @@ -16,7 +17,7 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; * * @author Steve Ebersole */ -public interface PersistentAttribute extends Attribute { +public interface PersistentAttribute extends Attribute, ModelPart { @Override ManagedDomainType getDeclaringType(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SingularPersistentAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SingularPersistentAttribute.java index ce8f719577..bd9bb675ef 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SingularPersistentAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/SingularPersistentAttribute.java @@ -8,6 +8,7 @@ package org.hibernate.metamodel.model.domain; import javax.persistence.metamodel.SingularAttribute; +import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.query.sqm.SqmJoinable; import org.hibernate.query.sqm.SqmPathSource; @@ -17,7 +18,7 @@ import org.hibernate.query.sqm.SqmPathSource; * @author Steve Ebersole */ public interface SingularPersistentAttribute - extends SingularAttribute, PersistentAttribute, SqmPathSource, SqmJoinable { + extends SingularAttribute, PersistentAttribute, ModelPart, SqmPathSource, SqmJoinable { @Override SimpleDomainType getType(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractAttribute.java index 3a48e2046a..14983762f0 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractAttribute.java @@ -16,6 +16,7 @@ import javax.persistence.metamodel.Attribute; import org.hibernate.internal.util.ReflectHelper; import org.hibernate.metamodel.AttributeClassification; +import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.PersistentAttribute; import org.hibernate.metamodel.model.domain.SimpleDomainType; @@ -39,6 +40,7 @@ public abstract class AbstractAttribute implements PersistentAttribute valueType; private transient Member member; + private final String mappingRole; @SuppressWarnings("WeakerAccess") protected AbstractAttribute( @@ -47,13 +49,16 @@ public abstract class AbstractAttribute implements PersistentAttribute attributeType, AttributeClassification attributeClassification, SimpleDomainType valueType, - Member member) { + Member member, + MetadataContext metadataContext) { this.declaringType = declaringType; this.name = name; this.attributeType = attributeType; this.attributeClassification = attributeClassification; this.valueType = valueType; this.member = member; + + this.mappingRole = metadataContext.getContainerRoleStack().getCurrent() + '.' + name; } @Override @@ -61,6 +66,10 @@ public abstract class AbstractAttribute implements PersistentAttribute getJavaType() { return attributeType.getJavaType(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java index 500155cfd0..1c58fdc9de 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractPluralAttribute.java @@ -10,6 +10,7 @@ import java.io.Serializable; import java.util.Collection; import org.hibernate.metamodel.CollectionClassification; +import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.model.domain.PluralPersistentAttribute; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.query.NavigablePath; @@ -35,14 +36,17 @@ public abstract class AbstractPluralAttribute private final SqmPathSource elementPathSource; @SuppressWarnings("WeakerAccess") - protected AbstractPluralAttribute(PluralAttributeBuilder builder) { + protected AbstractPluralAttribute( + PluralAttributeBuilder builder, + MetadataContext metadataContext) { super( builder.getDeclaringType(), builder.getProperty().getName(), builder.getCollectionJavaTypeDescriptor(), builder.getAttributeClassification(), builder.getValueType(), - builder.getMember() + builder.getMember(), + metadataContext ); this.classification = builder.getCollectionClassification(); @@ -59,6 +63,11 @@ public abstract class AbstractPluralAttribute return getName(); } + @Override + public String getMappingRole() { + return super.getMappingRole(); + } + @Override public CollectionClassification getCollectionClassification() { return classification; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java index cc48e0d43d..f868908ef4 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AbstractSqmPathSource.java @@ -15,14 +15,17 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; */ public abstract class AbstractSqmPathSource implements SqmPathSource { private final String localPathName; + private final String roleName; private final DomainType domainType; private final BindableType jpaBindableType; public AbstractSqmPathSource( String localPathName, + String roleName, DomainType domainType, BindableType jpaBindableType) { this.localPathName = localPathName; + this.roleName = roleName; this.domainType = domainType; this.jpaBindableType = jpaBindableType; } @@ -32,6 +35,11 @@ public abstract class AbstractSqmPathSource implements SqmPathSource { return localPathName; } + @Override + public String getMappingRole() { + return roleName; + } + @Override public DomainType getSqmPathType() { return domainType; diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java index 7e60f32084..5f2d7b698b 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/AnyMappingSqmPathSource.java @@ -24,6 +24,11 @@ public class AnyMappingSqmPathSource extends AbstractSqmPathSource { super( localPathName, domainType, jpaBindableType ); } + @Override + public String getMappingRole() { + return null; + } + @Override public AnyMappingDomainType getSqmPathType() { //noinspection unchecked diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java index d1da72a130..5874395a08 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/BasicSqmPathSource.java @@ -25,9 +25,10 @@ public class BasicSqmPathSource @SuppressWarnings("WeakerAccess") public BasicSqmPathSource( String localPathName, + String roleName, BasicDomainType domainType, BindableType jpaBindableType) { - super( localPathName, domainType, jpaBindableType ); + super( localPathName, roleName, domainType, jpaBindableType ); } @Override 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 d58e464ca3..02b419e869 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 @@ -9,6 +9,7 @@ package org.hibernate.metamodel.model.domain.internal; import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -43,6 +44,8 @@ import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Collection; import org.hibernate.mapping.PersistentClass; import org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting; +import org.hibernate.metamodel.mapping.MappingModelExpressable; +import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; @@ -55,7 +58,10 @@ import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Queryable; import org.hibernate.persister.spi.PersisterFactory; +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.tuple.entity.EntityTuplizer; +import org.hibernate.type.BasicType; import org.hibernate.type.Type; import org.hibernate.type.spi.TypeConfiguration; @@ -97,6 +103,7 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento // DomainMetamodel private final Set entityNameResolvers = new HashSet<>(); + private final Map modelPartRoleMap = new HashMap<>(); // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -219,6 +226,7 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento modelCreationContext ); entityPersisterMap.put( model.getEntityName(), cp ); + modelPartRoleMap.put( model.getEntityName(), cp ); if ( cp.getConcreteProxyClass() != null && cp.getConcreteProxyClass().isInterface() @@ -685,4 +693,26 @@ public class DomainMetamodelImpl implements DomainMetamodel, MetamodelImplemento return results.toArray( new String[results.size()] ); } + + @Override + public MappingModelExpressable resolveMappingExpressable(SqmExpressable sqmExpressable) { + + if ( sqmExpressable instanceof BasicType ) { + return (BasicType) sqmExpressable; + } + else if ( sqmExpressable instanceof SqmPathSource ) { + final SqmPathSource pathSource = (SqmPathSource) sqmExpressable; + final String role = pathSource.getMappingRole(); + + return modelPartRoleMap.get( role ); + + /* + "org...Person" -> EntityPersister(Person) + "org...Person.name" -> AttributeDescriptor(..) + "org...Person.name.first" -> AttributeDescriptor(..) + */ + } + + throw new NotYetImplementedFor6Exception( getClass() ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java index 0b49c69938..224ce0b4bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EmbeddedSqmPathSource.java @@ -19,9 +19,10 @@ import org.hibernate.query.sqm.tree.domain.SqmPath; public class EmbeddedSqmPathSource extends AbstractSqmPathSource implements AllowableParameterType { public EmbeddedSqmPathSource( String localPathName, + String roleName, EmbeddableDomainType domainType, BindableType jpaBindableType) { - super( localPathName, domainType, jpaBindableType ); + super( localPathName, roleName, domainType, jpaBindableType ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java index d5ba659035..7da2829112 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntitySqmPathSource.java @@ -21,9 +21,10 @@ import org.hibernate.query.sqm.tree.domain.SqmPath; public class EntitySqmPathSource extends AbstractSqmPathSource { public EntitySqmPathSource( String localPathName, + String roleName, EntityDomainType domainType, BindableType jpaBindableType) { - super( localPathName, domainType, jpaBindableType ); + super( localPathName, roleName, domainType, jpaBindableType ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java index e5c7346f28..d4c61b9603 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/EntityTypeImpl.java @@ -48,6 +48,7 @@ public class EntityTypeImpl persistentClass.isVersioned(), jpaMetamodel ); + this.jpaEntityName = persistentClass.getJpaEntityName(); } @@ -56,6 +57,11 @@ public class EntityTypeImpl return jpaEntityName; } + @Override + public String getMappingRole() { + return getHibernateEntityName(); + } + @Override public String getHibernateEntityName() { return super.getTypeName(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java index 390536f9ee..fe8c8e22ee 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/SingularAttributeImpl.java @@ -12,6 +12,7 @@ import java.util.function.Supplier; import org.hibernate.graph.spi.GraphHelper; import org.hibernate.metamodel.AttributeClassification; +import org.hibernate.metamodel.internal.MetadataContext; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.SimpleDomainType; import org.hibernate.metamodel.model.domain.SingularPersistentAttribute; @@ -48,8 +49,17 @@ public class SingularAttributeImpl Member member, boolean isIdentifier, boolean isVersion, - boolean isOptional) { - super( declaringType, name, attributeType.getExpressableJavaTypeDescriptor(), attributeClassification, attributeType, member ); + boolean isOptional, + MetadataContext metadataContext) { + super( + declaringType, + name, + attributeType.getExpressableJavaTypeDescriptor(), + attributeClassification, + attributeType, + member, + metadataContext + ); this.isIdentifier = isIdentifier; this.isVersion = isVersion; this.isOptional = isOptional; @@ -67,6 +77,15 @@ public class SingularAttributeImpl return getName(); } + @Override + public String getMappingRole() { + return super.getMappingRole(); + } + + public JavaTypeDescriptor getExpressableJavaTypeDescriptor() { + return sqmPathSource.getExpressableJavaTypeDescriptor(); + } + @Override public SimpleDomainType getSqmPathType() { //noinspection unchecked @@ -88,10 +107,6 @@ public class SingularAttributeImpl return getSqmPathType(); } - public JavaTypeDescriptor getExpressableJavaTypeDescriptor() { - return sqmPathSource.getExpressableJavaTypeDescriptor(); - } - @Override public Class getBindableJavaType() { return getExpressableJavaTypeDescriptor().getJavaType(); @@ -130,7 +145,8 @@ public class SingularAttributeImpl String name, SimpleDomainType attributeType, Member member, - AttributeClassification attributeClassification) { + AttributeClassification attributeClassification, + MetadataContext metadataContext) { super( declaringType, name, @@ -139,7 +155,8 @@ public class SingularAttributeImpl member, true, false, - false + false, + metadataContext ); } } @@ -154,7 +171,8 @@ public class SingularAttributeImpl String name, AttributeClassification attributeClassification, SimpleDomainType attributeType, - Member member) { + Member member, + MetadataContext metadataContext) { super( declaringType, name, @@ -163,7 +181,8 @@ public class SingularAttributeImpl member, false, true, - false + false, + metadataContext ); } } 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 4493be1177..5c472cdd13 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 @@ -12,15 +12,17 @@ import java.util.function.Consumer; import org.hibernate.Incubating; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.graph.RootGraph; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.metamodel.model.domain.AllowableParameterType; +import org.hibernate.metamodel.model.domain.BasicDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.NavigableRole; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.type.BasicType; import org.hibernate.type.spi.TypeConfiguration; @@ -52,9 +54,7 @@ public interface DomainMetamodel { * @param sqmExpressable * @return */ - default ValueMapping resolveValueMapping(SqmExpressable sqmExpressable) { - throw new NotYetImplementedFor6Exception( getClass() ); - } + MappingModelExpressable resolveMappingExpressable(SqmExpressable sqmExpressable); /** * Given a Java type, determine the corresponding AllowableParameterType to diff --git a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java index 5351bacff8..68692f414b 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java @@ -33,7 +33,6 @@ import org.hibernate.cache.spi.entry.CacheEntryStructure; import org.hibernate.cache.spi.entry.StructuredCollectionCacheEntry; import org.hibernate.cache.spi.entry.StructuredMapCacheEntry; import org.hibernate.cache.spi.entry.UnstructuredCacheEntry; -import org.hibernate.cfg.NotYetImplementedException; import org.hibernate.collection.spi.PersistentCollection; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.batch.internal.BasicBatchKey; @@ -66,10 +65,10 @@ import org.hibernate.mapping.List; import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Table; import org.hibernate.metadata.CollectionMetadata; +import org.hibernate.metamodel.mapping.ModelPart; +import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.NavigableRole; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; import org.hibernate.persister.entity.EntityPersister; -import org.hibernate.persister.entity.Loadable; import org.hibernate.persister.entity.PropertyMapping; import org.hibernate.persister.entity.Queryable; import org.hibernate.persister.spi.PersisterCreationContext; @@ -95,6 +94,8 @@ import org.hibernate.type.CollectionType; import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; import org.hibernate.type.Type; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; +import org.hibernate.type.spi.TypeConfiguration; import org.jboss.logging.Logger; @@ -2179,6 +2180,16 @@ public abstract class AbstractCollectionPersister throw new IllegalStateException( "Cannot treat collection index type as composite" ); } return new CompositeCollectionElementDefinition() { + @Override + public JavaTypeDescriptor getExpressableJavaTypeDescriptor() { + return ( (EmbeddableDomainType) getType() ).getExpressableJavaTypeDescriptor(); + } + + @Override + public void visitJdbcTypes(Consumer action, TypeConfiguration typeConfiguration) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + @Override public String getName() { return "index"; @@ -2262,13 +2273,23 @@ public abstract class AbstractCollectionPersister return new CompositeCollectionElementDefinition() { @Override - public void visitValueMappings(Consumer consumer) { + public JavaTypeDescriptor getExpressableJavaTypeDescriptor() { + return ( (EmbeddableDomainType) getType() ).getExpressableJavaTypeDescriptor(); + } + + @Override + public void visitJdbcTypes(Consumer action, TypeConfiguration typeConfiguration) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + + @Override + public void visitSubParts(Consumer consumer) { throw new NotYetImplementedFor6Exception( getClass() ); } @Override - public ValueMapping findValueMapping(String name) { + public ModelPart findSubPart(String name) { throw new NotYetImplementedFor6Exception( getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java index bea18cf0e1..ed6f0a0560 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java @@ -34,7 +34,6 @@ import org.hibernate.JDBCException; import org.hibernate.LockMode; import org.hibernate.LockOptions; import org.hibernate.MappingException; -import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.QueryException; import org.hibernate.Session; import org.hibernate.StaleObjectStateException; @@ -122,8 +121,8 @@ import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Subclass; import org.hibernate.mapping.Table; import org.hibernate.metadata.ClassMetadata; +import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.metamodel.model.domain.NavigableRole; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; import org.hibernate.persister.collection.CollectionPersister; import org.hibernate.persister.spi.PersisterCreationContext; import org.hibernate.persister.walking.internal.EntityIdentifierDefinitionHelper; @@ -143,14 +142,11 @@ import org.hibernate.sql.SelectFragment; import org.hibernate.sql.SimpleSelect; import org.hibernate.sql.Template; import org.hibernate.sql.Update; -import org.hibernate.sql.ast.ValueMappingExpressable; import org.hibernate.sql.ast.spi.SqlAliasBase; import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator; import org.hibernate.sql.ast.spi.SqlAliasStemHelper; import org.hibernate.sql.ast.spi.SqlAstCreationContext; -import org.hibernate.sql.ast.spi.SqlAstWalker; import org.hibernate.sql.ast.tree.expression.ColumnReference; -import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.from.StandardTableGroup; import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableReference; @@ -1195,7 +1191,7 @@ public abstract class AbstractEntityPersister } @Override - public ValueMapping findValueMapping(String name) { + public ModelPart findSubPart(String name) { for ( AttributeDefinition attributeDefinition : attributeDefinitions ) { if ( attributeDefinition.getName().equals( name ) ) { return attributeDefinition; @@ -1206,7 +1202,7 @@ public abstract class AbstractEntityPersister } @Override - public void visitValueMappings(Consumer consumer) { + public void visitSubParts(Consumer consumer) { consumer.accept( entityIdentifierDefinition ); for ( AttributeDefinition attributeDefinition : attributeDefinitions ) { diff --git a/hibernate-core/src/main/java/org/hibernate/persister/walking/internal/CompositionSingularSubAttributesHelper.java b/hibernate-core/src/main/java/org/hibernate/persister/walking/internal/CompositionSingularSubAttributesHelper.java index 3ca5bf195d..77f04ea9b9 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/walking/internal/CompositionSingularSubAttributesHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/walking/internal/CompositionSingularSubAttributesHelper.java @@ -7,6 +7,7 @@ package org.hibernate.persister.walking.internal; import java.util.Iterator; +import java.util.function.Consumer; import org.hibernate.FetchMode; import org.hibernate.engine.FetchStrategy; @@ -35,6 +36,8 @@ import org.hibernate.type.AnyType; import org.hibernate.type.AssociationType; import org.hibernate.type.CompositeType; import org.hibernate.type.Type; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; +import org.hibernate.type.spi.TypeConfiguration; /** * A helper for getting attributes from a composition that is known @@ -137,6 +140,18 @@ public final class CompositionSingularSubAttributesHelper { if ( type.isAssociationType() ) { final AssociationType aType = (AssociationType) type; return new AssociationAttributeDefinition() { + @Override + public JavaTypeDescriptor getExpressableJavaTypeDescriptor() { + return ; + } + + @Override + public void visitJdbcTypes( + Consumer action, + TypeConfiguration typeConfiguration) { + + } + @Override public AssociationKey getAssociationKey() { return new AssociationKey( lhsTableName, subAttributeLhsColumns ); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AttributeDefinition.java b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AttributeDefinition.java index dad5dd052f..ae0c57236a 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AttributeDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AttributeDefinition.java @@ -6,14 +6,14 @@ */ package org.hibernate.persister.walking.spi; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; +import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.type.Type; /** * Descriptor for * @author Steve Ebersole */ -public interface AttributeDefinition extends ValueMapping { +public interface AttributeDefinition extends ModelPart { AttributeSource getSource(); String getName(); Type getType(); diff --git a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AttributeSource.java b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AttributeSource.java index c56b10d54d..8d7152a727 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AttributeSource.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/AttributeSource.java @@ -6,11 +6,11 @@ */ package org.hibernate.persister.walking.spi; -import org.hibernate.metamodel.model.mapping.spi.ValueMappingContainer; +import org.hibernate.metamodel.mapping.ModelPartContainer; /** * @author Steve Ebersole */ -public interface AttributeSource extends ValueMappingContainer { +public interface AttributeSource extends ModelPartContainer { Iterable getAttributes(); } diff --git a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/EntityIdentifierDefinition.java b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/EntityIdentifierDefinition.java index e001c9d33c..e7a95e6fd0 100644 --- a/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/EntityIdentifierDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/persister/walking/spi/EntityIdentifierDefinition.java @@ -6,14 +6,14 @@ */ package org.hibernate.persister.walking.spi; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; +import org.hibernate.metamodel.mapping.ModelPart; /** * Describes aspects of the identifier for an entity * * @author Steve Ebersole */ -public interface EntityIdentifierDefinition extends ValueMapping { +public interface EntityIdentifierDefinition extends ModelPart { /** * Is the entity identifier encapsulated? Meaning, is it represented by a single attribute? * diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java index 469a139597..998d8d0c5b 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ProcedureCallImpl.java @@ -6,8 +6,6 @@ */ package org.hibernate.procedure.internal; -import java.sql.CallableStatement; -import java.sql.SQLException; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; @@ -16,7 +14,6 @@ import java.util.Date; import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.function.Consumer; import javax.persistence.FlushModeType; import javax.persistence.LockModeType; import javax.persistence.NoResultException; @@ -62,8 +59,7 @@ import org.hibernate.result.UpdateCountOutput; import org.hibernate.result.spi.ResultContext; import org.hibernate.sql.exec.spi.DomainParameterBindingContext; import org.hibernate.sql.results.NoMoreOutputsException; -import org.hibernate.sql.results.spi.DomainResultProducer; -import org.hibernate.type.Type; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.jboss.logging.Logger; diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ScalarDomainResultProducer.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ScalarDomainResultProducer.java index 9749612053..73533f08f4 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/ScalarDomainResultProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/ScalarDomainResultProducer.java @@ -8,10 +8,9 @@ package org.hibernate.procedure.internal; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.query.sqm.SqmExpressable; -import org.hibernate.sql.results.internal.ScalarDomainResultImpl; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/procedure/internal/Util.java b/hibernate-core/src/main/java/org/hibernate/procedure/internal/Util.java index 8901953d29..ac5c85b5c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/procedure/internal/Util.java +++ b/hibernate-core/src/main/java/org/hibernate/procedure/internal/Util.java @@ -11,13 +11,10 @@ import java.util.function.Consumer; import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.internal.util.collections.ArrayHelper; -import org.hibernate.metamodel.spi.DomainMetamodel; import org.hibernate.query.named.NamedQueryRepository; import org.hibernate.query.named.NamedResultSetMappingMemento; import org.hibernate.query.spi.ResultSetMapping; -import org.hibernate.sql.results.spi.DomainResultProducer; -import org.hibernate.type.BasicType; -import org.hibernate.type.spi.TypeConfiguration; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.jboss.logging.Logger; diff --git a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java index 3eb4061aff..fa5b5af6ca 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java +++ b/hibernate-core/src/main/java/org/hibernate/query/hql/internal/FullyQualifiedReflectivePathTerminal.java @@ -28,7 +28,6 @@ import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.expression.SqmFieldLiteral; import org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; -import org.hibernate.sql.results.spi.DomainResultProducer; import org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -240,8 +239,4 @@ public class FullyQualifiedReflectivePathTerminal return null; } - @Override - public DomainResultProducer getDomainResultProducer() { - throw new UnsupportedOperationException( ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/spi/ResultSetMapping.java b/hibernate-core/src/main/java/org/hibernate/query/spi/ResultSetMapping.java index 9aa633f99b..614661a831 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/spi/ResultSetMapping.java +++ b/hibernate-core/src/main/java/org/hibernate/query/spi/ResultSetMapping.java @@ -8,7 +8,7 @@ package org.hibernate.query.spi; import org.hibernate.Incubating; import org.hibernate.query.named.NamedResultSetMappingMemento; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * Describes a ResultSet mapping applied to either a {@link org.hibernate.query.NativeQuery} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmPathSource.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmPathSource.java index b8c75c5ae7..e63246f533 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmPathSource.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/SqmPathSource.java @@ -23,6 +23,12 @@ import org.hibernate.query.sqm.tree.domain.SqmPath; * @author Steve Ebersole */ public interface SqmPathSource extends SqmExpressable, Bindable { + /** + * A sort-of unique key for a part of the model as a compound (dot-separated) name. + * Will end with {@link #getPathName} + */ + String getMappingRole(); + /** * The name of this thing. Mainly used in logging and when creating a * {@link org.hibernate.query.NavigablePath} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCoalesce.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCoalesce.java index 5bd852b831..04568bd7f0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCoalesce.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmCoalesce.java @@ -19,7 +19,7 @@ import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.produce.function.SqmFunctionTemplate; import org.hibernate.query.sqm.tree.expression.AbstractSqmExpression; import org.hibernate.query.sqm.tree.expression.SqmExpression; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * Specialized CASE statement for resolving the first non-null value in a list of values @@ -103,8 +103,4 @@ public class SqmCoalesce extends AbstractSqmExpression implements JpaCoale return this; } - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunction.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunction.java index 8dfcb0ee2c..41d3bcae63 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunction.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmFunction.java @@ -9,7 +9,7 @@ package org.hibernate.query.sqm.function; import org.hibernate.query.criteria.JpaFunction; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.tree.expression.SqmExpression; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * Contract for functions impls that would like to control the @@ -37,8 +37,4 @@ public interface SqmFunction extends SqmExpression, JpaFunction, Domain return walker.visitFunction( this ); } - @Override - default DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmStar.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmStar.java index f4e29941c0..cba562a2b0 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmStar.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/function/SqmStar.java @@ -9,7 +9,6 @@ package org.hibernate.query.sqm.function; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.tree.expression.AbstractSqmExpression; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * @author Gavin King @@ -25,8 +24,4 @@ public class SqmStar extends AbstractSqmExpression { return walker.visitStar(this); } - @Override - public DomainResultProducer getDomainResultProducer() { - throw new UnsupportedOperationException( ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java index 4a48b73654..71895c0e68 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/BaseSqmToSqlAstConverter.java @@ -20,9 +20,9 @@ import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.engine.spi.LoadQueryInfluencers; import org.hibernate.internal.util.collections.Stack; import org.hibernate.internal.util.collections.StandardStack; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.BinaryArithmeticOperator; import org.hibernate.query.UnaryArithmeticOperator; @@ -37,16 +37,21 @@ import org.hibernate.query.sqm.internal.DomainParameterXref; import org.hibernate.query.sqm.spi.BaseSemanticQueryWalker; import org.hibernate.query.sqm.spi.JdbcParameterBySqmParameterAccess; import org.hibernate.query.sqm.sql.internal.SqlAstQuerySpecProcessingStateImpl; +import org.hibernate.query.sqm.sql.internal.SqmExpressionInterpretation; +import org.hibernate.query.sqm.sql.internal.SqmPathInterpretation; import org.hibernate.query.sqm.tree.delete.SqmDeleteStatement; import org.hibernate.query.sqm.tree.domain.SqmBasicValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmEmbeddedValuedSimplePath; import org.hibernate.query.sqm.tree.domain.SqmEntityValuedSimplePath; +import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmPluralValuedSimplePath; import org.hibernate.query.sqm.tree.expression.SqmBinaryArithmetic; import org.hibernate.query.sqm.tree.expression.SqmCaseSearched; import org.hibernate.query.sqm.tree.expression.SqmCaseSimple; import org.hibernate.query.sqm.tree.expression.SqmCriteriaParameter; +import org.hibernate.query.sqm.tree.expression.SqmEnumLiteral; import org.hibernate.query.sqm.tree.expression.SqmExpression; +import org.hibernate.query.sqm.tree.expression.SqmFieldLiteral; import org.hibernate.query.sqm.tree.expression.SqmLiteral; import org.hibernate.query.sqm.tree.expression.SqmNamedParameter; import org.hibernate.query.sqm.tree.expression.SqmParameter; @@ -55,6 +60,7 @@ import org.hibernate.query.sqm.tree.expression.SqmUnaryOperation; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmCrossJoin; import org.hibernate.query.sqm.tree.from.SqmEntityJoin; +import org.hibernate.query.sqm.tree.from.SqmFrom; import org.hibernate.query.sqm.tree.from.SqmFromClause; import org.hibernate.query.sqm.tree.from.SqmRoot; import org.hibernate.query.sqm.tree.insert.SqmInsertSelectStatement; @@ -78,7 +84,6 @@ import org.hibernate.query.sqm.tree.select.SqmSubQuery; import org.hibernate.query.sqm.tree.update.SqmUpdateStatement; import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.JoinType; -import org.hibernate.sql.ast.ValueMappingExpressable; import org.hibernate.sql.ast.spi.FromClauseAccess; import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator; import org.hibernate.sql.ast.spi.SqlAstCreationContext; @@ -86,6 +91,7 @@ import org.hibernate.sql.ast.tree.expression.BinaryArithmeticExpression; import org.hibernate.sql.ast.tree.expression.CaseSearchedExpression; import org.hibernate.sql.ast.tree.expression.CaseSimpleExpression; import org.hibernate.sql.ast.tree.expression.Expression; +import org.hibernate.sql.ast.tree.expression.QueryLiteral; import org.hibernate.sql.ast.tree.expression.SqlTuple; import org.hibernate.sql.ast.tree.expression.UnaryOperation; import org.hibernate.sql.ast.tree.from.TableGroup; @@ -265,7 +271,6 @@ public abstract class BaseSqmToSqlAstConverter this, currentClauseStack::getCurrent, () -> (expression) -> {}, - () -> sqlQuerySpec.getSelectClause()::addSelection, () -> sqlQuerySpec.getSelectClause()::addSqlSelection ) ); @@ -384,18 +389,10 @@ public abstract class BaseSqmToSqlAstConverter try { sqmFromClause.visitRoots( sqmRoot -> { - final EntityPersister entityDescriptor = resolveEntityPersister( sqmRoot.getReferencedPathSource() ); - - final TableGroup rootTableGroup = entityDescriptor.createRootTableGroup( - sqmRoot.getNavigablePath(), - sqmRoot.getExplicitAlias(), - null, - determineLockMode( sqmRoot.getExplicitAlias() ), - sqlAliasBaseManager, - creationContext - ); + final TableGroup rootTableGroup = visitRootPath( sqmRoot ); currentQuerySpec().getFromClause().addRoot( rootTableGroup ); + getFromClauseIndex().register( sqmRoot, rootTableGroup ); } ); } @@ -407,18 +404,16 @@ public abstract class BaseSqmToSqlAstConverter } - @Override public TableGroup visitRootPath(SqmRoot sqmRoot) { log.tracef( "Starting resolution of SqmRoot [%s] to TableGroup", sqmRoot ); - if ( fromClauseIndex.isResolved( sqmRoot ) ) { - final TableGroup resolvedTableGroup = fromClauseIndex.findTableGroup( sqmRoot.getNavigablePath() ); + final TableGroup resolvedTableGroup = fromClauseIndex.findTableGroup( sqmRoot.getNavigablePath() ); + if ( resolvedTableGroup != null ) { log.tracef( "SqmRoot [%s] resolved to existing TableGroup [%s]", sqmRoot, resolvedTableGroup ); return resolvedTableGroup; } - final EntityPersister entityDescriptor = resolveEntityPersister( sqmRoot.getReferencedPathSource() ); final TableGroup tableGroup = entityDescriptor.createRootTableGroup( @@ -435,14 +430,8 @@ public abstract class BaseSqmToSqlAstConverter log.tracef( "Resolved SqmRoot [%s] to new TableGroup [%s]", sqmRoot, tableGroup ); - sqmRoot.visitSqmJoins( - sqmJoin -> { - final TableGroupJoin tableGroupJoin = (TableGroupJoin) sqmJoin.accept( this ); - if ( tableGroupJoin != null ) { - tableGroup.addTableGroupJoin( tableGroupJoin ); - } - } - ); + visitExplicitJoins( sqmRoot, tableGroup ); + visitImplicitJoins( sqmRoot, tableGroup ); return tableGroup; } @@ -451,6 +440,30 @@ public abstract class BaseSqmToSqlAstConverter return creationContext.getDomainModel().getEntityDescriptor( entityDomainType.getHibernateEntityName() ); } + private void visitExplicitJoins(SqmFrom sqmFrom, TableGroup tableGroup) { + log.tracef( "Visiting explicit joins for `%s`", sqmFrom.getNavigablePath() ); + + sqmFrom.visitSqmJoins( + sqmJoin -> { + final TableGroupJoin tableGroupJoin = (TableGroupJoin) sqmJoin.accept( this ); + if ( tableGroupJoin != null ) { + tableGroup.addTableGroupJoin( tableGroupJoin ); + getFromClauseIndex().register( sqmFrom, tableGroup ); + } + } + ); + } + + private void visitImplicitJoins(SqmPath sqmPath, TableGroup tableGroup) { + log.tracef( "Visiting implicit joins for `%s`", sqmPath.getNavigablePath() ); + + sqmPath.visitImplicitJoinPaths( + joinedPath -> { + log.tracef( "Starting implicit join handling for `%s`", joinedPath.getNavigablePath() ); + } + ); + } + @Override public TableGroupJoin visitQualifiedAttributeJoin(SqmAttributeJoin sqmJoin) { final TableGroupJoin tableJoinJoin = fromClauseIndex.findTableGroupJoin( sqmJoin.getNavigablePath() ); @@ -554,23 +567,32 @@ public abstract class BaseSqmToSqlAstConverter } @Override - public Object visitBasicValuedPath(SqmBasicValuedSimplePath path) { - throw new NotYetImplementedFor6Exception( getClass() ); + public SqmPathInterpretation visitBasicValuedPath(SqmBasicValuedSimplePath sqmPath) { + final SqmPath lhs = sqmPath.getLhs(); + assert lhs != null; + + return (SqmPathInterpretation) sqmPath; } @Override - public Object visitEmbeddableValuedPath(SqmEmbeddedValuedSimplePath path) { - throw new NotYetImplementedFor6Exception( getClass() ); + public SqmPathInterpretation visitEmbeddableValuedPath(SqmEmbeddedValuedSimplePath sqmPath) { + final SqmPath lhs = sqmPath.getLhs(); + assert lhs != null; + + return (SqmPathInterpretation) sqmPath; } @Override - public Object visitEntityValuedPath(SqmEntityValuedSimplePath path) { - throw new NotYetImplementedFor6Exception( getClass() ); + public SqmPathInterpretation visitEntityValuedPath(SqmEntityValuedSimplePath sqmPath) { + final SqmPath lhs = sqmPath.getLhs(); + assert lhs != null; + + return (SqmPathInterpretation) sqmPath; } @Override - public Object visitPluralValuedPath(SqmPluralValuedSimplePath path) { - throw new NotYetImplementedFor6Exception(); + public SqmPathInterpretation visitPluralValuedPath(SqmPluralValuedSimplePath sqmPath) { + return (SqmPathInterpretation) sqmPath; } @@ -578,7 +600,7 @@ public abstract class BaseSqmToSqlAstConverter // Expressions @Override - public Object visitLiteral(SqmLiteral literal) { + public SqmExpressionInterpretation visitLiteral(SqmLiteral literal) { throw new NotYetImplementedFor6Exception( getClass() ); // final ExpressableType expressableType = determineExpressableType( literal ); // if ( expressableType instanceof BasicValuedExpressableType ) { @@ -612,7 +634,7 @@ public abstract class BaseSqmToSqlAstConverter private Expression consumeSqmParameter(SqmParameter sqmParameter) { final List jdbcParametersForSqm = new ArrayList<>(); - final ValueMapping valueMapping = determineValueMapping( sqmParameter ); + final MappingModelExpressable valueMapping = determineValueMapping( sqmParameter ); resolveSqmParameter( sqmParameter, valueMapping, jdbcParametersForSqm::add ); @@ -620,25 +642,25 @@ public abstract class BaseSqmToSqlAstConverter jdbcParamsBySqmParam.put( sqmParameter, jdbcParametersForSqm ); if ( jdbcParametersForSqm.size() > 1 ) { - return new SqlTuple( jdbcParametersForSqm, () -> valueMapping ); + return new SqlTuple( jdbcParametersForSqm, valueMapping ); } else { return jdbcParametersForSqm.get( 0 ); } } - protected ValueMapping determineValueMapping(SqmExpression sqmExpression) { + protected MappingModelExpressable determineValueMapping(SqmExpression sqmExpression) { final SqmExpressable nodeType = sqmExpression.getNodeType(); - ValueMapping valueMapping = getCreationContext().getDomainModel().resolveValueMapping( nodeType ); + MappingModelExpressable valueMapping = getCreationContext().getDomainModel().resolveMappingExpressable( nodeType ); // alternative - // sqmExpression.resolveValueMapping( getCreationContext(), "inferableTypeAccessStack" ); + // sqmExpression.resolveMappingExpressable( getCreationContext(), "inferableTypeAccessStack" ); if ( valueMapping == null ) { - final Supplier currentExpressableSupplier = inferableTypeAccessStack.getCurrent(); + final Supplier currentExpressableSupplier = inferableTypeAccessStack.getCurrent(); if ( currentExpressableSupplier != null ) { - valueMapping = currentExpressableSupplier.get().getExpressableValueMapping(); + valueMapping = currentExpressableSupplier.get(); } } @@ -650,11 +672,11 @@ public abstract class BaseSqmToSqlAstConverter } - private final Stack> inferableTypeAccessStack = new StandardStack<>( + private final Stack> inferableTypeAccessStack = new StandardStack<>( () -> () -> null ); - private void resolveSqmParameter(SqmParameter expression, ValueMapping valueMapping, Consumer jdbcParameterConsumer) { + private void resolveSqmParameter(SqmParameter expression, MappingModelExpressable valueMapping, Consumer jdbcParameterConsumer) { throw new NotYetImplementedFor6Exception( getClass() ); // if ( valueMapping == null ) { // final StandardJdbcParameterImpl jdbcParameter = new StandardJdbcParameterImpl( @@ -1118,7 +1140,7 @@ public abstract class BaseSqmToSqlAstConverter return new UnaryOperation( interpret( expression.getOperation() ), (Expression) expression.getOperand().accept( this ), - () -> determineValueMapping( expression ) + determineValueMapping( expression ) ); } @@ -1148,7 +1170,7 @@ public abstract class BaseSqmToSqlAstConverter return new BinaryArithmeticExpression( (Expression) expression.getLeftHandOperand().accept( this ), interpret( expression.getOperator() ), (Expression) expression.getRightHandOperand().accept( this ), - () -> determineValueMapping( expression ) + determineValueMapping( expression ) ); } finally { @@ -1198,7 +1220,7 @@ public abstract class BaseSqmToSqlAstConverter @Override public CaseSimpleExpression visitSimpleCaseExpression(SqmCaseSimple expression) { final CaseSimpleExpression result = new CaseSimpleExpression( - () -> determineValueMapping( expression ), + determineValueMapping( expression ), (Expression) expression.getFixture().accept( this ) ); @@ -1217,7 +1239,7 @@ public abstract class BaseSqmToSqlAstConverter @Override public CaseSearchedExpression visitSearchedCaseExpression(SqmCaseSearched expression) { final CaseSearchedExpression result = new CaseSearchedExpression( - () -> determineValueMapping( expression ) + determineValueMapping( expression ) ); for ( SqmCaseSearched.WhenFragment whenFragment : expression.getWhenFragments() ) { @@ -1232,6 +1254,24 @@ public abstract class BaseSqmToSqlAstConverter return result; } + @Override + public Object visitEnumLiteral(SqmEnumLiteral sqmEnumLiteral) { + return new QueryLiteral( + sqmEnumLiteral.getEnumValue(), + determineValueMapping( sqmEnumLiteral ), + getCurrentClauseStack().getCurrent() + ); + } + + @Override + public Object visitFieldLiteral(SqmFieldLiteral sqmFieldLiteral) { + return new QueryLiteral( + sqmFieldLiteral.getValue(), + determineValueMapping( sqmFieldLiteral ), + getCurrentClauseStack().getCurrent() + ); + } + // @Override // public Object visitPluralAttributeElementBinding(PluralAttributeElementBinding binding) { @@ -1294,7 +1334,7 @@ public abstract class BaseSqmToSqlAstConverter @Override public ComparisonPredicate visitComparisonPredicate(SqmComparisonPredicate predicate) { - inferableTypeAccessStack.push( () -> () -> determineValueMapping( predicate.getRightHandExpression() ) ); + inferableTypeAccessStack.push( () -> determineValueMapping( predicate.getRightHandExpression() ) ); final Expression lhs; try { @@ -1304,7 +1344,7 @@ public abstract class BaseSqmToSqlAstConverter inferableTypeAccessStack.pop(); } - inferableTypeAccessStack.push( () -> () -> determineValueMapping( predicate.getLeftHandExpression() ) ); + inferableTypeAccessStack.push( () -> determineValueMapping( predicate.getLeftHandExpression() ) ); final Expression rhs; try { @@ -1335,7 +1375,7 @@ public abstract class BaseSqmToSqlAstConverter final Expression upperBound; inferableTypeAccessStack.push( - () -> () -> coalesce( + () -> coalesce( determineValueMapping( predicate.getLowerBound() ), determineValueMapping( predicate.getUpperBound() ) ) @@ -1349,7 +1389,7 @@ public abstract class BaseSqmToSqlAstConverter } inferableTypeAccessStack.push( - () -> () -> coalesce( + () -> coalesce( determineValueMapping( predicate.getExpression() ), determineValueMapping( predicate.getUpperBound() ) ) @@ -1362,7 +1402,7 @@ public abstract class BaseSqmToSqlAstConverter } inferableTypeAccessStack.push( - () -> () -> coalesce( + () -> coalesce( determineValueMapping( predicate.getExpression() ), determineValueMapping( predicate.getLowerBound() ) ) @@ -1423,7 +1463,7 @@ public abstract class BaseSqmToSqlAstConverter ); inferableTypeAccessStack.push( - () -> () -> determineValueMapping( predicate.getTestExpression() ) ); + () -> determineValueMapping( predicate.getTestExpression() ) ); try { boolean first = true; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/AssignableSqmPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/AssignableSqmPathInterpretation.java new file mode 100644 index 0000000000..23a117709b --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/AssignableSqmPathInterpretation.java @@ -0,0 +1,30 @@ +/* + * 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.query.sqm.sql.internal; + +import java.util.function.Consumer; + +import org.hibernate.sql.ast.spi.SqlAstCreationContext; +import org.hibernate.sql.ast.tree.expression.Expression; +import org.hibernate.sql.ast.tree.update.Assignment; + +/** + * @author Steve Ebersole + */ +public interface AssignableSqmPathInterpretation extends SqmPathInterpretation { + // need to be able to collect assignments per-table, including + // SqmParameter -> JdbcParameter mapping + + void applySqlAssignments( + Expression newValueExpression, + AssignmentContext assignmentProcessingState, + Consumer assignmentConsumer, + SqlAstCreationContext creationContext); + + interface AssignmentContext { + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/DomainResultProducer.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DomainResultProducer.java similarity index 68% rename from hibernate-core/src/main/java/org/hibernate/sql/results/spi/DomainResultProducer.java rename to hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DomainResultProducer.java index d18d48b106..8e23f47d34 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/DomainResultProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DomainResultProducer.java @@ -4,23 +4,45 @@ * 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.sql.results.spi; +package org.hibernate.query.sqm.sql.internal; import java.util.function.Consumer; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.metamodel.model.mapping.spi.SqlExpressableType; +import org.hibernate.metamodel.mapping.SqlExpressableType; +import org.hibernate.sql.results.spi.DomainResult; +import org.hibernate.sql.results.spi.DomainResultCreationState; import org.hibernate.type.spi.TypeConfiguration; /** - * Represents something that can produce a {@link DomainResult} - * instances which can be used as selection items and - * dynamic-instantiation args in a domain query. + * Something that can produce a DomainResult as part of a SQM interpretation * * @author Steve Ebersole */ public interface DomainResultProducer { + // this has to be designed as a bridge, but more geared toward the SQL + + /* + * select p.name, p2.name from Person p, Person p2 + * + * SqmPathSource (SqmExpressable) (unmapped) + * + * DomainType + * SimpleDomainType + * ... + * + * MappingType + * + * + * + * ValueMapping (mapped) + * + * + * ModelPartContainer personMapping = ...; + * personMapping.getValueMapping( "name" ); + */ + /** * Visit all of the SqlExpressableTypes associated with this this Readable. * @@ -35,7 +57,7 @@ public interface DomainResultProducer { */ default DomainResult createDomainResult( String resultVariable, - DomainResultCreationState creationState){ + DomainResultCreationState creationState) { throw new NotYetImplementedFor6Exception( getClass() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DynamicInstantiation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DynamicInstantiation.java index ef6ecbfe58..b7c8fc22f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DynamicInstantiation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DynamicInstantiation.java @@ -20,7 +20,6 @@ import org.hibernate.sql.results.spi.AssemblerCreationState; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultAssembler; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.jboss.logging.Logger; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DynamicInstantiationArgument.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DynamicInstantiationArgument.java index a7b0f43f98..dd8d6a4d6b 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DynamicInstantiationArgument.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/DynamicInstantiationArgument.java @@ -7,7 +7,6 @@ package org.hibernate.query.sqm.sql.internal; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQuerySpecProcessingStateImpl.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQuerySpecProcessingStateImpl.java index 64c6ac2c2a..68f5a350ed 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQuerySpecProcessingStateImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqlAstQuerySpecProcessingStateImpl.java @@ -17,7 +17,6 @@ import org.hibernate.sql.ast.Clause; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.ast.tree.select.QuerySpec; -import org.hibernate.sql.results.spi.DomainResult; /** * @author Steve Ebersole @@ -28,7 +27,6 @@ public class SqlAstQuerySpecProcessingStateImpl private final QuerySpec querySpec; - private final Supplier> domainResultConsumerSupplier; private final Supplier> sqlSelectionConsumerSupplier; public SqlAstQuerySpecProcessingStateImpl( @@ -37,11 +35,9 @@ public class SqlAstQuerySpecProcessingStateImpl SqlAstCreationState creationState, Supplier currentClauseAccess, Supplier> resolvedExpressionConsumerAccess, - Supplier> domainResultConsumerSupplier, Supplier> sqlSelectionConsumerSupplier) { super( parent, creationState, currentClauseAccess, resolvedExpressionConsumerAccess ); this.querySpec = querySpec; - this.domainResultConsumerSupplier = domainResultConsumerSupplier; this.sqlSelectionConsumerSupplier = sqlSelectionConsumerSupplier; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmExpressionInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmExpressionInterpretation.java new file mode 100644 index 0000000000..de85c4b6a7 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmExpressionInterpretation.java @@ -0,0 +1,30 @@ +/* + * 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.query.sqm.sql.internal; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.sql.SqlAstCreationState; +import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; +import org.hibernate.sql.ast.tree.expression.Expression; + +/** + * The interpretation of an SqmExpression as part of the SQM -> SQL conversion. + * + * Allows multi-column navigable references to be used anywhere a (SqlExpression) + * can be. The trick is to properly define methods on this interface for how the + * thing should be rendered into the SQL AST. + * + * @author Steve Ebersole + */ +public interface SqmExpressionInterpretation extends SqmSelectableInterpretation { + SqmExpressable getExpressableType(); + + default Expression toSqlExpression(SqmToSqlAstConverter walker, SqlAstCreationState sqlAstCreationState) { + throw new NotYetImplementedFor6Exception( getClass() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmPathInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmPathInterpretation.java new file mode 100644 index 0000000000..c4eef79cf0 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmPathInterpretation.java @@ -0,0 +1,69 @@ +/* + * 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.query.sqm.sql.internal; + +import java.util.List; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.metamodel.model.domain.internal.BasicSqmPathSource; +import org.hibernate.query.NavigablePath; +import org.hibernate.query.sqm.SqmPathSource; +import org.hibernate.query.sqm.sql.ConversionException; +import org.hibernate.query.sqm.sql.SqlAstCreationState; +import org.hibernate.sql.ast.tree.expression.Expression; +import org.hibernate.sql.ast.tree.expression.SqlTuple; +import org.hibernate.sql.ast.tree.from.TableGroup; + +/** + * @author Steve Ebersole + */ +public interface SqmPathInterpretation extends SqmExpressionInterpretation { + NavigablePath getNavigablePath(); + + @Override + default SqmPathSource getExpressableType() { + return getSqmPathSource(); + } + + SqmPathSource getSqmPathSource(); + + @Override + default Expression toSqlExpression(SqlAstCreationState sqlAstCreationState) { + throw new NotYetImplementedFor6Exception( getClass() ); +// final TableGroup tableGroup; +// +// if ( getSqmPathSource() instanceof BasicSqmPathSource ) { +// // maybe we should register the LHS TableGroup for the basic value +// // under its NavigablePath, similar to what we do for embeddables +// tableGroup = sqlAstCreationState.getFromClauseAccess().findTableGroup( getNavigablePath().getParent() ); +// } +// else { +// // for embeddable-, entity- and plural-valued Navigables we maybe do not have a TableGroup +// final TableGroup thisTableGroup = sqlAstCreationState.getFromClauseAccess().findTableGroup( getNavigablePath() ); +// if ( thisTableGroup != null ) { +// tableGroup = thisTableGroup; +// } +// else { +// final NavigablePath lhsNavigablePath = getNavigablePath().getParent(); +// if ( lhsNavigablePath == null ) { +// throw new ConversionException( "Could not find TableGroup to use - " + getNavigablePath().getFullPath() ); +// } +// tableGroup = sqlAstCreationState.getFromClauseAccess().findTableGroup( lhsNavigablePath ); +// } +// } +// +// sqlAstCreationState.getCreationContext().getDomainModel().resolveMappingExpressable( ) +// +// final List list = getNavigable().resolveColumnReferences( tableGroup, sqlAstCreationState ); +// if ( list.size() == 1 ) { +// assert list.get( 0 ) instanceof Expression; +// return (Expression) list.get( 0 ); +// } +// +// return new SqlTuple( list, sqlAstCreationState.getExpressableType() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSelectToSqlAstConverter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSelectToSqlAstConverter.java index 403f2891b0..d4492fff48 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSelectToSqlAstConverter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSelectToSqlAstConverter.java @@ -31,7 +31,6 @@ import org.hibernate.query.spi.QueryParameterBindings; import org.hibernate.query.sqm.internal.DomainParameterXref; import org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter; import org.hibernate.query.sqm.sql.SqlAstCreationState; -import org.hibernate.query.sqm.sql.SqlAstQuerySpecProcessingState; import org.hibernate.query.sqm.tree.expression.SqmEnumLiteral; import org.hibernate.query.sqm.tree.expression.SqmFieldLiteral; import org.hibernate.query.sqm.tree.expression.SqmLiteralEntityType; @@ -51,12 +50,10 @@ import org.hibernate.sql.ast.tree.from.TableGroup; import org.hibernate.sql.ast.tree.from.TableGroupJoin; import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer; import org.hibernate.sql.ast.tree.select.QuerySpec; -import org.hibernate.sql.ast.tree.select.SelectClause; import org.hibernate.sql.ast.tree.select.SelectStatement; import org.hibernate.sql.results.spi.CircularFetchDetector; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; import org.hibernate.sql.results.spi.Fetch; import org.hibernate.sql.results.spi.FetchParent; import org.hibernate.sql.results.spi.Fetchable; @@ -74,6 +71,8 @@ public class SqmSelectToSqlAstConverter implements DomainResultCreationState { private final CircularFetchDetector circularFetchDetector = new CircularFetchDetector(); + private final List domainResults = new ArrayList<>(); + public SqmSelectToSqlAstConverter( QueryOptions queryOptions, DomainParameterXref domainParameterXref, @@ -111,41 +110,36 @@ public class SqmSelectToSqlAstConverter public SelectStatement visitSelectStatement(SqmSelectStatement statement) { final QuerySpec querySpec = visitQuerySpec( statement.getQuerySpec() ); - return new SelectStatement( querySpec ); + return new SelectStatement( querySpec, domainResults ); } @Override public Void visitSelection(SqmSelection sqmSelection) { - // todo (6.0) : this should actually be able to generate multiple SqlSelections - final DomainResultProducer resultProducer = (DomainResultProducer) sqmSelection.getSelectableNode().accept( this ); + final DomainResultProducer resultProducer = resolveDomainResultProducer( sqmSelection ); if ( getProcessingStateStack().depth() > 1 ) { resultProducer.applySqlSelections( this ); } else { - final SelectClause selectClause = ( (SqlAstQuerySpecProcessingState) getCurrentProcessingState() ) - .getInflightQuerySpec() - .getSelectClause(); final DomainResult domainResult = resultProducer.createDomainResult( sqmSelection.getAlias(), this ); - selectClause - .addSelection( domainResult ); + domainResults.add( domainResult ); } return null; } - private int fetchDepth = 0; - - private int currentFetchDepth() { - return fetchDepth; + private DomainResultProducer resolveDomainResultProducer(SqmSelection sqmSelection) { + return ( (SqmExpressionInterpretation) sqmSelection.getSelectableNode() ).getDomainResultProducer( this, this ); } + private int fetchDepth = 0; + @Override public List visitFetches(FetchParent fetchParent) { final List fetches = new ArrayList(); @@ -394,24 +388,6 @@ public class SqmSelectToSqlAstConverter // .getOrMakeJavaDescriptor( namedClass ); } - @Override - public Object visitEnumLiteral(SqmEnumLiteral sqmEnumLiteral) { - return new QueryLiteral( - sqmEnumLiteral.getEnumValue(), - determineValueMapping( sqmEnumLiteral ), - getCurrentClauseStack().getCurrent() - ); - } - - @Override - public Object visitFieldLiteral(SqmFieldLiteral sqmFieldLiteral) { - return new QueryLiteral( - sqmFieldLiteral.getValue(), - determineValueMapping( sqmFieldLiteral ), - getCurrentClauseStack().getCurrent() - ); - } - // @Override // public SqlSelection resolveSqlSelection(Expression expression) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSelectableInterpretation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSelectableInterpretation.java new file mode 100644 index 0000000000..3233146f42 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSelectableInterpretation.java @@ -0,0 +1,20 @@ +/* + * 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.query.sqm.sql.internal; + +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.query.sqm.sql.SqlAstCreationState; +import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; + +/** + * @author Steve Ebersole + */ +public interface SqmSelectableInterpretation { + default DomainResultProducer getDomainResultProducer(SqmToSqlAstConverter walker, SqlAstCreationState sqlAstCreationState) { + throw new NotYetImplementedFor6Exception( getClass() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSqlHelper.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSqlHelper.java new file mode 100644 index 0000000000..c6b1f63b18 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/sql/internal/SqmSqlHelper.java @@ -0,0 +1,36 @@ +/* + * 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.query.sqm.sql.internal; + +import org.hibernate.metamodel.model.domain.EmbeddableDomainType; +import org.hibernate.query.sqm.sql.ConversionException; +import org.hibernate.query.sqm.sql.SqlAstCreationState; +import org.hibernate.query.sqm.tree.domain.SqmPath; +import org.hibernate.sql.ast.tree.from.TableGroup; + +/** + * @author Steve Ebersole + */ +@SuppressWarnings("WeakerAccess") +public class SqmSqlHelper { + private SqmSqlHelper() { + } + + public static TableGroup resolveTableGroup(SqmPath sqmPath, SqlAstCreationState creationState) { + SqmPath lhs = sqmPath; + while ( lhs.getReferencedPathSource().getSqmPathType() instanceof EmbeddableDomainType ) { + lhs = lhs.getLhs(); + } + + final TableGroup tableGroup = creationState.getFromClauseAccess().findTableGroup( lhs.getNavigablePath() ); + if ( tableGroup != null ) { + return tableGroup; + } + + throw new ConversionException( "Could not locate TableGroup to use : " + lhs.getNavigablePath() ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java index 3acf93a858..ce52b86855 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/AbstractSqmPath.java @@ -159,6 +159,8 @@ public abstract class AbstractSqmPath extends AbstractSqmExpression implem final DomainType sqmNodeType = getReferencedPathSource().getSqmPathType(); + final String mappingRoleName = getReferencedPathSource().getMappingRole() + '.' + discriminatorPathName; + if ( sqmNodeType instanceof EntityDomainType ) { final SqmPathSource discriminatorPathSource = new SqmPathSource() { @Override @@ -166,8 +168,14 @@ public abstract class AbstractSqmPath extends AbstractSqmExpression implem return discriminatorPathName; } + @Override + public String getMappingRole() { + return mappingRoleName; + } + @Override public DomainType getSqmPathType() { + // the BasicType for Class? return null; } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBasicValuedSimplePath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBasicValuedSimplePath.java index b992018f29..74fd191827 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBasicValuedSimplePath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmBasicValuedSimplePath.java @@ -11,10 +11,10 @@ import org.hibernate.query.NavigablePath; import org.hibernate.query.PathException; import org.hibernate.query.SemanticException; import org.hibernate.query.hql.spi.SemanticPathPart; -import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.SqmPathSource; -import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmPathSource; import org.hibernate.type.descriptor.java.BasicJavaDescriptor; /** diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java index 73da1e30f8..fc726dfb66 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmMapEntryReference.java @@ -20,7 +20,7 @@ import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.tree.select.SqmSelectableNode; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -84,11 +84,6 @@ public class SqmMapEntryReference return walker.visitMapEntryFunction( this ); } - @Override - public DomainResultProducer> getDomainResultProducer() { - return this; - } - @Override public void visitSubSelectableNodes(Consumer> jpaSelectionConsumer) { } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPath.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPath.java index 38475c26dd..1f7ed1f8eb 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPath.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmPath.java @@ -15,13 +15,12 @@ import org.hibernate.query.PathException; import org.hibernate.query.SemanticException; import org.hibernate.query.criteria.JpaPath; import org.hibernate.query.hql.spi.SemanticPathPart; +import org.hibernate.query.hql.spi.SqmCreationState; import org.hibernate.query.sqm.ParsingException; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SqmPathSource; -import org.hibernate.query.hql.spi.SqmCreationState; import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.from.SqmRoot; -import org.hibernate.sql.results.spi.DomainResultProducer; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** @@ -31,7 +30,7 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; * * @author Steve Ebersole */ -public interface SqmPath extends SqmExpression, SemanticPathPart, JpaPath, DomainResultProducer { +public interface SqmPath extends SqmExpression, SemanticPathPart, JpaPath { /** * Returns the NavigablePath. @@ -46,11 +45,6 @@ public interface SqmPath extends SqmExpression, SemanticPathPart, JpaPath< */ SqmPathSource getReferencedPathSource(); - @Override - default DomainResultProducer getDomainResultProducer() { - return this; - } - /** * Retrieve the explicit alias, if one. May return null */ diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java index 71c4b4f5a2..cb93861ace 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/domain/SqmSingularJoin.java @@ -11,15 +11,17 @@ import java.util.function.Consumer; import org.hibernate.HibernateException; import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.metamodel.mapping.SqlExpressableType; import org.hibernate.metamodel.model.domain.EmbeddableDomainType; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.metamodel.model.domain.ManagedDomainType; import org.hibernate.metamodel.model.domain.SingularPersistentAttribute; -import org.hibernate.metamodel.model.mapping.spi.SqlExpressableType; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.PathException; -import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.hql.spi.SqmCreationProcessingState; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.query.sqm.tree.SqmJoinType; import org.hibernate.query.sqm.tree.from.SqmAttributeJoin; import org.hibernate.query.sqm.tree.from.SqmFrom; @@ -30,7 +32,7 @@ import org.hibernate.type.spi.TypeConfiguration; /** * @author Steve Ebersole */ -public class SqmSingularJoin extends AbstractSqmAttributeJoin { +public class SqmSingularJoin extends AbstractSqmAttributeJoin implements DomainResultProducer { public SqmSingularJoin( SqmFrom lhs, SingularPersistentAttribute joinedNavigable, @@ -98,7 +100,7 @@ public class SqmSingularJoin extends AbstractSqmAttributeJoin { final EntityPersister entityDescriptor = typeConfiguration.getSessionFactory() .getMetamodel() .getEntityDescriptor( entityName ); - entityDescriptor.visitValueMappings( + entityDescriptor.visitSubParts( valueMapping -> valueMapping.getBindable().visitJdbcTypes( action, Clause.IRRELEVANT, diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java index f80f6c53ba..3b97618ae6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/AbstractSqmExpression.java @@ -31,6 +31,11 @@ public abstract class AbstractSqmExpression extends AbstractJpaSelection i super( type, criteriaBuilder ); } + @Override + public SqmExpressable getExpressableType() { + return getNodeType(); + } + @Override public final void applyInferableType(SqmExpressable type) { if ( type == null ) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmBinaryArithmetic.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmBinaryArithmetic.java index 99f0cd2d72..84b6af0a30 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmBinaryArithmetic.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmBinaryArithmetic.java @@ -9,14 +9,14 @@ package org.hibernate.query.sqm.tree.expression; import org.hibernate.metamodel.model.domain.JpaMetamodel; import org.hibernate.query.BinaryArithmeticOperator; import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.tree.select.SqmSelectableNode; /** * @author Steve Ebersole */ -public class SqmBinaryArithmetic extends AbstractSqmExpression implements DomainResultProducer { +public class SqmBinaryArithmetic extends AbstractSqmExpression implements SqmSelectableNode { private final SqmExpression lhsOperand; private final BinaryArithmeticOperator operator; private final SqmExpression rhsOperand; @@ -106,8 +106,4 @@ public class SqmBinaryArithmetic extends AbstractSqmExpression implements return getOperator().toLoggableText( lhsOperand.asLoggableText(), rhsOperand.asLoggableText() ); } - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCaseSearched.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCaseSearched.java index 7f6c57e3e4..a07591fbdf 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCaseSearched.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCaseSearched.java @@ -16,7 +16,7 @@ import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * @author Steve Ebersole @@ -126,8 +126,4 @@ public class SqmCaseSearched return this; } - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCaseSimple.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCaseSimple.java index 50f902dfac..a6e433909a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCaseSimple.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCaseSimple.java @@ -16,7 +16,7 @@ import org.hibernate.query.criteria.JpaSimpleCase; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * @author Steve Ebersole @@ -139,8 +139,4 @@ public class SqmCaseSimple return this; } - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCollectionSize.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCollectionSize.java index 342e07cecf..dacfc2441a 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCollectionSize.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCollectionSize.java @@ -10,7 +10,7 @@ import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.tree.domain.SqmPath; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.type.StandardBasicTypes; /** @@ -45,12 +45,7 @@ public class SqmCollectionSize extends AbstractSqmExpression implements return "SIZE(" + pluralPath.asLoggableText() + ")"; } - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } - -// @Override + // @Override // public DomainResult createDomainResult( // String resultVariable, // DomainResultCreationState creationState) { diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCriteriaParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCriteriaParameter.java index 387b4efa64..f7173572d8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCriteriaParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmCriteriaParameter.java @@ -14,7 +14,7 @@ import org.hibernate.query.spi.QueryParameterImplementor; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * SqmParameter created via JPA {@link javax.persistence.criteria.CriteriaBuilder} @@ -121,9 +121,4 @@ public class SqmCriteriaParameter public NamedCallableQueryMemento.ParameterMemento toMemento() { throw new UnsupportedOperationException( "ParameterMemento cannot be extracted from Criteria query parameter" ); } - - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEntityType.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEntityType.java index 6b8b12fa20..ed9e30ae74 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEntityType.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEntityType.java @@ -8,17 +8,17 @@ package org.hibernate.query.sqm.tree.expression; import org.hibernate.metamodel.model.domain.EntityDomainType; import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.domain.SqmPath; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.tree.select.SqmSelectableNode; /** * Entity type expression based on a parameter - `TYPE( :someParam )` * * @author Steve Ebersole */ -public class SqmEntityType extends AbstractSqmExpression implements DomainResultProducer { +public class SqmEntityType extends AbstractSqmExpression implements SqmSelectableNode { private final SqmExpression discriminatorSource; public SqmEntityType(SqmParameter parameterExpression, NodeBuilder nodeBuilder) { @@ -45,10 +45,4 @@ public class SqmEntityType extends AbstractSqmExpression implements Domain return walker.visitParameterizedEntityTypeExpression( this ); } - @Override - public DomainResultProducer getDomainResultProducer() { - // technically `T` should be `Class` here - return this; - } - } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEnumLiteral.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEnumLiteral.java index de3e5f2f20..0bc4bd8e3f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEnumLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmEnumLiteral.java @@ -16,13 +16,12 @@ import javax.persistence.criteria.Expression; import org.hibernate.query.SemanticException; import org.hibernate.query.criteria.JpaSelection; import org.hibernate.query.hql.spi.SemanticPathPart; -import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.SqmExpressable; -import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; -import org.hibernate.sql.results.spi.DomainResultProducer; import org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -32,7 +31,7 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; * * @author Steve Ebersole */ -public class SqmEnumLiteral implements SqmExpression, SqmExpressable, DomainResultProducer, SemanticPathPart { +public class SqmEnumLiteral implements SqmExpression, SqmExpressable, SemanticPathPart { private final Enum enumValue; private final EnumJavaTypeDescriptor referencedEnumTypeDescriptor; private final String enumValueName; @@ -66,6 +65,11 @@ public class SqmEnumLiteral implements SqmExpression, SqmExpressable return referencedEnumTypeDescriptor; } + @Override + public SqmExpressable getExpressableType() { + return expressable; + } + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // SemanticPathPart @@ -216,9 +220,4 @@ public class SqmEnumLiteral implements SqmExpression, SqmExpressable public String getAlias() { return null; } - - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java index ebeb50bd5b..55599c7524 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmExpression.java @@ -16,6 +16,7 @@ import org.hibernate.metamodel.model.domain.AllowableFunctionReturnType; import org.hibernate.metamodel.model.domain.DomainType; import org.hibernate.query.criteria.JpaExpression; import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.sql.internal.SqmExpressionInterpretation; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; import org.hibernate.query.sqm.tree.select.SqmSelectableNode; @@ -28,7 +29,7 @@ import org.hibernate.query.sqm.tree.select.SqmSelectableNode; * * @author Steve Ebersole */ -public interface SqmExpression extends SqmSelectableNode, JpaExpression { +public interface SqmExpression extends SqmSelectableNode, JpaExpression, SqmExpressionInterpretation { /** * The expression's type. * diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java index b2760fb5dc..05695281df 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmFieldLiteral.java @@ -18,19 +18,19 @@ import org.hibernate.QueryException; import org.hibernate.query.SemanticException; import org.hibernate.query.criteria.JpaSelection; import org.hibernate.query.hql.spi.SemanticPathPart; -import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.SqmExpressable; -import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.tree.select.SqmSelectableNode; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** * @author Steve Ebersole */ -public class SqmFieldLiteral implements SqmExpression, SqmExpressable, DomainResultProducer, SemanticPathPart { +public class SqmFieldLiteral implements SqmExpression, SqmExpressable, SqmSelectableNode, SemanticPathPart { private final T value; private final JavaTypeDescriptor fieldJavaTypeDescriptor; private final String fieldName; @@ -77,6 +77,11 @@ public class SqmFieldLiteral implements SqmExpression, SqmExpressable, return value; } + @Override + public SqmExpressable getExpressableType() { + return expressable; + } + public JavaTypeDescriptor getFieldJavaTypeDescriptor() { return fieldJavaTypeDescriptor; } @@ -252,8 +257,4 @@ public class SqmFieldLiteral implements SqmExpression, SqmExpressable, return null; } - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java index d13ec0b42f..cdbac64e99 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteral.java @@ -9,7 +9,7 @@ package org.hibernate.query.sqm.tree.expression; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * Represents a literal value in the sqm, e.g.
    @@ -45,8 +45,4 @@ public class SqmLiteral return "Literal( " + value + ")"; } - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteralEntityType.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteralEntityType.java index bbf48e2633..84df7e61af 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteralEntityType.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmLiteralEntityType.java @@ -7,14 +7,14 @@ package org.hibernate.query.sqm.tree.expression; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.query.hql.spi.SemanticPathPart; -import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.SqmExpressable; -import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.hql.HqlInterpretationException; +import org.hibernate.query.hql.spi.SemanticPathPart; import org.hibernate.query.hql.spi.SqmCreationState; +import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.domain.SqmPath; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.tree.select.SqmSelectableNode; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** @@ -28,7 +28,7 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; */ public class SqmLiteralEntityType extends AbstractSqmExpression - implements DomainResultProducer, SemanticPathPart { + implements SqmSelectableNode, SemanticPathPart { private final EntityDomainType entityType; public SqmLiteralEntityType(EntityDomainType entityType, NodeBuilder nodeBuilder) { @@ -85,9 +85,4 @@ public class SqmLiteralEntityType throw new HqlInterpretationException( "Cannot dereference an entity name" ); } - @Override - public DomainResultProducer getDomainResultProducer() { - // technically `T` should be `Class` here - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmNamedParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmNamedParameter.java index 278eccd1cc..f53be36250 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmNamedParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmNamedParameter.java @@ -9,7 +9,6 @@ package org.hibernate.query.sqm.tree.expression; import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * Represents a named query parameter in the SQM tree. @@ -37,11 +36,6 @@ public class SqmNamedParameter extends AbstractSqmParameter { return walker.visitNamedParameterExpression( this ); } - @Override - public DomainResultProducer getDomainResultProducer() { - throw new UnsupportedOperationException( ); - } - @Override public String asLoggableText() { return ":" + getName(); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmPositionalParameter.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmPositionalParameter.java index 805b01ae52..16bab7cfe8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmPositionalParameter.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmPositionalParameter.java @@ -9,7 +9,6 @@ package org.hibernate.query.sqm.tree.expression; import org.hibernate.metamodel.model.domain.AllowableParameterType; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * Models a positional parameter expression @@ -55,8 +54,4 @@ public class SqmPositionalParameter extends AbstractSqmParameter { return "?" + getPosition(); } - @Override - public DomainResultProducer getDomainResultProducer() { - throw new UnsupportedOperationException( ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmRestrictedSubQueryExpression.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmRestrictedSubQueryExpression.java index d96d7dc728..2c1d21424c 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmRestrictedSubQueryExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmRestrictedSubQueryExpression.java @@ -7,10 +7,9 @@ package org.hibernate.query.sqm.tree.expression; import org.hibernate.query.sqm.NodeBuilder; +import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.select.SqmSubQuery; -import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * Represents a {@link Modifier#ALL}, {@link Modifier#ANY}, {@link Modifier#SOME} modifier appplied to a subquery as @@ -62,9 +61,4 @@ public class SqmRestrictedSubQueryExpression extends AbstractSqmExpression public X accept(SemanticQueryWalker walker) { return walker.visitRestrictedSubQueryExpression( this ); } - - @Override - public DomainResultProducer getDomainResultProducer() { - return subQuery.getDomainResultProducer(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmTuple.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmTuple.java index f3610e3e8e..7a1652d204 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmTuple.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmTuple.java @@ -6,6 +6,7 @@ */ package org.hibernate.query.sqm.tree.expression; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -13,10 +14,15 @@ import org.hibernate.QueryException; import org.hibernate.query.criteria.JpaCompoundSelection; import org.hibernate.query.criteria.JpaSelection; import org.hibernate.query.sqm.NodeBuilder; -import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.sql.SqlAstCreationState; +import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.SqmExpressionInterpretation; import org.hibernate.query.sqm.tree.select.SqmJpaCompoundSelection; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.sql.ast.tree.expression.Expression; +import org.hibernate.sql.ast.tree.expression.SqlTuple; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** @@ -29,7 +35,9 @@ import org.hibernate.type.descriptor.java.JavaTypeDescriptor; * * @author Steve Ebersole */ -public class SqmTuple extends AbstractSqmExpression implements JpaCompoundSelection { +public class SqmTuple + extends AbstractSqmExpression + implements JpaCompoundSelection, SqmExpressionInterpretation { private final List> groupedExpressions; public SqmTuple(NodeBuilder nodeBuilder, SqmExpression... groupedExpressions) { @@ -77,6 +85,36 @@ public class SqmTuple extends AbstractSqmExpression implements JpaCompound return walker.visitTuple( this ); } + @Override + public Expression toSqlExpression( + SqmToSqlAstConverter walker, + SqlAstCreationState sqlAstCreationState) { + final List groupedSqlExpressions = new ArrayList<>(); + + for ( SqmExpression groupedExpression : groupedExpressions ) { + final SqmExpressionInterpretation interpretation = (SqmExpressionInterpretation) groupedExpression.accept( walker ); + final Expression sqlExpression = interpretation.toSqlExpression( + walker, + sqlAstCreationState + ); + + groupedSqlExpressions.add( sqlExpression ); + } + + return new SqlTuple( + groupedSqlExpressions, + sqlAstCreationState.getCreationContext().getDomainModel() + .resolveMappingExpressable( getExpressableType() ) + ); + } + + @Override + public DomainResultProducer getDomainResultProducer( + SqmToSqlAstConverter walker, + SqlAstCreationState sqlAstCreationState) { + return null; + } + @Override public String asLoggableText() { return toString(); @@ -97,9 +135,4 @@ public class SqmTuple extends AbstractSqmExpression implements JpaCompound return groupedExpressions; } - @Override - public DomainResultProducer getDomainResultProducer() { - // could technically return an array I guess - throw new UnsupportedOperationException(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmUnaryOperation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmUnaryOperation.java index eb4f614f97..1c779a6bc3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmUnaryOperation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/expression/SqmUnaryOperation.java @@ -7,14 +7,14 @@ package org.hibernate.query.sqm.tree.expression; import org.hibernate.query.UnaryArithmeticOperator; -import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.tree.select.SqmSelectableNode; /** * @author Steve Ebersole */ -public class SqmUnaryOperation extends AbstractSqmExpression implements DomainResultProducer { +public class SqmUnaryOperation extends AbstractSqmExpression implements SqmSelectableNode { private final UnaryArithmeticOperator operation; private final SqmExpression operand; @@ -41,11 +41,6 @@ public class SqmUnaryOperation extends AbstractSqmExpression implements Do return operation; } - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } - @Override public X accept(SemanticQueryWalker walker) { return walker.visitUnaryOperationExpression( this ); diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmRoot.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmRoot.java index a10e9eb2d9..f62ae432e3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmRoot.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/from/SqmRoot.java @@ -8,18 +8,24 @@ package org.hibernate.query.sqm.tree.from; import java.util.function.Consumer; +import org.hibernate.NotYetImplementedFor6Exception; +import org.hibernate.metamodel.mapping.SqlExpressableType; import org.hibernate.metamodel.model.domain.EntityDomainType; -import org.hibernate.metamodel.model.mapping.spi.SqlExpressableType; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.query.PathException; import org.hibernate.query.criteria.JpaRoot; import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; +import org.hibernate.query.sqm.SqmExpressable; +import org.hibernate.query.sqm.sql.SqlAstCreationState; +import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.query.sqm.tree.domain.AbstractSqmFrom; import org.hibernate.query.sqm.tree.domain.SqmPath; import org.hibernate.query.sqm.tree.domain.SqmTreatedPath; import org.hibernate.query.sqm.tree.domain.SqmTreatedRoot; import org.hibernate.sql.ast.Clause; +import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -28,7 +34,7 @@ import org.hibernate.type.spi.TypeConfiguration; /** * @author Steve Ebersole */ -public class SqmRoot extends AbstractSqmFrom implements JpaRoot { +public class SqmRoot extends AbstractSqmFrom implements JpaRoot, DomainResultProducer { public SqmRoot( EntityDomainType entityType, String alias, @@ -97,13 +103,27 @@ public class SqmRoot extends AbstractSqmFrom implements JpaRoot { return new SqmTreatedRoot<>( this, treatTarget, nodeBuilder() ); } + @Override + public DomainResultProducer getDomainResultProducer( + SqmToSqlAstConverter walker, + SqlAstCreationState sqlAstCreationState) { + return this; + } + + @Override + public Expression toSqlExpression( + SqmToSqlAstConverter walker, + SqlAstCreationState sqlAstCreationState) { + throw new NotYetImplementedFor6Exception( getClass() ); + } + @Override public void visitJdbcTypes(Consumer action, TypeConfiguration typeConfiguration) { final String entityName = getReferencedPathSource().getHibernateEntityName(); final EntityPersister entityDescriptor = typeConfiguration.getSessionFactory() .getMetamodel() .getEntityDescriptor( entityName ); - entityDescriptor.visitValueMappings( + entityDescriptor.visitSubParts( valueMapping -> valueMapping.getBindable().visitJdbcTypes( action, Clause.IRRELEVANT, @@ -112,6 +132,7 @@ public class SqmRoot extends AbstractSqmFrom implements JpaRoot { ); } + @Override public DomainResult createDomainResult( String resultVariable, @@ -123,6 +144,7 @@ public class SqmRoot extends AbstractSqmFrom implements JpaRoot { .getEntityDescriptor( entityName ); return entityDescriptor.createDomainResult( getNavigablePath(), + creationState.getSqlAstCreationState().getFromClauseAccess().findTableGroup( getNavigablePath() ), resultVariable, creationState ); @@ -135,7 +157,11 @@ public class SqmRoot extends AbstractSqmFrom implements JpaRoot { .getCreationContext() .getDomainModel() .getEntityDescriptor( entityName ); - entityDescriptor.applySqlSelections( getNavigablePath(), creationState ); + entityDescriptor.applySqlSelections( + getNavigablePath(), + creationState.getSqlAstCreationState().getFromClauseAccess().findTableGroup( getNavigablePath() ), + creationState + ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/predicate/SqmPredicate.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/predicate/SqmPredicate.java index ab2a2986c4..207ed5392d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/predicate/SqmPredicate.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/predicate/SqmPredicate.java @@ -9,7 +9,7 @@ package org.hibernate.query.sqm.tree.predicate; import org.hibernate.query.criteria.JpaPredicate; import org.hibernate.query.sqm.tree.SqmVisitableNode; import org.hibernate.query.sqm.tree.expression.SqmExpression; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.type.descriptor.java.BooleanTypeDescriptor; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -26,8 +26,4 @@ public interface SqmPredicate @Override SqmPredicate not(); - @Override - default DomainResultProducer getDomainResultProducer() { - return this; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java index 67a1427426..0b55761fb2 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java @@ -48,6 +48,7 @@ public abstract class AbstractSqmSelectQuery this.resultType = sqmQuerySpec.getSelectClause().getJavaType(); } + @Override public Class getResultType() { return resultType; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmAliasedNode.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmAliasedNode.java index 929c0e1c8a..5fd77c5753 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmAliasedNode.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmAliasedNode.java @@ -8,7 +8,7 @@ package org.hibernate.query.sqm.tree.select; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.tree.SqmTypedNode; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * Models any aliased expression. E.g. `select exp as e ...` diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiation.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiation.java index 2c09d3a859..97c35fae7e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiation.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmDynamicInstantiation.java @@ -18,7 +18,7 @@ import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.jpa.AbstractJpaSelection; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; import org.jboss.logging.Logger; @@ -118,11 +118,6 @@ public class SqmDynamicInstantiation return getInstantiationTarget().getTargetTypeDescriptor(); } - @Override - public DomainResultProducer getDomainResultProducer() { - return this; - } - @Override public String asLoggableText() { return ""; diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmJpaCompoundSelection.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmJpaCompoundSelection.java index 5411dc8f69..25fa6c205d 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmJpaCompoundSelection.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmJpaCompoundSelection.java @@ -16,7 +16,7 @@ import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.SqmExpressable; import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.tree.expression.AbstractSqmExpression; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** @@ -109,9 +109,4 @@ public class SqmJpaCompoundSelection return walker.visitJpaCompoundSelection( this ); } - @Override - public DomainResultProducer getDomainResultProducer() { - // could technically return an array I guess. See `SqmTuple` - throw new UnsupportedOperationException( ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectableNode.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectableNode.java index 40b0fb97ab..81b1da9ce8 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectableNode.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSelectableNode.java @@ -9,10 +9,14 @@ package org.hibernate.query.sqm.tree.select; import java.util.function.Consumer; import javax.persistence.criteria.Selection; +import org.hibernate.NotYetImplementedFor6Exception; import org.hibernate.query.criteria.JpaSelection; +import org.hibernate.query.sqm.sql.SqlAstCreationState; +import org.hibernate.query.sqm.sql.SqmToSqlAstConverter; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.SqmSelectableInterpretation; import org.hibernate.query.sqm.tree.SqmTypedNode; import org.hibernate.query.sqm.tree.SqmVisitableNode; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * Defines a SQM AST node that can be used as a selection in the query, @@ -20,12 +24,7 @@ import org.hibernate.sql.results.spi.DomainResultProducer; * * @author Steve Ebersole */ -public interface SqmSelectableNode extends JpaSelection, SqmTypedNode, SqmVisitableNode { - /** - * Get the DomainResultProducer for this SqmSelectableNode - */ - DomainResultProducer getDomainResultProducer(); - +public interface SqmSelectableNode extends JpaSelection, SqmTypedNode, SqmVisitableNode, SqmSelectableInterpretation { /** * Visit each of this selectable's direct sub-selectables - used to * support JPA's {@link Selection} model (which is really a "selectable", @@ -35,4 +34,8 @@ public interface SqmSelectableNode extends JpaSelection, SqmTypedNode, * @see Selection#getCompoundSelectionItems() */ void visitSubSelectableNodes(Consumer> jpaSelectionConsumer); + + default DomainResultProducer getDomainResultProducer(SqmToSqlAstConverter walker, SqlAstCreationState sqlAstCreationState) { + throw new NotYetImplementedFor6Exception( getClass() ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java index 9beed1193a..7b8a90b449 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java +++ b/hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/SqmSubQuery.java @@ -37,7 +37,6 @@ import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.from.SqmRoot; import org.hibernate.query.sqm.tree.predicate.SqmInPredicate; import org.hibernate.query.sqm.tree.predicate.SqmPredicate; -import org.hibernate.sql.results.spi.DomainResultProducer; import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.descriptor.java.JavaTypeDescriptor; @@ -73,6 +72,11 @@ public class SqmSubQuery extends AbstractSqmSelectQuery implements SqmSele this.parent = parent; } + @Override + public SqmExpressable getExpressableType() { + return expressableType; + } + @Override public SqmQuery getContainingQuery() { return parent; @@ -313,8 +317,4 @@ public class SqmSubQuery extends AbstractSqmSelectQuery implements SqmSele return walker.visitSubQueryExpression( this ); } - @Override - public DomainResultProducer getDomainResultProducer() { - throw new NotYetImplementedFor6Exception( getClass() ); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/ValueMappingExpressable.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/ValueMappingExpressable.java deleted file mode 100644 index a620ecaeb3..0000000000 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/ValueMappingExpressable.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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.sql.ast; - -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; - -/** - * Something that is expressable at the mapping-model type level as a type for - * `SqlExpression` whether the SQL AST node is simple or compound. - * - * todo (6.0) : in that case it seems like `SqlExpression` should be a `ValueMappingExpressable`. `SqlTuple` is - * a special case for compound expressions - the `ValueMapping` would be the "composite type" - * - * todo (6.0) : does adding a SqlAstExpressionProducer make sense? - * - * @author Steve Ebersole - */ -public interface ValueMappingExpressable { - /** - * The ValueMapping for this expressable - */ - ValueMapping getExpressableValueMapping(); -} diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/AbstractLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/AbstractLiteral.java index 3fbed34d42..a3ce44ff94 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/AbstractLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/AbstractLiteral.java @@ -10,15 +10,14 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; +import org.hibernate.metamodel.mapping.MappingModelExpressable; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.sql.ast.Clause; -import org.hibernate.sql.ast.ValueMappingExpressable; import org.hibernate.sql.exec.spi.ExecutionContext; import org.hibernate.sql.exec.spi.JdbcParameterBinder; import org.hibernate.sql.exec.spi.JdbcParameterBindings; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * We classify literals different based on their source so that we can handle then differently @@ -29,12 +28,12 @@ import org.hibernate.sql.results.spi.DomainResultProducer; * @author Steve Ebersole */ public abstract class AbstractLiteral - implements JdbcParameterBinder, Expression, ValueMappingExpressable, DomainResultProducer { + implements JdbcParameterBinder, Expression, DomainResultProducer { private final Object value; - private final ValueMappingExpressable type; + private final MappingModelExpressable type; private final Clause clause; - public AbstractLiteral(Object value, ValueMappingExpressable type, Clause clause) { + public AbstractLiteral(Object value, MappingModelExpressable type, Clause clause) { this.value = value; this.type = type; this.clause = clause; @@ -44,15 +43,15 @@ public abstract class AbstractLiteral return value; } - @Override - public ValueMapping getExpressableValueMapping() { - return type.getExpressableValueMapping(); - } - public boolean isInSelect() { return clause == Clause.SELECT; } + @Override + public MappingModelExpressable getExpressionType() { + return type; + } + @Override public DomainResult createDomainResult( String resultVariable, @@ -61,7 +60,6 @@ public abstract class AbstractLiteral } @Override - @SuppressWarnings("unchecked") public void bindParameterValue( PreparedStatement statement, int startPosition, @@ -70,9 +68,4 @@ public abstract class AbstractLiteral throw new NotYetImplementedFor6Exception( getClass() ); // getType().getJdbcValueBinder().bind( statement, startPosition, value, executionContext ); } - - @Override - public ValueMappingExpressable getExpressionType() { - return type; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/BinaryArithmeticExpression.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/BinaryArithmeticExpression.java index 9409ea5112..07f0624f68 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/BinaryArithmeticExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/BinaryArithmeticExpression.java @@ -4,32 +4,29 @@ * 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.sql.ast.tree.expression; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.query.BinaryArithmeticOperator; -import org.hibernate.sql.ast.ValueMappingExpressable; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.sql.ast.spi.SqlAstWalker; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * @author Steve Ebersole */ -public class BinaryArithmeticExpression - implements Expression, ValueMappingExpressable, DomainResultProducer { +public class BinaryArithmeticExpression implements Expression, DomainResultProducer { private final Expression lhsOperand; private final BinaryArithmeticOperator operator; private final Expression rhsOperand; - private final ValueMappingExpressable resultType; + private final MappingModelExpressable resultType; public BinaryArithmeticExpression( Expression lhsOperand, BinaryArithmeticOperator operator, Expression rhsOperand, - ValueMappingExpressable resultType) { + MappingModelExpressable resultType) { this.operator = operator; this.lhsOperand = lhsOperand; this.rhsOperand = rhsOperand; @@ -37,12 +34,7 @@ public class BinaryArithmeticExpression } @Override - public ValueMapping getExpressableValueMapping() { - return resultType.getExpressableValueMapping(); - } - - @Override - public ValueMappingExpressable getExpressionType() { + public MappingModelExpressable getExpressionType() { return resultType; } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSearchedExpression.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSearchedExpression.java index a5e5c5f06b..56fda9d115 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSearchedExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSearchedExpression.java @@ -11,24 +11,23 @@ import java.util.ArrayList; import java.util.List; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; -import org.hibernate.sql.ast.ValueMappingExpressable; +import org.hibernate.metamodel.mapping.MappingModelExpressable; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.sql.ast.spi.SqlAstWalker; import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * @author Steve Ebersole */ -public class CaseSearchedExpression implements Expression, ValueMappingExpressable, DomainResultProducer { - private final ValueMappingExpressable type; +public class CaseSearchedExpression implements Expression, DomainResultProducer { + private final MappingModelExpressable type; private List whenFragments = new ArrayList<>(); private Expression otherwise; - public CaseSearchedExpression(ValueMappingExpressable type) { + public CaseSearchedExpression(MappingModelExpressable type) { this.type = type; } @@ -72,15 +71,7 @@ public class CaseSearchedExpression implements Expression, ValueMappingExpressab } @Override - public ValueMapping getExpressableValueMapping() { - return null; - } - - @Override - public ValueMappingExpressable getExpressionType() { - if ( type == null ) { - return this; - } + public MappingModelExpressable getExpressionType() { return type; } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSimpleExpression.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSimpleExpression.java index a794861e77..189de5d1ca 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSimpleExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/CaseSimpleExpression.java @@ -11,24 +11,24 @@ import java.util.ArrayList; import java.util.List; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; -import org.hibernate.sql.ast.ValueMappingExpressable; +import org.hibernate.metamodel.mapping.MappingModelExpressable; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.sql.ast.spi.SqlAstWalker; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** * @author Steve Ebersole */ -public class CaseSimpleExpression implements Expression, ValueMappingExpressable, DomainResultProducer { - private final ValueMappingExpressable type; +public class CaseSimpleExpression implements Expression, DomainResultProducer { + private final MappingModelExpressable type; private final Expression fixture; private List whenFragments = new ArrayList<>(); private Expression otherwise; - public CaseSimpleExpression(ValueMappingExpressable type, Expression fixture) { + public CaseSimpleExpression(MappingModelExpressable type, Expression fixture) { this.type = type; this.fixture = fixture; } @@ -38,15 +38,10 @@ public class CaseSimpleExpression implements Expression, ValueMappingExpressable } @Override - public ValueMappingExpressable getExpressionType() { + public MappingModelExpressable getExpressionType() { return type; } - @Override - public ValueMapping getExpressableValueMapping() { - return type.getExpressableValueMapping(); - } - @Override public void accept(SqlAstWalker walker) { walker.visitCaseSimpleExpression( this ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ColumnReference.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ColumnReference.java index 0bb5e4df19..d5aa00a047 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ColumnReference.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/ColumnReference.java @@ -12,8 +12,8 @@ import java.util.Objects; import org.hibernate.boot.model.naming.Identifier; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.metamodel.model.mapping.spi.SqlExpressableType; -import org.hibernate.sql.ast.ValueMappingExpressable; +import org.hibernate.metamodel.mapping.MappingModelExpressable; +import org.hibernate.metamodel.mapping.SqlExpressableType; import org.hibernate.sql.ast.spi.SqlAstWalker; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.from.TableReference; @@ -78,8 +78,8 @@ public class ColumnReference implements Expression { } @Override - public ValueMappingExpressable getExpressionType() { - return (ValueMappingExpressable) sqlExpressableType; + public MappingModelExpressable getExpressionType() { + return (MappingModelExpressable) sqlExpressableType; } public String renderSqlFragment() { diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/EntityTypeLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/EntityTypeLiteral.java index de90041828..0e9b1c48a2 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/EntityTypeLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/EntityTypeLiteral.java @@ -6,10 +6,9 @@ */ package org.hibernate.sql.ast.tree.expression; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; +import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Queryable; -import org.hibernate.sql.ast.ValueMappingExpressable; import org.hibernate.sql.ast.spi.SqlAstWalker; import org.hibernate.type.Type; @@ -30,13 +29,9 @@ public class EntityTypeLiteral implements Expression { } @Override - public ValueMappingExpressable getExpressionType() { - return () -> new ValueMapping() { - @Override - public Type getValueType() { - return discriminatorType; - } - }; + public ModelPart getExpressionType() { + // todo (6.0) : entity descriptor or its discriminator descriptor? + return entityTypeDescriptor; } // @Override diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Expression.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Expression.java index 80a5e4e883..24825e982b 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Expression.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/Expression.java @@ -7,7 +7,7 @@ package org.hibernate.sql.ast.tree.expression; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.sql.ast.ValueMappingExpressable; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.spi.SqlSelectionProducer; import org.hibernate.sql.ast.tree.SqlAstNode; @@ -23,7 +23,7 @@ public interface Expression extends SqlAstNode, SqlSelectionProducer { /** * The type for this expression */ - ValueMappingExpressable getExpressionType(); + MappingModelExpressable getExpressionType(); @Override default SqlSelection createSqlSelection( diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java index f716696c92..5fe4d4614d 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/QueryLiteral.java @@ -6,8 +6,8 @@ */ package org.hibernate.sql.ast.tree.expression; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.sql.ast.Clause; -import org.hibernate.sql.ast.ValueMappingExpressable; import org.hibernate.sql.ast.spi.SqlAstWalker; /** @@ -16,7 +16,7 @@ import org.hibernate.sql.ast.spi.SqlAstWalker; * @author Steve Ebersole */ public class QueryLiteral extends AbstractLiteral { - public QueryLiteral(Object value, ValueMappingExpressable expressableType, Clause clause) { + public QueryLiteral(Object value, MappingModelExpressable expressableType, Clause clause) { super( value, expressableType, clause ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlSelectionExpression.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlSelectionExpression.java index 86ef42a0a3..5cd20b47d2 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlSelectionExpression.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlSelectionExpression.java @@ -6,8 +6,8 @@ */ package org.hibernate.sql.ast.tree.expression; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.sql.ast.spi.SqlSelection; -import org.hibernate.sql.ast.ValueMappingExpressable; import org.hibernate.sql.ast.spi.SqlAstWalker; /** @@ -43,7 +43,7 @@ public class SqlSelectionExpression implements Expression { } @Override - public ValueMappingExpressable getExpressionType() { + public MappingModelExpressable getExpressionType() { return theExpression.getExpressionType(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java index 0c51f39d3a..e6ed212052 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/SqlTuple.java @@ -6,10 +6,9 @@ */ package org.hibernate.sql.ast.tree.expression; -import java.util.Collections; import java.util.List; -import org.hibernate.sql.ast.ValueMappingExpressable; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.sql.ast.spi.SqlAstWalker; /** @@ -17,20 +16,16 @@ import org.hibernate.sql.ast.spi.SqlAstWalker; */ public class SqlTuple implements Expression { private final List expressions; - private final ValueMappingExpressable expressable; + private final MappingModelExpressable valueMapping; - public SqlTuple(List expressions, ValueMappingExpressable expressable) { + public SqlTuple(List expressions, MappingModelExpressable valueMapping) { this.expressions = expressions; - this.expressable = expressable; - } - - public SqlTuple(Expression expression, ValueMappingExpressable expressable) { - this( Collections.singletonList( expression ), expressable ); + this.valueMapping = valueMapping; } @Override - public ValueMappingExpressable getExpressionType() { - return expressable; + public MappingModelExpressable getExpressionType() { + return valueMapping; } public List getExpressions(){ diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/UnaryOperation.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/UnaryOperation.java index 7a9c2aae1b..238ce5733e 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/UnaryOperation.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/expression/UnaryOperation.java @@ -8,25 +8,25 @@ package org.hibernate.sql.ast.tree.expression; import org.hibernate.NotYetImplementedFor6Exception; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.query.UnaryArithmeticOperator; -import org.hibernate.sql.ast.ValueMappingExpressable; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.sql.ast.spi.SqlAstWalker; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.type.descriptor.java.JavaTypeDescriptor; /** * @author Steve Ebersole */ -public class UnaryOperation implements Expression, ValueMappingExpressable, DomainResultProducer { +public class UnaryOperation implements Expression, DomainResultProducer { private final UnaryArithmeticOperator operator; private final Expression operand; - private final ValueMappingExpressable type; + private final MappingModelExpressable type; - public UnaryOperation(UnaryArithmeticOperator operator, Expression operand, ValueMappingExpressable type) { + public UnaryOperation(UnaryArithmeticOperator operator, Expression operand, MappingModelExpressable type) { this.operator = operator; this.operand = operand; this.type = type; @@ -41,16 +41,10 @@ public class UnaryOperation implements Expression, ValueMappingExpressable, Doma } @Override - public ValueMappingExpressable getExpressionType() { + public MappingModelExpressable getExpressionType() { return type; } - @Override - public ValueMapping getExpressableValueMapping() { - // calling type#getExpressableValueMapping could be recursive - throw new NotYetImplementedFor6Exception( getClass() ); - } - @Override public void accept(SqlAstWalker walker) { walker.visitUnaryOperationExpression( this ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractTableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractTableGroup.java index 33dea0d22a..1c80d2de0f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractTableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/AbstractTableGroup.java @@ -114,25 +114,6 @@ public abstract class AbstractTableGroup implements TableGroup { @Override public String toString() { - final StringBuilder buffer = new StringBuilder( "(" ); - - buffer.append( "path=(" ).append( getNavigablePath() ).append( "), " ); - buffer.append( "root=(" ).append( getPrimaryTableReference() ).append( "), " ); - buffer.append( "joins=[" ); - if ( getTableReferenceJoins() != null ) { - boolean firstPass = true; - for ( TableReferenceJoin tableReferenceJoin : getTableReferenceJoins() ) { - if ( firstPass ) { - firstPass = false; - } - else { - buffer.append( ',' ); - } - - buffer.append( tableReferenceJoin ); - } - } - - return buffer.append( "])" ).toString(); + return getClass().getSimpleName() + '(' + getNavigablePath() + ')'; } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/RootTableGroupProducer.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/RootTableGroupProducer.java index 4c11eb6f00..dba95b0dd2 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/RootTableGroupProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/RootTableGroupProducer.java @@ -7,7 +7,7 @@ package org.hibernate.sql.ast.tree.from; import org.hibernate.LockMode; -import org.hibernate.metamodel.model.mapping.spi.ValueMappingContainer; +import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.query.NavigablePath; import org.hibernate.sql.ast.JoinType; import org.hibernate.sql.ast.spi.SqlAliasBaseGenerator; @@ -19,7 +19,7 @@ import org.hibernate.sql.ast.spi.SqlAstCreationContext; * * @author Steve Ebersole */ -public interface RootTableGroupProducer extends TableGroupProducer, ValueMappingContainer { +public interface RootTableGroupProducer extends TableGroupProducer, ModelPartContainer { /** * Create a root TableGroup as defined by this producer */ diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroup.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroup.java index d75f6a0bfd..ba83784961 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroup.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroup.java @@ -11,15 +11,15 @@ import java.util.Set; import java.util.function.Consumer; import org.hibernate.LockMode; -import org.hibernate.metamodel.model.mapping.spi.ModelPart; +import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.query.NavigablePath; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; import org.hibernate.sql.ast.spi.SqlAppender; import org.hibernate.sql.ast.spi.SqlAstWalker; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.expression.ColumnReference; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; /** * Group together {@link TableReference} references related to a single entity or @@ -57,6 +57,7 @@ public interface TableGroup extends SqlAstNode, DomainResultProducer { DomainResultCreationState creationState) { return getModelPart().createDomainResult( getNavigablePath(), + this, resultVariable, creationState ); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupJoin.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupJoin.java index d63b4fa353..bdc4b8b1b6 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupJoin.java @@ -13,7 +13,7 @@ import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.ast.tree.predicate.Predicate; import org.hibernate.sql.results.spi.DomainResult; import org.hibernate.sql.results.spi.DomainResultCreationState; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupProducer.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupProducer.java index 5e492a6327..446135532f 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupProducer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/from/TableGroupProducer.java @@ -6,7 +6,7 @@ */ package org.hibernate.sql.ast.tree.from; -import org.hibernate.metamodel.model.mapping.spi.ValueMappingContainer; +import org.hibernate.metamodel.mapping.ModelPartContainer; import org.hibernate.query.sqm.sql.SqlAliasBaseManager; /** @@ -15,7 +15,7 @@ import org.hibernate.query.sqm.sql.SqlAliasBaseManager; * @author Steve Ebersole * @author Andrea Boriero */ -public interface TableGroupProducer extends ValueMappingContainer { +public interface TableGroupProducer extends ModelPartContainer { /** * Get the "stem" used as the base for generating SQL table aliases for table * references that are part of the TableGroup being generated diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SelectClause.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SelectClause.java index fd658a89c2..bf7716c405 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SelectClause.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SelectClause.java @@ -14,7 +14,7 @@ import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.spi.SqlAstWalker; import org.hibernate.sql.ast.tree.SqlAstNode; import org.hibernate.sql.results.spi.DomainResult; -import org.hibernate.sql.results.spi.DomainResultProducer; +import org.hibernate.query.sqm.sql.internal.DomainResultProducer; /** * The SELECT CLAUSE in the SQL AST. Each selection here is a @@ -24,7 +24,7 @@ import org.hibernate.sql.results.spi.DomainResultProducer; */ public class SelectClause implements SqlAstNode { private boolean distinct; - private final List domainResults = new ArrayList<>(); + private final List sqlSelections = new ArrayList<>(); public void makeDistinct(boolean distinct) { @@ -35,14 +35,6 @@ public class SelectClause implements SqlAstNode { return distinct; } - public List getSelections() { - return Collections.unmodifiableList( domainResults ); - } - - public void addSelection(DomainResult domainResultProducer) { - domainResults.add( domainResultProducer ); - } - public void addSqlSelection(SqlSelection sqlSelection) { sqlSelections.add( sqlSelection ); } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SelectStatement.java b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SelectStatement.java index 5cb1d34766..4fce9464d0 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SelectStatement.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/ast/tree/select/SelectStatement.java @@ -6,19 +6,31 @@ */ package org.hibernate.sql.ast.tree.select; +import java.util.Collections; +import java.util.List; + import org.hibernate.sql.ast.tree.Statement; +import org.hibernate.sql.results.spi.DomainResult; /** * @author Steve Ebersole */ public class SelectStatement implements Statement { private final QuerySpec querySpec; + private final List domainResults; - public SelectStatement(QuerySpec querySpec) { + public SelectStatement( + QuerySpec querySpec, + List domainResults) { this.querySpec = querySpec; + this.domainResults = domainResults; } public QuerySpec getQuerySpec() { return querySpec; } + + public List getDomainResultDescriptors() { + return Collections.unmodifiableList( domainResults ); + } } diff --git a/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcParameterBinding.java b/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcParameterBinding.java index 752c5ea2c1..7ae0549c91 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcParameterBinding.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/exec/spi/JdbcParameterBinding.java @@ -6,8 +6,7 @@ */ package org.hibernate.sql.exec.spi; - -import org.hibernate.metamodel.model.mapping.spi.SqlExpressableType; +import org.hibernate.metamodel.mapping.SqlExpressableType; /** * @author Steve Ebersole diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java index aaf15fbb0b..fe1b42a9af 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/internal/SqlSelectionImpl.java @@ -8,7 +8,7 @@ package org.hibernate.sql.results.internal; import java.util.Objects; -import org.hibernate.metamodel.model.mapping.spi.SqlExpressableType; +import org.hibernate.metamodel.mapping.SqlExpressableType; import org.hibernate.sql.ast.spi.SqlSelection; import org.hibernate.sql.ast.tree.expression.Expression; import org.hibernate.type.descriptor.ValueExtractor; diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/CompositeInitializer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/CompositeInitializer.java index 584b2b5441..e9befa6fd8 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/CompositeInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/CompositeInitializer.java @@ -6,13 +6,14 @@ */ package org.hibernate.sql.results.spi; -import org.hibernate.metamodel.model.mapping.spi.ValueMappingContainer; + +import org.hibernate.metamodel.mapping.ModelPartContainer; /** * @author Steve Ebersole */ public interface CompositeInitializer extends Initializer, FetchParentAccess { - ValueMappingContainer getInitializingEmbeddedDescriptor(); + ModelPartContainer getInitializingEmbeddedDescriptor(); Object getCompositeInstance(); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/Fetch.java b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/Fetch.java index d775061086..19e045e433 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/Fetch.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/Fetch.java @@ -8,7 +8,7 @@ package org.hibernate.sql.results.spi; import java.util.function.Consumer; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; +import org.hibernate.metamodel.mapping.ModelPart; import org.hibernate.query.NavigablePath; /** @@ -40,7 +40,7 @@ public interface Fetch { /** * The value mapping being fetched */ - ValueMapping getFetchedValueMapping(); + ModelPart getFetchedMapping(); /** * Get the property path to this fetch diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/Fetchable.java b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/Fetchable.java index 9a550740c9..fc2dbc0a90 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/Fetchable.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/Fetchable.java @@ -9,12 +9,12 @@ package org.hibernate.sql.results.spi; import org.hibernate.LockMode; import org.hibernate.engine.FetchStrategy; import org.hibernate.engine.FetchTiming; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; +import org.hibernate.metamodel.mapping.ModelPart; /** * @author Steve Ebersole */ -public interface Fetchable extends ValueMapping { +public interface Fetchable extends ModelPart { String getFetchableName(); FetchStrategy getMappedFetchStrategy(); diff --git a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/FetchableContainer.java b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/FetchableContainer.java index 666678ca4c..5a9506ffbf 100644 --- a/hibernate-core/src/main/java/org/hibernate/sql/results/spi/FetchableContainer.java +++ b/hibernate-core/src/main/java/org/hibernate/sql/results/spi/FetchableContainer.java @@ -8,14 +8,14 @@ package org.hibernate.sql.results.spi; import java.util.function.Consumer; -import org.hibernate.metamodel.model.mapping.spi.ValueMappingContainer; +import org.hibernate.metamodel.mapping.ModelPartContainer; /** * @author Steve Ebersole */ -public interface FetchableContainer extends ValueMappingContainer { +public interface FetchableContainer extends ModelPartContainer { default Fetchable findFetchable(String name) { - return (Fetchable) findValueMapping( name ); + return (Fetchable) findSubPart( name ); } default void visitKeyFetchables(Consumer fetchableConsumer) { diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractCompositionAttribute.java b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractCompositionAttribute.java index 3134ba9b85..f712fa4d6f 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractCompositionAttribute.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/component/AbstractCompositionAttribute.java @@ -7,11 +7,9 @@ package org.hibernate.tuple.component; import java.util.Iterator; -import java.util.function.Consumer; import org.hibernate.engine.internal.JoinHelper; import org.hibernate.engine.spi.SessionFactoryImplementor; -import org.hibernate.metamodel.model.mapping.spi.ValueMapping; import org.hibernate.persister.collection.QueryableCollection; import org.hibernate.persister.entity.EntityPersister; import org.hibernate.persister.entity.Joinable; diff --git a/hibernate-core/src/main/java/org/hibernate/type/BasicType.java b/hibernate-core/src/main/java/org/hibernate/type/BasicType.java index 0afec55910..05f6dec558 100644 --- a/hibernate-core/src/main/java/org/hibernate/type/BasicType.java +++ b/hibernate-core/src/main/java/org/hibernate/type/BasicType.java @@ -6,6 +6,7 @@ */ package org.hibernate.type; +import org.hibernate.metamodel.mapping.MappingModelExpressable; import org.hibernate.metamodel.model.domain.BasicDomainType; /** @@ -13,11 +14,13 @@ import org.hibernate.metamodel.model.domain.BasicDomainType; * * @author Steve Ebersole */ -public interface BasicType extends Type, BasicDomainType { +public interface BasicType extends Type, BasicDomainType, MappingModelExpressable { /** * Get the names under which this type should be registered in the type registry. * * @return The keys under which to register this type. */ String[] getRegistrationKeys(); + + } diff --git a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/ast/SmokeTests.java b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/ast/SmokeTests.java index 584e9c4274..705e15c203 100644 --- a/hibernate-core/src/test/java/org/hibernate/orm/test/sql/ast/SmokeTests.java +++ b/hibernate-core/src/test/java/org/hibernate/orm/test/sql/ast/SmokeTests.java @@ -9,11 +9,9 @@ package org.hibernate.orm.test.sql.ast; import org.hibernate.cfg.AvailableSettings; import org.hibernate.query.hql.spi.HqlQueryImplementor; import org.hibernate.query.spi.QueryImplementor; -import org.hibernate.query.sqm.internal.DomainParameterXref; import org.hibernate.query.sqm.internal.QuerySqmImpl; import org.hibernate.query.sqm.sql.internal.SqmSelectInterpretation; import org.hibernate.query.sqm.sql.internal.SqmSelectToSqlAstConverter; -import org.hibernate.query.sqm.tree.SqmStatement; import org.hibernate.query.sqm.tree.select.SqmSelectStatement; import org.hibernate.testing.orm.domain.StandardDomainModel;