6 - SQM based on JPA type system, RuntimeModelCreationProcess

This commit is contained in:
Andrea Boriero 2019-06-04 18:15:10 +01:00
parent d6428c5b43
commit 46e27d7f46
8 changed files with 63 additions and 42 deletions

View File

@ -194,9 +194,9 @@ public class InflightRuntimeMetamodel {
);
for ( PersistentClass entityBinding : bootMetamodel.getEntityBindings() ) {
locateOrBuildEntityType( entityBinding, context );
locateOrBuildEntityType( entityBinding, context, typeConfiguration );
}
handleUnusedMappedSuperclasses( context );
handleUnusedMappedSuperclasses( context, typeConfiguration );
context.wrapUp();
@ -339,22 +339,23 @@ public class InflightRuntimeMetamodel {
}
}
private static void handleUnusedMappedSuperclasses(MetadataContext context) {
private static void handleUnusedMappedSuperclasses(MetadataContext context, TypeConfiguration typeConfiguration) {
final Set<MappedSuperclass> unusedMappedSuperclasses = context.getUnusedMappedSuperclasses();
if ( !unusedMappedSuperclasses.isEmpty() ) {
for ( MappedSuperclass mappedSuperclass : unusedMappedSuperclasses ) {
log.unusedMappedSuperclass( mappedSuperclass.getMappedClass().getName() );
locateOrBuildMappedSuperclassType( mappedSuperclass, context );
locateOrBuildMappedSuperclassType( mappedSuperclass, context, typeConfiguration );
}
}
}
private static MappedSuperclassDomainType<?> locateOrBuildMappedSuperclassType(
MappedSuperclass mappedSuperclass,
MetadataContext context) {
MetadataContext context,
TypeConfiguration typeConfiguration) {
MappedSuperclassDomainType<?> mappedSuperclassType = context.locateMappedSuperclassType( mappedSuperclass );
if ( mappedSuperclassType == null ) {
mappedSuperclassType = buildMappedSuperclassType( mappedSuperclass, context );
mappedSuperclassType = buildMappedSuperclassType( mappedSuperclass, context, typeConfiguration );
}
return mappedSuperclassType;
}
@ -362,17 +363,18 @@ public class InflightRuntimeMetamodel {
@SuppressWarnings("unchecked")
private static MappedSuperclassTypeImpl<?> buildMappedSuperclassType(
MappedSuperclass mappedSuperclass,
MetadataContext context) {
MetadataContext context,
TypeConfiguration typeConfiguration) {
final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass();
IdentifiableDomainType<?> superType = superMappedSuperclass == null
? null
: locateOrBuildMappedSuperclassType( superMappedSuperclass, context );
: locateOrBuildMappedSuperclassType( superMappedSuperclass, context, typeConfiguration );
//no mappedSuperclass, check for a super entity
if ( superType == null ) {
final PersistentClass superPersistentClass = mappedSuperclass.getSuperPersistentClass();
superType = superPersistentClass == null
? null
: locateOrBuildEntityType( superPersistentClass, context );
: locateOrBuildEntityType( superPersistentClass, context, typeConfiguration );
}
final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration()
.getJavaTypeDescriptorRegistry()
@ -380,7 +382,8 @@ public class InflightRuntimeMetamodel {
MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(
javaTypeDescriptor,
mappedSuperclass,
superType
superType,
typeConfiguration
);
context.registerMappedSuperclassType( mappedSuperclass, mappedSuperclassType );
@ -389,28 +392,32 @@ public class InflightRuntimeMetamodel {
private static EntityDomainType<?> locateOrBuildEntityType(
PersistentClass persistentClass,
MetadataContext context) {
MetadataContext context,
TypeConfiguration typeConfiguration) {
EntityDomainType<?> entityType = context.locateEntityType( persistentClass );
if ( entityType == null ) {
entityType = buildEntityType( persistentClass, context );
entityType = buildEntityType( persistentClass, context, typeConfiguration );
}
return entityType;
}
@SuppressWarnings("unchecked")
private static EntityTypeImpl<?> buildEntityType(PersistentClass persistentClass, MetadataContext context) {
private static EntityTypeImpl<?> buildEntityType(
PersistentClass persistentClass,
MetadataContext context,
TypeConfiguration typeConfiguration) {
final Class javaType = persistentClass.getMappedClass();
context.pushEntityWorkedOn( persistentClass );
final MappedSuperclass superMappedSuperclass = persistentClass.getSuperMappedSuperclass();
IdentifiableDomainType<?> superType = superMappedSuperclass == null
? null
: locateOrBuildMappedSuperclassType( superMappedSuperclass, context );
: locateOrBuildMappedSuperclassType( superMappedSuperclass, context, typeConfiguration );
//no mappedSuperclass, check for a super entity
if ( superType == null ) {
final PersistentClass superPersistentClass = persistentClass.getSuperclass();
superType = superPersistentClass == null
? null
: locateOrBuildEntityType( superPersistentClass, context );
: locateOrBuildEntityType( superPersistentClass, context, typeConfiguration );
}
final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration()
@ -419,7 +426,8 @@ public class InflightRuntimeMetamodel {
EntityTypeImpl entityType = new EntityTypeImpl(
javaTypeDescriptor,
superType,
persistentClass
persistentClass,
typeConfiguration
);
context.registerEntityType( persistentClass, entityType );
context.popEntityWorkedOn( persistentClass );

View File

@ -7,26 +7,23 @@
package org.hibernate.metamodel.model.domain;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.spi.TypeConfiguration;
/**
* @author Steve Ebersole
*/
public abstract class AbstractDomainType<J> implements SimpleDomainType<J> {
private JpaMetamodel jpaMetamodel;
private final TypeConfiguration typeConfiguration;
private final JavaTypeDescriptor<J> javaTypeDescriptor;
@SuppressWarnings("WeakerAccess")
public AbstractDomainType(JavaTypeDescriptor<J> javaTypeDescriptor) {
public AbstractDomainType(JavaTypeDescriptor<J> javaTypeDescriptor, TypeConfiguration typeConfiguration) {
this.javaTypeDescriptor = javaTypeDescriptor;
this.typeConfiguration = typeConfiguration;
}
protected JpaMetamodel jpaMetamodel() {
return jpaMetamodel;
}
public void injectJpaMetamodel(JpaMetamodel jpaMetamodel){
this.jpaMetamodel = jpaMetamodel;
return typeConfiguration.getSessionFactory().getJpaMetamodel();
}
@Override

View File

@ -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
@ -45,8 +46,9 @@ public abstract class AbstractIdentifiableType<J>
IdentifiableDomainType<? super J> superType,
boolean hasIdClass,
boolean hasIdentifierProperty,
boolean versioned) {
super( typeName, javaTypeDescriptor, superType );
boolean versioned,
TypeConfiguration typeConfiguration) {
super( typeName, javaTypeDescriptor, superType, typeConfiguration );
this.hasIdClass = hasIdClass;
this.hasIdentifierProperty = hasIdentifierProperty;
this.isVersioned = versioned;

View File

@ -28,6 +28,7 @@ import org.hibernate.metamodel.RepresentationMode;
import org.hibernate.metamodel.model.domain.internal.AttributeContainer;
import org.hibernate.metamodel.model.domain.internal.DomainModelHelper;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.spi.TypeConfiguration;
/**
* Commonality for Hibernate's implementations of the JPA {@link ManagedType}
@ -48,8 +49,9 @@ public abstract class AbstractManagedType<J>
protected AbstractManagedType(
String hibernateTypeName,
JavaTypeDescriptor<J> javaTypeDescriptor,
ManagedDomainType<? super J> superType) {
super( javaTypeDescriptor );
ManagedDomainType<? super J> superType,
TypeConfiguration typeConfiguration) {
super( javaTypeDescriptor, typeConfiguration );
this.hibernateTypeName = hibernateTypeName;
this.superType = superType;

View File

@ -15,6 +15,7 @@ import org.hibernate.metamodel.model.domain.AbstractManagedType;
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.spi.TypeConfiguration;
/**
* Standard Hibernate implementation of JPA's {@link javax.persistence.metamodel.EmbeddableType}
@ -27,13 +28,17 @@ public class EmbeddableTypeImpl<J>
extends AbstractManagedType<J>
implements EmbeddableDomainType<J>, Serializable {
public EmbeddableTypeImpl(JavaTypeDescriptor<J> javaTypeDescriptor, NodeBuilder nodeBuilder) {
super( javaTypeDescriptor.getJavaType().getName(), javaTypeDescriptor, null );
public EmbeddableTypeImpl(
JavaTypeDescriptor<J> javaTypeDescriptor,
NodeBuilder nodeBuilder,
TypeConfiguration typeConfiguration) {
super( javaTypeDescriptor.getJavaType().getName(), javaTypeDescriptor, null, typeConfiguration );
}
public EmbeddableTypeImpl(
String name,
NodeBuilder nodeBuilder) {
NodeBuilder nodeBuilder,
TypeConfiguration typeConfiguration) {
//noinspection unchecked
super(
name,
@ -41,7 +46,8 @@ public class EmbeddableTypeImpl<J>
.getTypeConfiguration()
.getJavaTypeDescriptorRegistry()
.getDescriptor( Map.class ),
null
null,
typeConfiguration
);
}

View File

@ -21,6 +21,7 @@ import org.hibernate.query.sqm.SqmPathSource;
import org.hibernate.query.sqm.produce.spi.SqmCreationState;
import org.hibernate.query.sqm.tree.domain.SqmPath;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.spi.TypeConfiguration;
/**
* Defines the Hibernate implementation of the JPA {@link EntityType} contract.
@ -36,14 +37,16 @@ public class EntityTypeImpl<J>
public EntityTypeImpl(
JavaTypeDescriptor<J> javaTypeDescriptor,
IdentifiableDomainType<? super J> superType,
PersistentClass persistentClass) {
PersistentClass persistentClass,
TypeConfiguration typeConfiguration) {
super(
persistentClass.getEntityName(),
javaTypeDescriptor,
superType,
persistentClass.getDeclaredIdentifierMapper() != null || ( superType != null && superType.hasIdClass() ),
persistentClass.hasIdentifierProperty(),
persistentClass.isVersioned()
persistentClass.isVersioned(),
typeConfiguration
);
this.jpaEntityName = persistentClass.getJpaEntityName();
}

View File

@ -77,12 +77,12 @@ public class JpaMetamodelImpl implements JpaMetamodel {
mappedSuperclassTypeMap = runtimeMetamodel.getJpaMappedSuperclassTypeMap();
embeddableDescriptorMap = runtimeMetamodel.getJpaEmbeddableDescriptorMap();
entityDescriptorMap.values()
.forEach( domainType -> ( (AbstractDomainType) domainType ).injectJpaMetamodel( this ) );
mappedSuperclassTypeMap.values().forEach( domainType -> ( (AbstractDomainType) domainType ).injectJpaMetamodel(
this ) );
entityDescriptorMap.values()
.forEach( domainType -> ( (AbstractDomainType) domainType ).injectJpaMetamodel( this ) );
// entityDescriptorMap.values()
// .forEach( domainType -> ( (AbstractDomainType) domainType ).injectJpaMetamodel( this ) );
// mappedSuperclassTypeMap.values().forEach( domainType -> ( (AbstractDomainType) domainType ).injectJpaMetamodel(
// this ) );
// entityDescriptorMap.values()
// .forEach( domainType -> ( (AbstractDomainType) domainType ).injectJpaMetamodel( this ) );
nameToImportNameMap = runtimeMetamodel.getNameToImportNameMap();
entityProxyInterfaceMap = runtimeMetamodel.getEntityProxyInterfaceMap();

View File

@ -13,6 +13,7 @@ import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.spi.TypeConfiguration;
/**
* @author Emmanuel Bernard
@ -22,14 +23,16 @@ public class MappedSuperclassTypeImpl<X> extends AbstractIdentifiableType<X> imp
public MappedSuperclassTypeImpl(
JavaTypeDescriptor<X> javaTypeDescriptor,
MappedSuperclass mappedSuperclass,
IdentifiableDomainType<? super X> superType) {
IdentifiableDomainType<? super X> superType,
TypeConfiguration typeConfiguration) {
super(
javaTypeDescriptor.getJavaType().getName(),
javaTypeDescriptor,
superType,
mappedSuperclass.getDeclaredIdentifierMapper() != null || ( superType != null && superType.hasIdClass() ),
mappedSuperclass.hasIdentifierProperty(),
mappedSuperclass.isVersioned()
mappedSuperclass.isVersioned(),
typeConfiguration
);
}