design doc work

This commit is contained in:
Steve Ebersole 2020-08-25 20:17:35 -05:00
parent f5ba3c22a0
commit 57a3b0b456
28 changed files with 74 additions and 103 deletions

View File

@ -5,12 +5,12 @@ no references to tables, columns, etc. The base contract for Hibernate's extens
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
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
.Domain type system
....
@startuml
skinparam handwritten true

View File

@ -1,80 +1,57 @@
= Mapping model
[plantuml,SqmTypeSystem,png]
.Mapping type system
The mapping model encompasses the complete mapping of objects to/from database. It is the
model used to drive read and write operations.
[NOTE]
----
As of 6.0, only read operations are implemented to use this mapping model. Future versions will hopefully
move writing to use this mapping model as well
----
[plantuml,MasppingTypeSystem,png]
.Mapping type model (org.hibernate.metamodel.mapping)
....
@startuml
skinparam handwritten true
interface MappingType
interface ManagedMappingType
interface MappingModelExpressable
interface ValueMapping
interface BasicType
interface ModelPart
interface ModelPartContainer
MappingType <|--
MappingType <|-- BasicType
MappingType <|-- JdbcMapping
MappingType <|-- ManagedMappingType
MappingType <|-- CollectionMappingType
ManagedMappingType <|-- EmbeddableMappingType
ManagedMappingType <|-- EntityMappingType
MappingModelExpressable <|-- ValueMapping
MappingModelExpressable <|-- ModelPart
ValueMapping <|-- BasicType
ValueMapping <|-- ModelPart
ModelPartContainer <|-- EntityMapping
ModelPartContainer <|-- EmbeddableMapping
ModelPart <|-- EmbeddableMapping
ModelPart <|-- BasicValuedModelPart
ModelPart <|-- EmbeddableValuedModelPart
ModelPart <|-- EntityValuedModelPart
ModelPart <|-- AttributeMapping
ModelPart <|-- EntityIdentifierMapping
ModelPart <|-- EntityVersionMapping
ModelPart <|-- EntityDiscriminatorMapping
ModelPart <|-- CollectionPart
ModelPartContainer <|-- EntityMappingType
ModelPartContainer <|-- EmbeddableMappingType
@enduml
....
[source,JAVA]
----
interface ValueMapping {
Type getMappingType();
<X> X getCapability(Class<X> capabilityType);
...
}
interface ModelPart extends ValueMapping {
<T> DomainResult<T> createDomainResult(...);
void applySqlSelections(...);
...
}
interface ModelPartContainer extends ValueMapping {
void visitSubMappings(Consumer<ModelPart> 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`:

View File

@ -132,10 +132,10 @@ public class DefaultLoadEventListener implements LoadEventListener {
if ( cidMapping.getAttributeCount() == 1 ) {
final AttributeMapping singleIdAttribute = cidMapping.getAttributes().iterator().next();
if ( singleIdAttribute.getMappedTypeDescriptor() instanceof EntityMappingType ) {
final EntityMappingType dependentIdTargetMapping = (EntityMappingType) singleIdAttribute.getMappedTypeDescriptor();
if ( singleIdAttribute.getMappedType() instanceof EntityMappingType ) {
final EntityMappingType dependentIdTargetMapping = (EntityMappingType) singleIdAttribute.getMappedType();
final EntityIdentifierMapping dependentIdTargetIdMapping = dependentIdTargetMapping.getIdentifierMapping();
final JavaTypeDescriptor dependentParentIdJtd = dependentIdTargetIdMapping.getMappedTypeDescriptor().getMappedJavaTypeDescriptor();
final JavaTypeDescriptor dependentParentIdJtd = dependentIdTargetIdMapping.getMappedType().getMappedJavaTypeDescriptor();
if ( dependentParentIdJtd.getJavaType().isInstance( event.getEntityId() ) ) {
// yep that's what we have...
loadByDerivedIdentitySimplePkValue(

View File

@ -34,12 +34,10 @@ import org.hibernate.loader.ast.spi.Loadable;
import org.hibernate.loader.ast.spi.Loader;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.metamodel.mapping.CollectionPart;
import org.hibernate.metamodel.mapping.EmbeddableValuedModelPart;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
import org.hibernate.metamodel.mapping.EntityMappingType;
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
import org.hibernate.metamodel.mapping.JdbcMapping;
import org.hibernate.metamodel.mapping.ModelPart;
import org.hibernate.metamodel.mapping.PluralAttributeMapping;
import org.hibernate.metamodel.mapping.internal.EmbeddedAttributeMapping;
@ -654,7 +652,7 @@ public class LoaderSelectBuilder {
if ( fetch.getTiming() == FetchTiming.IMMEDIATE && fetchable instanceof PluralAttributeMapping ) {
final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable;
if ( pluralAttributeMapping.getMappedTypeDescriptor()
if ( pluralAttributeMapping.getMappedType()
.getCollectionSemantics() instanceof BagSemantics ) {
bagRoles.add( fetchable.getNavigableRole().getNavigableName() );
}

View File

@ -81,7 +81,7 @@ public abstract class AbstractCompositeIdentifierMapping
}
@Override
public EmbeddableMappingType getMappedTypeDescriptor() {
public EmbeddableMappingType getMappedType() {
return embeddableDescriptor;
}

View File

@ -29,7 +29,7 @@ public interface PluralAttributeMapping
CollectionPart getIndexDescriptor();
@Override
CollectionMappingType getMappedTypeDescriptor();
CollectionMappingType getMappedType();
interface IndexMetadata {
CollectionPart getIndexDescriptor();

View File

@ -22,7 +22,7 @@ public interface ValueMapping extends MappingModelExpressable {
/**
* Descriptor for the type of this mapping
*/
MappingType getMappedTypeDescriptor();
MappingType getMappedType();
/**
* Treat operation. Asks the ValueMapping to treat itself as the

View File

@ -38,13 +38,13 @@ public abstract class AbstractAttributeMapping implements AttributeMapping {
@Override
public MappingType getPartMappingType() {
return getMappedTypeDescriptor();
return getMappedType();
}
@Override
@SuppressWarnings("rawtypes")
public JavaTypeDescriptor getJavaTypeDescriptor() {
return getMappedTypeDescriptor().getMappedJavaTypeDescriptor();
return getMappedType().getMappedJavaTypeDescriptor();
}
void setForeignKeyDescriptor(ForeignKeyDescriptor foreignKeyDescriptor){

View File

@ -139,11 +139,11 @@ public abstract class AbstractEntityDiscriminatorMapping implements EntityDiscri
@Override
public JavaTypeDescriptor getJavaTypeDescriptor() {
return getMappedTypeDescriptor().getMappedJavaTypeDescriptor();
return getMappedType().getMappedJavaTypeDescriptor();
}
@Override
public MappingType getMappedTypeDescriptor() {
public MappingType getMappedType() {
return mappingType;
}

View File

@ -125,7 +125,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
}
@Override
public MappingType getMappedTypeDescriptor() {
public MappingType getMappedType() {
return getJdbcMapping()::getJavaTypeDescriptor;
}
@ -163,7 +163,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
@Override
public JavaTypeDescriptor getJavaTypeDescriptor() {
return getMappedTypeDescriptor().getMappedJavaTypeDescriptor();
return getMappedType().getMappedJavaTypeDescriptor();
}
@Override
@ -217,7 +217,7 @@ public class BasicEntityIdentifierMappingImpl implements BasicEntityIdentifierMa
return new BasicResult(
sqlSelection.getValuesArrayPosition(),
resultVariable,
entityPersister.getIdentifierMapping().getMappedTypeDescriptor().getMappedJavaTypeDescriptor(),
entityPersister.getIdentifierMapping().getMappedType().getMappedJavaTypeDescriptor(),
navigablePath
);
}

View File

@ -163,7 +163,7 @@ public class BasicValuedCollectionPart
}
@Override
public MappingType getMappedTypeDescriptor() {
public MappingType getMappedType() {
return this::getJavaTypeDescriptor;
}

View File

@ -9,11 +9,9 @@ package org.hibernate.metamodel.mapping.internal;
import java.util.function.Consumer;
import org.hibernate.LockMode;
import org.hibernate.MappingException;
import org.hibernate.engine.FetchStrategy;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
import org.hibernate.metamodel.mapping.ColumnConsumer;
import org.hibernate.metamodel.mapping.ConvertibleModelPart;
@ -26,7 +24,6 @@ import org.hibernate.metamodel.model.convert.spi.BasicValueConverter;
import org.hibernate.metamodel.model.domain.NavigableRole;
import org.hibernate.property.access.spi.PropertyAccess;
import org.hibernate.query.NavigablePath;
import org.hibernate.sql.Template;
import org.hibernate.sql.ast.Clause;
import org.hibernate.sql.ast.spi.SqlAstCreationState;
import org.hibernate.sql.ast.spi.SqlExpressionResolver;
@ -96,7 +93,7 @@ public class BasicValuedSingularAttributeMapping
}
@Override
public MappingType getMappedTypeDescriptor() {
public MappingType getMappedType() {
return getJdbcMapping();
}
@ -142,7 +139,7 @@ public class BasicValuedSingularAttributeMapping
return new BasicResult(
sqlSelection.getValuesArrayPosition(),
resultVariable,
getMappedTypeDescriptor().getMappedJavaTypeDescriptor(),
getMappedType().getMappedJavaTypeDescriptor(),
valueConverter,
navigablePath
);
@ -169,7 +166,7 @@ public class BasicValuedSingularAttributeMapping
creationState.getSqlAstCreationState().getCreationContext().getSessionFactory()
)
),
valueConverter == null ? getMappedTypeDescriptor().getMappedJavaTypeDescriptor() : valueConverter.getRelationalJavaDescriptor(),
valueConverter == null ? getMappedType().getMappedJavaTypeDescriptor() : valueConverter.getRelationalJavaDescriptor(),
creationState.getSqlAstCreationState().getCreationContext().getDomainModel().getTypeConfiguration()
);
}
@ -198,7 +195,7 @@ public class BasicValuedSingularAttributeMapping
creationState.getSqlAstCreationState().getCreationContext().getSessionFactory()
)
),
valueConverter == null ? getMappedTypeDescriptor().getMappedJavaTypeDescriptor() : valueConverter.getRelationalJavaDescriptor(),
valueConverter == null ? getMappedType().getMappedJavaTypeDescriptor() : valueConverter.getRelationalJavaDescriptor(),
creationState.getSqlAstCreationState().getCreationContext().getDomainModel().getTypeConfiguration()
);
}

View File

@ -82,13 +82,13 @@ public class CollectionIdentifierDescriptorImpl implements CollectionIdentifierD
}
@Override
public MappingType getMappedTypeDescriptor() {
public MappingType getMappedType() {
return type;
}
@Override
public JavaTypeDescriptor getJavaTypeDescriptor() {
return getMappedTypeDescriptor().getMappedJavaTypeDescriptor();
return getMappedType().getMappedJavaTypeDescriptor();
}
@Override

View File

@ -101,7 +101,7 @@ public class EmbeddedAttributeMapping
}
@Override
public EmbeddableMappingType getMappedTypeDescriptor() {
public EmbeddableMappingType getMappedType() {
return getEmbeddableTypeDescriptor();
}
@ -247,14 +247,14 @@ public class EmbeddedAttributeMapping
public ModelPart findSubPart(
String name,
EntityMappingType treatTargetType) {
return getMappedTypeDescriptor().findSubPart( name, treatTargetType );
return getMappedType().findSubPart( name, treatTargetType );
}
@Override
public void visitSubParts(
Consumer<ModelPart> consumer,
EntityMappingType treatTargetType) {
getMappedTypeDescriptor().visitSubParts( consumer, treatTargetType );
getMappedType().visitSubParts( consumer, treatTargetType );
}
@Override

View File

@ -54,7 +54,7 @@ public class EntityDiscriminatorMappingImpl extends AbstractEntityDiscriminatorM
creationState.getSqlAstCreationState().getCreationContext().getSessionFactory()
)
),
getMappedTypeDescriptor().getMappedJavaTypeDescriptor(),
getMappedType().getMappedJavaTypeDescriptor(),
creationState.getSqlAstCreationState().getCreationContext().getDomainModel().getTypeConfiguration()
);
}

View File

@ -82,7 +82,7 @@ public class EntityVersionMappingImpl implements EntityVersionMapping, FetchOpti
}
@Override
public MappingType getMappedTypeDescriptor() {
public MappingType getMappedType() {
return versionBasicType;
}

View File

@ -51,7 +51,7 @@ public class JoinedSubclassDiscriminatorMappingImpl extends AbstractEntityDiscri
columnReference ->
expressionResolver.resolveSqlSelection(
columnReference,
getMappedTypeDescriptor().getMappedJavaTypeDescriptor(),
getMappedType().getMappedJavaTypeDescriptor(),
creationState.getSqlAstCreationState()
.getCreationContext()
.getDomainModel()
@ -64,7 +64,7 @@ public class JoinedSubclassDiscriminatorMappingImpl extends AbstractEntityDiscri
getMappedColumnExpression(),
sqlAstProcessingState -> caseSearchedExpression
),
getMappedTypeDescriptor().getMappedJavaTypeDescriptor(),
getMappedType().getMappedJavaTypeDescriptor(),
creationState.getSqlAstCreationState().getCreationContext().getDomainModel().getTypeConfiguration()
);
}

View File

@ -357,7 +357,7 @@ public class PluralAttributeMappingImpl extends AbstractAttributeMapping
@Override
@SuppressWarnings("rawtypes")
public CollectionMappingType getMappedTypeDescriptor() {
public CollectionMappingType getMappedType() {
return collectionMappingType;
}

View File

@ -379,7 +379,7 @@ public class SimpleForeignKeyDescriptor implements ForeignKeyDescriptor, BasicVa
}
@Override
public MappingType getMappedTypeDescriptor() {
public MappingType getMappedType() {
return null;
}

View File

@ -206,7 +206,7 @@ public class ToOneAttributeMapping extends AbstractSingularAttributeMapping
}
@Override
public EntityMappingType getMappedTypeDescriptor() {
public EntityMappingType getMappedType() {
return getEntityMappingType();
}

View File

@ -100,7 +100,7 @@ public class CompleteResultBuilderBasicValuedStandard implements CompleteResultB
sessionFactory.getTypeConfiguration()
);
return new BasicResult<>( valuesArrayPosition, columnName, basicType.getMappedTypeDescriptor().getMappedJavaTypeDescriptor() );
return new BasicResult<>( valuesArrayPosition, columnName, basicType.getMappedType().getMappedJavaTypeDescriptor() );
}
}

View File

@ -18,7 +18,6 @@ import org.hibernate.HibernateException;
import org.hibernate.LockMode;
import org.hibernate.LockOptions;
import org.hibernate.NotYetImplementedFor6Exception;
import org.hibernate.collection.spi.BagSemantics;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.profile.FetchProfile;
import org.hibernate.engine.spi.LoadQueryInfluencers;
@ -296,7 +295,7 @@ public class StandardSqmSelectTranslator
if ( fetch != null ) {
if ( fetch.getTiming() == FetchTiming.IMMEDIATE && fetchable instanceof PluralAttributeMapping ) {
final PluralAttributeMapping pluralAttributeMapping = (PluralAttributeMapping) fetchable;
final CollectionClassification collectionClassification = pluralAttributeMapping.getMappedTypeDescriptor()
final CollectionClassification collectionClassification = pluralAttributeMapping.getMappedType()
.getCollectionSemantics()
.getCollectionClassification();
if ( collectionClassification == CollectionClassification.BAG ) {

View File

@ -65,7 +65,7 @@ public abstract class AbstractLiteral<T>
final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
this,
type.getMappedTypeDescriptor().getMappedJavaTypeDescriptor(),
type.getMappedType().getMappedJavaTypeDescriptor(),
creationState.getSqlAstCreationState()
.getCreationContext()
.getSessionFactory()
@ -76,7 +76,7 @@ public abstract class AbstractLiteral<T>
return new BasicResult<>(
sqlSelection.getValuesArrayPosition(),
resultVariable,
type.getMappedTypeDescriptor().getMappedJavaTypeDescriptor()
type.getMappedType().getMappedJavaTypeDescriptor()
);
}

View File

@ -67,7 +67,7 @@ public class QueryLiteral<T> implements Literal, DomainResultProducer<T> {
final SqlExpressionResolver sqlExpressionResolver = creationState.getSqlAstCreationState().getSqlExpressionResolver();
final SqlSelection sqlSelection = sqlExpressionResolver.resolveSqlSelection(
this,
type.getMappedTypeDescriptor().getMappedJavaTypeDescriptor(),
type.getMappedType().getMappedJavaTypeDescriptor(),
creationState.getSqlAstCreationState()
.getCreationContext()
.getSessionFactory()
@ -78,7 +78,7 @@ public class QueryLiteral<T> implements Literal, DomainResultProducer<T> {
return new BasicResult<>(
sqlSelection.getValuesArrayPosition(),
resultVariable,
type.getMappedTypeDescriptor().getMappedJavaTypeDescriptor()
type.getMappedType().getMappedJavaTypeDescriptor()
);
}

View File

@ -198,7 +198,7 @@ public abstract class AbstractEntityInitializer extends AbstractFetchParentAcces
final DomainResultAssembler stateAssembler;
if ( fetch == null ) {
stateAssembler = new NullValueAssembler( attributeMapping.getMappedTypeDescriptor().getMappedJavaTypeDescriptor() );
stateAssembler = new NullValueAssembler( attributeMapping.getMappedType().getMappedJavaTypeDescriptor() );
}
else {
stateAssembler = fetch.createAssembler( this, creationState );

View File

@ -189,7 +189,7 @@ public class CircularBiDirectionalFetchImpl implements BiDirectionalFetch, Assoc
final CollectionKey collectionKey = circ.resolveCollectionKey( rowProcessingState );
final EntityKey entityKey = new EntityKey(
collectionKey.getKey(),
(EntityPersister) ( (AttributeMapping) fetchable ).getMappedTypeDescriptor()
(EntityPersister) ( (AttributeMapping) fetchable ).getMappedType()
);
final SharedSessionContractImplementor session = rowProcessingState.getJdbcValuesSourceProcessingState()

View File

@ -33,7 +33,7 @@ public interface BasicType<T> extends Type, BasicDomainType<T>, MappingType, Bas
String[] getRegistrationKeys();
@Override
default MappingType getMappedTypeDescriptor() {
default MappingType getMappedType() {
return this;
}

View File

@ -66,7 +66,7 @@ public class SmokeTests {
final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
assertThat(
identifierMapping.getMappedTypeDescriptor().getMappedJavaTypeDescriptor().getJavaType(),
identifierMapping.getMappedType().getMappedJavaTypeDescriptor().getJavaType(),
sameInstance( Integer.class )
);
@ -154,7 +154,7 @@ public class SmokeTests {
assertThat( part, instanceOf( ToOneAttributeMapping.class ) );
final ToOneAttributeMapping attrMapping = (ToOneAttributeMapping) part;
assertThat( attrMapping.getAttributeName(), is( "simpleEntity" ) );
assertThat( attrMapping.getMappedTypeDescriptor(), is( simpleEntityDescriptor ) );
assertThat( attrMapping.getMappedType(), is( simpleEntityDescriptor ) );
assertThat(
attrMapping.getJavaTypeDescriptor(),
is( simpleEntityDescriptor.getJavaTypeDescriptor() )