mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-08 20:24:46 +00:00
6 - SQM based on JPA type system
- focus on reducing compilation errors
This commit is contained in:
parent
83a9618614
commit
18a52483ef
@ -299,8 +299,7 @@ public void sessionFactoryClosed(SessionFactory factory) {
|
||||
|
||||
LOG.debug( "Instantiated session factory" );
|
||||
|
||||
this.metamodel = (MetamodelImplementor) metadata.getTypeConfiguration().scope( this )
|
||||
.create( metadata, determineJpaMetaModelPopulationSetting( properties ) );
|
||||
this.metamodel = (MetamodelImplementor) metadata.getTypeConfiguration().scope( this ).create( metadata );
|
||||
|
||||
// todo (6.0) : manage old getMultiTableBulkIdStrategy
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.QueryException;
|
||||
import org.hibernate.ScrollMode;
|
||||
import org.hibernate.Session;
|
||||
@ -38,7 +39,6 @@
|
||||
import org.hibernate.cache.spi.access.EntityDataAccess;
|
||||
import org.hibernate.cache.spi.entry.CacheEntry;
|
||||
import org.hibernate.cache.spi.entry.ReferenceCacheEntryImpl;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.dialect.pagination.LimitHandler;
|
||||
import org.hibernate.dialect.pagination.LimitHelper;
|
||||
@ -1236,11 +1236,13 @@ private void endCollectionLoad(
|
||||
final Object resultSetId,
|
||||
final SharedSessionContractImplementor session,
|
||||
final CollectionPersister collectionPersister) {
|
||||
//this is a query and we are loading multiple instances of the same collection role
|
||||
session.getPersistenceContextInternal()
|
||||
.getLoadContexts()
|
||||
.getCollectionLoadContext( (ResultSet) resultSetId )
|
||||
.endLoadingCollections( collectionPersister );
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
|
||||
// //this is a query and we are loading multiple instances of the same collection role
|
||||
// session.getPersistenceContextInternal()
|
||||
// .getLoadContexts()
|
||||
// .getCollectionLoadContext( (ResultSet) resultSetId )
|
||||
// .endLoadingCollections( collectionPersister );
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1409,13 +1411,14 @@ private void readCollectionElement(
|
||||
}
|
||||
}
|
||||
|
||||
PersistentCollection rowCollection = persistenceContext.getLoadContexts()
|
||||
.getCollectionLoadContext( rs )
|
||||
.getLoadingCollection( persister, collectionRowKey );
|
||||
|
||||
if ( rowCollection != null ) {
|
||||
rowCollection.readFrom( rs, persister, descriptor, owner );
|
||||
}
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
// PersistentCollection rowCollection = persistenceContext.getLoadContexts()
|
||||
// .getCollectionLoadContext( rs )
|
||||
// .getLoadingCollection( persister, collectionRowKey );
|
||||
//
|
||||
// if ( rowCollection != null ) {
|
||||
// rowCollection.readFrom( rs, persister, descriptor, owner );
|
||||
// }
|
||||
|
||||
}
|
||||
else if ( optionalKey != null ) {
|
||||
@ -1430,9 +1433,10 @@ else if ( optionalKey != null ) {
|
||||
);
|
||||
}
|
||||
|
||||
persistenceContext.getLoadContexts()
|
||||
.getCollectionLoadContext( rs )
|
||||
.getLoadingCollection( persister, optionalKey ); // handle empty collection
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
// persistenceContext.getLoadContexts()
|
||||
// .getCollectionLoadContext( rs )
|
||||
// .getLoadingCollection( persister, optionalKey ); // handle empty collection
|
||||
|
||||
}
|
||||
|
||||
@ -1457,9 +1461,6 @@ private void handleEmptyCollections(
|
||||
CollectionPersister[] collectionPersisters = getCollectionPersisters();
|
||||
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
||||
final boolean debugEnabled = LOG.isDebugEnabled();
|
||||
final CollectionLoadContext collectionLoadContext = persistenceContext
|
||||
.getLoadContexts()
|
||||
.getCollectionLoadContext( (ResultSet) resultSetId );
|
||||
for ( CollectionPersister collectionPersister : collectionPersisters ) {
|
||||
for ( Serializable key : keys ) {
|
||||
//handle empty collections
|
||||
@ -1470,8 +1471,11 @@ private void handleEmptyCollections(
|
||||
);
|
||||
}
|
||||
|
||||
collectionLoadContext
|
||||
.getLoadingCollection( collectionPersister, key );
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
// session.getPersistenceContext()
|
||||
// .getLoadContexts()
|
||||
// .getCollectionLoadContext( (ResultSet) resultSetId )
|
||||
// .getLoadingCollection( collectionPersister, key );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.internal.CoreLogging;
|
||||
@ -66,20 +67,22 @@ public void finishUpRow(ResultSet resultSet, ResultSetProcessingContextImpl cont
|
||||
);
|
||||
}
|
||||
|
||||
Object collectionOwner = findCollectionOwner( collectionRowKey, resultSet, context );
|
||||
|
||||
PersistentCollection rowCollection = persistenceContext.getLoadContexts()
|
||||
.getCollectionLoadContext( resultSet )
|
||||
.getLoadingCollection( collectionReference.getCollectionPersister(), collectionRowKey );
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
|
||||
if ( rowCollection != null ) {
|
||||
rowCollection.readFrom(
|
||||
resultSet,
|
||||
collectionReference.getCollectionPersister(),
|
||||
aliases.getCollectionColumnAliases(),
|
||||
collectionOwner
|
||||
);
|
||||
}
|
||||
// Object collectionOwner = findCollectionOwner( collectionRowKey, resultSet, context );
|
||||
// PersistentCollection rowCollection = persistenceContext.getLoadContexts()
|
||||
// .getCollectionLoadContext( resultSet )
|
||||
// .getLoadingCollection( collectionReference.getCollectionPersister(), collectionRowKey );
|
||||
//
|
||||
// if ( rowCollection != null ) {
|
||||
// rowCollection.readFrom(
|
||||
// resultSet,
|
||||
// collectionReference.getCollectionPersister(),
|
||||
// aliases.getCollectionColumnAliases(),
|
||||
// collectionOwner
|
||||
// );
|
||||
// }
|
||||
|
||||
}
|
||||
else {
|
||||
@ -99,10 +102,12 @@ public void finishUpRow(ResultSet resultSet, ResultSetProcessingContextImpl cont
|
||||
)
|
||||
);
|
||||
}
|
||||
// handle empty collection
|
||||
persistenceContext.getLoadContexts()
|
||||
.getCollectionLoadContext( resultSet )
|
||||
.getLoadingCollection( collectionReference.getCollectionPersister(), optionalKey );
|
||||
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
// // handle empty collection
|
||||
// persistenceContext.getLoadContexts()
|
||||
// .getCollectionLoadContext( resultSet )
|
||||
// .getLoadingCollection( collectionReference.getCollectionPersister(), optionalKey );
|
||||
|
||||
}
|
||||
}
|
||||
@ -148,9 +153,10 @@ protected Serializable findCollectionOwnerKey(ResultSetProcessingContextImpl con
|
||||
|
||||
@Override
|
||||
public void endLoading(ResultSetProcessingContextImpl context) {
|
||||
context.getSession().getPersistenceContextInternal()
|
||||
.getLoadContexts()
|
||||
.getCollectionLoadContext( context.getResultSet() )
|
||||
.endLoadingCollections( collectionReference.getCollectionPersister() );
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
// context.getSession().getPersistenceContextInternal()
|
||||
// .getLoadContexts()
|
||||
// .getCollectionLoadContext( context.getResultSet() )
|
||||
// .endLoadingCollections( collectionReference.getCollectionPersister() );
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,6 @@
|
||||
import javax.persistence.metamodel.PluralAttribute;
|
||||
import javax.persistence.metamodel.Type;
|
||||
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.annotations.common.AssertionFailure;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.internal.EntityManagerMessageLogger;
|
||||
@ -492,32 +491,32 @@ private interface MemberResolver {
|
||||
private <X, Y> AttributeMetadata<X, Y> determineAttributeMetadata(
|
||||
AttributeContext<X> attributeContext,
|
||||
MemberResolver memberResolver) {
|
||||
LOG.trace(
|
||||
"Starting attribute metadata determination [" + attributeContext.getPropertyMapping()
|
||||
.getName() + "]"
|
||||
);
|
||||
final Property propertyMapping = attributeContext.getPropertyMapping();
|
||||
final String propertyName = propertyMapping.getName();
|
||||
|
||||
LOG.trace( "Starting attribute metadata determination [" + propertyName + "]" );
|
||||
|
||||
final Member member = memberResolver.resolveMember( attributeContext );
|
||||
LOG.trace( " Determined member [" + member + "]" );
|
||||
|
||||
final Value value = attributeContext.getPropertyMapping().getValue();
|
||||
final Value value = propertyMapping.getValue();
|
||||
final org.hibernate.type.Type type = value.getType();
|
||||
LOG.trace( " Determined type [name=" + type.getName() + ", class=" + type.getClass().getName() + "]" );
|
||||
|
||||
if ( type.isAnyType() ) {
|
||||
// ANY mappings are currently not supported in the JPA metamodel; see HHH-6589
|
||||
if ( context.isIgnoreUnsupported() ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException( "ANY not supported" );
|
||||
}
|
||||
return new SingularAttributeMetadataImpl<>(
|
||||
propertyMapping,
|
||||
attributeContext.getOwnerType(),
|
||||
member,
|
||||
AttributeClassification.ANY
|
||||
);
|
||||
}
|
||||
else if ( type.isAssociationType() ) {
|
||||
// collection or entity
|
||||
if ( type.isEntityType() ) {
|
||||
// entity
|
||||
return new SingularAttributeMetadataImpl<X, Y>(
|
||||
attributeContext.getPropertyMapping(),
|
||||
propertyMapping,
|
||||
attributeContext.getOwnerType(),
|
||||
member,
|
||||
determineSingularAssociationClassification( member )
|
||||
@ -528,21 +527,17 @@ else if ( type.isAssociationType() ) {
|
||||
final Collection collValue = (Collection) value;
|
||||
final Value elementValue = collValue.getElement();
|
||||
final org.hibernate.type.Type elementType = elementValue.getType();
|
||||
final boolean isManyToMany = isManyToMany( member );
|
||||
|
||||
// First, determine the type of the elements and use that to help determine the
|
||||
// collection type)
|
||||
final AttributeClassification elementClassification;
|
||||
final AttributeClassification attributeClassification;
|
||||
if ( elementType.isAnyType() ) {
|
||||
if ( context.isIgnoreUnsupported() ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException( "collection of any not supported yet" );
|
||||
}
|
||||
attributeClassification = AttributeClassification.ELEMENT_COLLECTION;
|
||||
elementClassification = AttributeClassification.ANY;
|
||||
}
|
||||
final boolean isManyToMany = isManyToMany( member );
|
||||
if ( elementValue instanceof Component ) {
|
||||
else if ( elementValue instanceof Component ) {
|
||||
elementClassification = AttributeClassification.EMBEDDED;
|
||||
attributeClassification = AttributeClassification.ELEMENT_COLLECTION;
|
||||
}
|
||||
@ -565,14 +560,9 @@ else if ( elementType.isAssociationType() ) {
|
||||
final org.hibernate.type.Type keyType = keyValue.getType();
|
||||
|
||||
if ( keyType.isAnyType() ) {
|
||||
if ( context.isIgnoreUnsupported() ) {
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
throw new UnsupportedOperationException( "collection of any not supported yet" );
|
||||
}
|
||||
indexClassification = AttributeClassification.ANY;
|
||||
}
|
||||
if ( keyValue instanceof Component ) {
|
||||
else if ( keyValue instanceof Component ) {
|
||||
indexClassification = AttributeClassification.EMBEDDED;
|
||||
}
|
||||
else if ( keyType.isAssociationType() ) {
|
||||
@ -589,7 +579,7 @@ else if ( value instanceof List ) {
|
||||
indexClassification = null;
|
||||
}
|
||||
return new PluralAttributeMetadataImpl(
|
||||
attributeContext.getPropertyMapping(),
|
||||
propertyMapping,
|
||||
attributeContext.getOwnerType(),
|
||||
member,
|
||||
attributeClassification,
|
||||
@ -617,10 +607,10 @@ else if ( value instanceof OneToMany ) {
|
||||
// );
|
||||
}
|
||||
}
|
||||
else if ( attributeContext.getPropertyMapping().isComposite() ) {
|
||||
else if ( propertyMapping.isComposite() ) {
|
||||
// component
|
||||
return new SingularAttributeMetadataImpl<>(
|
||||
attributeContext.getPropertyMapping(),
|
||||
propertyMapping,
|
||||
attributeContext.getOwnerType(),
|
||||
member,
|
||||
AttributeClassification.EMBEDDED
|
||||
@ -629,13 +619,13 @@ else if ( attributeContext.getPropertyMapping().isComposite() ) {
|
||||
else {
|
||||
// basic type
|
||||
return new SingularAttributeMetadataImpl<>(
|
||||
attributeContext.getPropertyMapping(),
|
||||
propertyMapping,
|
||||
attributeContext.getOwnerType(),
|
||||
member,
|
||||
AttributeClassification.BASIC
|
||||
);
|
||||
}
|
||||
throw new UnsupportedOperationException( "oops, we are missing something: " + attributeContext.getPropertyMapping() );
|
||||
throw new UnsupportedOperationException( "oops, we are missing something: " + propertyMapping );
|
||||
}
|
||||
|
||||
public static AttributeClassification determineSingularAssociationClassification(Member member) {
|
||||
|
@ -24,25 +24,16 @@
|
||||
import org.hibernate.internal.EntityManagerMessageLogger;
|
||||
import org.hibernate.internal.HEMLogging;
|
||||
import org.hibernate.mapping.Collection;
|
||||
import org.hibernate.mapping.MappedSuperclass;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.metamodel.model.domain.internal.EntityTypeImpl;
|
||||
import org.hibernate.metamodel.model.domain.internal.MappedSuperclassTypeImpl;
|
||||
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
|
||||
import org.hibernate.persister.collection.CollectionPersister;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.persister.spi.PersisterCreationContext;
|
||||
import org.hibernate.persister.spi.PersisterFactory;
|
||||
import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder;
|
||||
import org.hibernate.tuple.entity.EntityTuplizer;
|
||||
import org.hibernate.type.EntityType;
|
||||
import org.hibernate.type.Type;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
@ -63,14 +54,6 @@ public class InflightRuntimeMetamodel {
|
||||
private final Map<String, Set<String>> collectionRolesByEntityParticipant = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// JPA metamodel
|
||||
|
||||
private final Map<String, EntityDomainType<?>> jpaEntityTypeMap = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, MappedSuperclassDomainType<?>> jpaMappedSuperclassTypeMap = new ConcurrentHashMap<>();
|
||||
private Map<Class, EmbeddableDomainType<?>> jpaEmbeddableDescriptorMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Misc
|
||||
|
||||
@ -84,12 +67,9 @@ public InflightRuntimeMetamodel(TypeConfiguration typeConfiguration) {
|
||||
|
||||
public void processBootMetaModel(
|
||||
MetadataImplementor bootMetamodel,
|
||||
SqmCriteriaNodeBuilder criteriaBuilder,
|
||||
CacheImplementor cacheImplementor,
|
||||
PersisterFactory persisterFactory,
|
||||
RuntimeModelCreationContext modelCreationContext,
|
||||
JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting,
|
||||
JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) {
|
||||
RuntimeModelCreationContext modelCreationContext) {
|
||||
this.imports.putAll( bootMetamodel.getImports() );
|
||||
processBootEntities(
|
||||
bootMetamodel.getEntityBindings(),
|
||||
@ -107,13 +87,6 @@ public void processBootMetaModel(
|
||||
|
||||
finishDomainMetamodelInitialization();
|
||||
|
||||
processJpa(
|
||||
bootMetamodel,
|
||||
criteriaBuilder,
|
||||
jpaMetaModelPopulationSetting,
|
||||
jpaStaticMetaModelPopulationSetting
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public TypeConfiguration getTypeConfiguration() {
|
||||
@ -136,18 +109,6 @@ public Map<String, Set<String>> getCollectionRolesByEntityParticipant() {
|
||||
return collectionRolesByEntityParticipant;
|
||||
}
|
||||
|
||||
public Map<String, EntityDomainType<?>> getJpaEntityTypeMap() {
|
||||
return jpaEntityTypeMap;
|
||||
}
|
||||
|
||||
public Map<Class<?>, MappedSuperclassDomainType<?>> getJpaMappedSuperclassTypeMap() {
|
||||
return jpaMappedSuperclassTypeMap;
|
||||
}
|
||||
|
||||
public Map<Class, EmbeddableDomainType<?>> getJpaEmbeddableDescriptorMap() {
|
||||
return jpaEmbeddableDescriptorMap;
|
||||
}
|
||||
|
||||
public Map<String, String> getNameToImportNameMap() {
|
||||
return nameToImportNameMap;
|
||||
}
|
||||
@ -178,40 +139,6 @@ public EntityPersister findEntityDescriptor(String entityName) {
|
||||
return entityPersisterMap.get( entityName );
|
||||
}
|
||||
|
||||
private void processJpa(
|
||||
MetadataImplementor bootMetamodel,
|
||||
SqmCriteriaNodeBuilder criteriaBuilder,
|
||||
JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting,
|
||||
JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) {
|
||||
if ( jpaMetaModelPopulationSetting != JpaMetaModelPopulationSetting.DISABLED ) {
|
||||
MetadataContext context = new MetadataContext(
|
||||
this,
|
||||
criteriaBuilder,
|
||||
bootMetamodel.getMappedSuperclassMappingsCopy(),
|
||||
typeConfiguration,
|
||||
jpaMetaModelPopulationSetting,
|
||||
jpaStaticMetaModelPopulationSetting
|
||||
);
|
||||
|
||||
for ( PersistentClass entityBinding : bootMetamodel.getEntityBindings() ) {
|
||||
locateOrBuildEntityType( entityBinding, context, typeConfiguration );
|
||||
}
|
||||
handleUnusedMappedSuperclasses( context, typeConfiguration );
|
||||
|
||||
context.wrapUp();
|
||||
|
||||
this.nameToImportNameMap.putAll( bootMetamodel.getImports() );
|
||||
|
||||
this.jpaEntityTypeMap.putAll( context.getEntityTypesByEntityName() );
|
||||
this.jpaMappedSuperclassTypeMap.putAll( context.getMappedSuperclassTypeMap() );
|
||||
|
||||
for ( EmbeddableDomainType<?> embeddable : context.getEmbeddableTypeSet() ) {
|
||||
this.jpaEmbeddableDescriptorMap.put( embeddable.getJavaType(), embeddable );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void processBootEntities(
|
||||
java.util.Collection<PersistentClass> entityBindings,
|
||||
CacheImplementor cacheImplementor,
|
||||
@ -339,101 +266,6 @@ private static void registerEntityNameResolvers(
|
||||
}
|
||||
}
|
||||
|
||||
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, typeConfiguration );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static MappedSuperclassDomainType<?> locateOrBuildMappedSuperclassType(
|
||||
MappedSuperclass mappedSuperclass,
|
||||
MetadataContext context,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
MappedSuperclassDomainType<?> mappedSuperclassType = context.locateMappedSuperclassType( mappedSuperclass );
|
||||
if ( mappedSuperclassType == null ) {
|
||||
mappedSuperclassType = buildMappedSuperclassType( mappedSuperclass, context, typeConfiguration );
|
||||
}
|
||||
return mappedSuperclassType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static MappedSuperclassTypeImpl<?> buildMappedSuperclassType(
|
||||
MappedSuperclass mappedSuperclass,
|
||||
MetadataContext context,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass();
|
||||
IdentifiableDomainType<?> superType = superMappedSuperclass == null
|
||||
? null
|
||||
: 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, typeConfiguration );
|
||||
}
|
||||
final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration()
|
||||
.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( mappedSuperclass.getMappedClass() );
|
||||
MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(
|
||||
javaTypeDescriptor,
|
||||
mappedSuperclass,
|
||||
superType,
|
||||
typeConfiguration
|
||||
);
|
||||
|
||||
context.registerMappedSuperclassType( mappedSuperclass, mappedSuperclassType );
|
||||
return mappedSuperclassType;
|
||||
}
|
||||
|
||||
private static EntityDomainType<?> locateOrBuildEntityType(
|
||||
PersistentClass persistentClass,
|
||||
MetadataContext context,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
EntityDomainType<?> entityType = context.locateEntityType( persistentClass );
|
||||
if ( entityType == null ) {
|
||||
entityType = buildEntityType( persistentClass, context, typeConfiguration );
|
||||
}
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
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, typeConfiguration );
|
||||
//no mappedSuperclass, check for a super entity
|
||||
if ( superType == null ) {
|
||||
final PersistentClass superPersistentClass = persistentClass.getSuperclass();
|
||||
superType = superPersistentClass == null
|
||||
? null
|
||||
: locateOrBuildEntityType( superPersistentClass, context, typeConfiguration );
|
||||
}
|
||||
|
||||
final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration()
|
||||
.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( javaType );
|
||||
EntityTypeImpl entityType = new EntityTypeImpl(
|
||||
javaTypeDescriptor,
|
||||
superType,
|
||||
persistentClass,
|
||||
typeConfiguration
|
||||
);
|
||||
context.registerEntityType( persistentClass, entityType );
|
||||
context.popEntityWorkedOn( persistentClass );
|
||||
return entityType;
|
||||
}
|
||||
|
||||
public Map<String, String> getImports() {
|
||||
return imports;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
import javax.persistence.metamodel.Type;
|
||||
|
||||
import org.hibernate.Internal;
|
||||
import org.hibernate.annotations.common.AssertionFailure;
|
||||
import org.hibernate.internal.EntityManagerMessageLogger;
|
||||
import org.hibernate.internal.HEMLogging;
|
||||
@ -62,7 +63,8 @@
|
||||
* @author Steve Ebersole
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
class MetadataContext {
|
||||
@Internal
|
||||
public class MetadataContext {
|
||||
private static final EntityManagerMessageLogger LOG = HEMLogging.messageLogger( MetadataContext.class );
|
||||
|
||||
private final RuntimeModelCreationContext runtimeModelCreationContext;
|
||||
@ -70,7 +72,6 @@ class MetadataContext {
|
||||
private final SqmCriteriaNodeBuilder criteriaBuilder;
|
||||
private Set<MappedSuperclass> knownMappedSuperclasses;
|
||||
private TypeConfiguration typeConfiguration;
|
||||
private final boolean ignoreUnsupported;
|
||||
private final JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting;
|
||||
private final AttributeFactory attributeFactory = new AttributeFactory( this );
|
||||
|
||||
@ -97,15 +98,12 @@ public MetadataContext(
|
||||
InflightRuntimeMetamodel metamodel,
|
||||
SqmCriteriaNodeBuilder criteriaBuilder,
|
||||
Set<MappedSuperclass> mappedSuperclasses,
|
||||
TypeConfiguration typeConfiguration,
|
||||
JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting,
|
||||
JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting) {
|
||||
this.runtimeModelCreationContext = runtimeModelCreationContext;
|
||||
this.metamodel = metamodel;
|
||||
this.criteriaBuilder = criteriaBuilder;
|
||||
this.knownMappedSuperclasses = mappedSuperclasses;
|
||||
this.typeConfiguration = typeConfiguration;
|
||||
this.ignoreUnsupported = jpaMetaModelPopulationSetting == JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED;
|
||||
this.typeConfiguration = runtimeModelCreationContext.getTypeConfiguration();
|
||||
this.jpaStaticMetaModelPopulationSetting = jpaStaticMetaModelPopulationSetting;
|
||||
}
|
||||
|
||||
@ -129,10 +127,6 @@ InflightRuntimeMetamodel getMetamodel() {
|
||||
return metamodel;
|
||||
}
|
||||
|
||||
/*package*/ boolean isIgnoreUnsupported() {
|
||||
return ignoreUnsupported;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the {@linkplain Class java type} to {@link EntityTypeImpl} map.
|
||||
*
|
||||
@ -162,11 +156,7 @@ public Map<Class<?>, MappedSuperclassDomainType<?>> getMappedSuperclassTypeMap()
|
||||
return mappedSuperClassTypeMap;
|
||||
}
|
||||
|
||||
/*package*/ void registerEntityType(PersistentClass persistentClass, EntityTypeImpl<?> entityType) {
|
||||
if ( ignoreUnsupported && entityType.getBindableJavaType() == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
public void registerEntityType(PersistentClass persistentClass, EntityTypeImpl<?> entityType) {
|
||||
if ( entityType.getBindableJavaType() != null ) {
|
||||
entityTypes.put( entityType.getBindableJavaType(), entityType );
|
||||
}
|
||||
@ -176,14 +166,14 @@ public Map<Class<?>, MappedSuperclassDomainType<?>> getMappedSuperclassTypeMap()
|
||||
orderedMappings.add( persistentClass );
|
||||
}
|
||||
|
||||
/*package*/ void registerEmbeddableType(EmbeddableDomainType<?> embeddableType) {
|
||||
public void registerEmbeddableType(EmbeddableDomainType<?> embeddableType) {
|
||||
assert embeddableType.getJavaType() != null;
|
||||
assert ! Map.class.isAssignableFrom( embeddableType.getJavaType() );
|
||||
|
||||
embeddables.put( embeddableType.getJavaType(), embeddableType );
|
||||
}
|
||||
|
||||
/*package*/ void registerMappedSuperclassType(
|
||||
public void registerMappedSuperclassType(
|
||||
MappedSuperclass mappedSuperclass,
|
||||
MappedSuperclassDomainType<?> mappedSuperclassType) {
|
||||
mappedSuperclassByMappedSuperclassMapping.put( mappedSuperclass, mappedSuperclassType );
|
||||
|
@ -100,10 +100,8 @@ public RuntimeModelCreationProcess(
|
||||
* Perform the runtime metamodel creation based on the information obtained during
|
||||
* the first phase of booting, returning the
|
||||
*/
|
||||
public DomainMetamodel create(
|
||||
MetadataImplementor bootMetamodel,
|
||||
JpaMetaModelPopulationSetting jpaMetaModelPopulationSetting) {
|
||||
final RuntimeModelCreationContext persisterCreationContext = new RuntimeModelCreationContext() {
|
||||
public DomainMetamodel create(MetadataImplementor bootMetamodel) {
|
||||
final RuntimeModelCreationContext runtimeModelCreationContext = new RuntimeModelCreationContext() {
|
||||
@Override
|
||||
public BootstrapContext getBootstrapContext() {
|
||||
return bootstrapContext;
|
||||
@ -126,20 +124,21 @@ public MetadataImplementor getMetadata() {
|
||||
|
||||
primeSecondLevelCacheRegions( bootMetamodel );
|
||||
|
||||
final JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting = determineJpaMetaModelPopulationSetting( sessionFactory.getProperties() );
|
||||
|
||||
inflightRuntimeMetamodel.processBootMetaModel(
|
||||
bootMetamodel,
|
||||
sessionFactory.getQueryEngine().getCriteriaBuilder(),
|
||||
sessionFactory.getCache(),
|
||||
persisterFactory,
|
||||
persisterCreationContext,
|
||||
jpaMetaModelPopulationSetting,
|
||||
determineJpaMetaModelPopulationSetting(
|
||||
sessionFactory.getProperties() )
|
||||
|
||||
runtimeModelCreationContext
|
||||
);
|
||||
|
||||
final JpaMetamodel jpaMetamodel = new JpaMetamodelImpl(
|
||||
final JpaMetamodel jpaMetamodel = JpaMetamodelImpl.buildMetamodel(
|
||||
runtimeModelCreationContext,
|
||||
bootMetamodel,
|
||||
inflightRuntimeMetamodel,
|
||||
sessionFactory.getQueryEngine().getCriteriaBuilder(),
|
||||
jpaStaticMetaModelPopulationSetting,
|
||||
bootMetamodel.getNamedEntityGraphs().values()
|
||||
);
|
||||
|
||||
|
@ -15,7 +15,6 @@
|
||||
|
||||
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
|
||||
@ -47,8 +46,8 @@ public AbstractIdentifiableType(
|
||||
boolean hasIdClass,
|
||||
boolean hasIdentifierProperty,
|
||||
boolean versioned,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
super( typeName, javaTypeDescriptor, superType, typeConfiguration );
|
||||
JpaMetamodel jpaMetamodel) {
|
||||
super( typeName, javaTypeDescriptor, superType, jpaMetamodel );
|
||||
this.hasIdClass = hasIdClass;
|
||||
this.hasIdentifierProperty = hasIdentifierProperty;
|
||||
this.isVersioned = versioned;
|
||||
|
@ -21,7 +21,6 @@
|
||||
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.
|
||||
@ -38,7 +37,7 @@ public EntityTypeImpl(
|
||||
JavaTypeDescriptor<J> javaTypeDescriptor,
|
||||
IdentifiableDomainType<? super J> superType,
|
||||
PersistentClass persistentClass,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
JpaMetamodel jpaMetamodel) {
|
||||
super(
|
||||
persistentClass.getEntityName(),
|
||||
javaTypeDescriptor,
|
||||
@ -46,7 +45,7 @@ public EntityTypeImpl(
|
||||
persistentClass.getDeclaredIdentifierMapper() != null || ( superType != null && superType.hasIdClass() ),
|
||||
persistentClass.hasIdentifierProperty(),
|
||||
persistentClass.isVersioned(),
|
||||
typeConfiguration
|
||||
jpaMetamodel
|
||||
);
|
||||
this.jpaEntityName = persistentClass.getJpaEntityName();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.annotations.NamedEntityGraphDefinition;
|
||||
import org.hibernate.graph.internal.RootGraphImpl;
|
||||
import org.hibernate.graph.spi.AttributeNodeImplementor;
|
||||
@ -34,14 +35,21 @@
|
||||
import org.hibernate.internal.HEMLogging;
|
||||
import org.hibernate.internal.util.StringHelper;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.mapping.MappedSuperclass;
|
||||
import org.hibernate.mapping.PersistentClass;
|
||||
import org.hibernate.metamodel.internal.InflightRuntimeMetamodel;
|
||||
import org.hibernate.metamodel.model.domain.AbstractDomainType;
|
||||
import org.hibernate.metamodel.internal.JpaStaticMetaModelPopulationSetting;
|
||||
import org.hibernate.metamodel.internal.MetadataContext;
|
||||
import org.hibernate.metamodel.model.domain.EmbeddableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.EntityDomainType;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.metamodel.model.domain.ManagedDomainType;
|
||||
import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType;
|
||||
import org.hibernate.metamodel.spi.RuntimeModelCreationContext;
|
||||
import org.hibernate.query.sqm.internal.SqmCriteriaNodeBuilder;
|
||||
import org.hibernate.query.sqm.tree.domain.SqmPolymorphicRootDescriptor;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
@ -53,13 +61,9 @@ public class JpaMetamodelImpl implements JpaMetamodel {
|
||||
|
||||
private final TypeConfiguration typeConfiguration;
|
||||
|
||||
private final Map<String, EntityDomainType<?>> entityDescriptorMap;
|
||||
|
||||
private final Map<Class<?>, MappedSuperclassDomainType<?>> mappedSuperclassTypeMap;
|
||||
|
||||
private final Map<Class, EmbeddableDomainType<?>> embeddableDescriptorMap;
|
||||
|
||||
private final Map<String, String> nameToImportNameMap;
|
||||
private final Map<String, EntityDomainType<?>> jpaEntityTypeMap = new ConcurrentHashMap<>();
|
||||
private final Map<Class<?>, MappedSuperclassDomainType<?>> jpaMappedSuperclassTypeMap = new ConcurrentHashMap<>();
|
||||
private final Map<Class, EmbeddableDomainType<?>> jpaEmbeddableDescriptorMap = new ConcurrentHashMap<>();
|
||||
|
||||
private final transient Map<String, RootGraphImplementor> entityGraphMap = new ConcurrentHashMap<>();
|
||||
|
||||
@ -67,26 +71,14 @@ public class JpaMetamodelImpl implements JpaMetamodel {
|
||||
|
||||
private final Map<Class, String> entityProxyInterfaceMap;
|
||||
|
||||
private final Map<String, String> nameToImportNameMap;
|
||||
|
||||
public JpaMetamodelImpl(
|
||||
InflightRuntimeMetamodel runtimeMetamodel,
|
||||
java.util.Collection<NamedEntityGraphDefinition> namedEntityGraphDefinitions) {
|
||||
|
||||
public JpaMetamodelImpl(InflightRuntimeMetamodel runtimeMetamodel) {
|
||||
this.typeConfiguration = runtimeMetamodel.getTypeConfiguration();
|
||||
|
||||
entityDescriptorMap = runtimeMetamodel.getJpaEntityTypeMap();
|
||||
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 ) );
|
||||
|
||||
nameToImportNameMap = runtimeMetamodel.getNameToImportNameMap();
|
||||
entityProxyInterfaceMap = runtimeMetamodel.getEntityProxyInterfaceMap();
|
||||
applyNamedEntityGraphs( namedEntityGraphDefinitions );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -97,7 +89,7 @@ public TypeConfiguration getTypeConfiguration() {
|
||||
@Override
|
||||
public <X> EntityDomainType<X> entity(String entityName) {
|
||||
//noinspection unchecked
|
||||
return (EntityDomainType) entityDescriptorMap.get( entityName );
|
||||
return (EntityDomainType) jpaEntityTypeMap.get( entityName );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -125,17 +117,17 @@ public <X> EntityDomainType<X> resolveHqlEntityReference(String entityName) {
|
||||
public void visitManagedTypes(Consumer<ManagedDomainType<?>> action) {
|
||||
visitEntityTypes( (Consumer) action );
|
||||
visitEmbeddables( (Consumer) action );
|
||||
mappedSuperclassTypeMap.values().forEach( action );
|
||||
jpaMappedSuperclassTypeMap.values().forEach( action );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> ManagedDomainType<X> findManagedType(Class<X> cls) {
|
||||
ManagedType<?> type = entityDescriptorMap.get( cls );
|
||||
ManagedType<?> type = jpaEntityTypeMap.get( cls );
|
||||
if ( type == null ) {
|
||||
type = mappedSuperclassTypeMap.get( cls );
|
||||
type = jpaMappedSuperclassTypeMap.get( cls );
|
||||
}
|
||||
if ( type == null ) {
|
||||
type = embeddableDescriptorMap.get( cls );
|
||||
type = jpaEmbeddableDescriptorMap.get( cls );
|
||||
}
|
||||
if ( type == null ) {
|
||||
return null;
|
||||
@ -147,12 +139,12 @@ public <X> ManagedDomainType<X> findManagedType(Class<X> cls) {
|
||||
|
||||
@Override
|
||||
public void visitEntityTypes(Consumer<EntityDomainType<?>> action) {
|
||||
entityDescriptorMap.values().forEach( action );
|
||||
jpaEntityTypeMap.values().forEach( action );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> EntityDomainType<X> findEntityType(Class<X> cls) {
|
||||
final EntityType<?> entityType = entityDescriptorMap.get( cls );
|
||||
final EntityType<?> entityType = jpaEntityTypeMap.get( cls );
|
||||
if ( entityType == null ) {
|
||||
return null;
|
||||
}
|
||||
@ -162,7 +154,7 @@ public <X> EntityDomainType<X> findEntityType(Class<X> cls) {
|
||||
|
||||
@Override
|
||||
public void visitRootEntityTypes(Consumer<EntityDomainType<?>> action) {
|
||||
entityDescriptorMap.values().forEach(
|
||||
jpaEntityTypeMap.values().forEach(
|
||||
entityDomainType -> {
|
||||
if ( entityDomainType.getSuperType() == null ) {
|
||||
action.accept( entityDomainType );
|
||||
@ -173,17 +165,17 @@ public void visitRootEntityTypes(Consumer<EntityDomainType<?>> action) {
|
||||
|
||||
@Override
|
||||
public void visitEmbeddables(Consumer<EmbeddableDomainType<?>> action) {
|
||||
embeddableDescriptorMap.values().forEach( action );
|
||||
jpaEmbeddableDescriptorMap.values().forEach( action );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> ManagedDomainType<X> managedType(Class<X> cls) {
|
||||
ManagedType<?> type = entityDescriptorMap.get( cls );
|
||||
ManagedType<?> type = jpaEntityTypeMap.get( cls );
|
||||
if ( type == null ) {
|
||||
type = mappedSuperclassTypeMap.get( cls );
|
||||
type = jpaMappedSuperclassTypeMap.get( cls );
|
||||
}
|
||||
if ( type == null ) {
|
||||
type = embeddableDescriptorMap.get( cls );
|
||||
type = jpaEmbeddableDescriptorMap.get( cls );
|
||||
}
|
||||
if ( type == null ) {
|
||||
// per JPA
|
||||
@ -196,7 +188,7 @@ public <X> ManagedDomainType<X> managedType(Class<X> cls) {
|
||||
|
||||
@Override
|
||||
public <X> EntityDomainType<X> entity(Class<X> cls) {
|
||||
final EntityType<?> entityType = entityDescriptorMap.get( cls );
|
||||
final EntityType<?> entityType = jpaEntityTypeMap.get( cls );
|
||||
if ( entityType == null ) {
|
||||
throw new IllegalArgumentException( "Not an entity: " + cls );
|
||||
}
|
||||
@ -206,7 +198,7 @@ public <X> EntityDomainType<X> entity(Class<X> cls) {
|
||||
|
||||
@Override
|
||||
public <X> EmbeddableDomainType<X> embeddable(Class<X> cls) {
|
||||
final EmbeddableDomainType<?> embeddableType = embeddableDescriptorMap.get( cls );
|
||||
final EmbeddableDomainType<?> embeddableType = jpaEmbeddableDescriptorMap.get( cls );
|
||||
if ( embeddableType == null ) {
|
||||
throw new IllegalArgumentException( "Not an embeddable: " + cls );
|
||||
}
|
||||
@ -217,23 +209,23 @@ public <X> EmbeddableDomainType<X> embeddable(Class<X> cls) {
|
||||
@Override
|
||||
public Set<ManagedType<?>> getManagedTypes() {
|
||||
final int setSize = CollectionHelper.determineProperSizing(
|
||||
entityDescriptorMap.size() + mappedSuperclassTypeMap.size() + embeddableDescriptorMap.size()
|
||||
jpaEntityTypeMap.size() + jpaMappedSuperclassTypeMap.size() + jpaEmbeddableDescriptorMap.size()
|
||||
);
|
||||
final Set<ManagedType<?>> managedTypes = new HashSet<>( setSize );
|
||||
managedTypes.addAll( entityDescriptorMap.values() );
|
||||
managedTypes.addAll( mappedSuperclassTypeMap.values() );
|
||||
managedTypes.addAll( embeddableDescriptorMap.values() );
|
||||
managedTypes.addAll( jpaEntityTypeMap.values() );
|
||||
managedTypes.addAll( jpaMappedSuperclassTypeMap.values() );
|
||||
managedTypes.addAll( jpaEmbeddableDescriptorMap.values() );
|
||||
return managedTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<EntityType<?>> getEntities() {
|
||||
return new HashSet<>( entityDescriptorMap.values() );
|
||||
return new HashSet<>( jpaEntityTypeMap.values() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<EmbeddableType<?>> getEmbeddables() {
|
||||
return new HashSet<>( embeddableDescriptorMap.values() );
|
||||
return new HashSet<>( jpaEmbeddableDescriptorMap.values() );
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -405,7 +397,7 @@ private <X> Class<X> resolveRequestedClass(String entityName) {
|
||||
public <T> EntityDomainType<T> resolveEntityReference(Class<T> javaType) {
|
||||
// try the incoming Java type as a "strict" entity reference
|
||||
{
|
||||
final EntityDomainType<?> descriptor = entityDescriptorMap.get( javaType );
|
||||
final EntityDomainType<?> descriptor = jpaEntityTypeMap.get( javaType );
|
||||
if ( descriptor != null ) {
|
||||
return (EntityDomainType<T>) descriptor;
|
||||
}
|
||||
@ -415,7 +407,7 @@ public <T> EntityDomainType<T> resolveEntityReference(Class<T> javaType) {
|
||||
{
|
||||
final String proxyEntityName = entityProxyInterfaceMap.get( javaType );
|
||||
if ( proxyEntityName != null ) {
|
||||
return (EntityDomainType<T>) entityDescriptorMap.get( proxyEntityName );
|
||||
return (EntityDomainType<T>) jpaEntityTypeMap.get( proxyEntityName );
|
||||
}
|
||||
}
|
||||
|
||||
@ -445,4 +437,156 @@ public <T> EntityDomainType<T> resolveEntityReference(Class<T> javaType) {
|
||||
|
||||
throw new IllegalArgumentException( "Could not resolve entity reference : " + javaType.getName() );
|
||||
}
|
||||
|
||||
public static JpaMetamodel buildMetamodel(
|
||||
RuntimeModelCreationContext runtimeModelCreationContext,
|
||||
MetadataImplementor bootMetamodel,
|
||||
InflightRuntimeMetamodel inflightRuntimeMetamodel,
|
||||
SqmCriteriaNodeBuilder criteriaBuilder,
|
||||
JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting,
|
||||
java.util.Collection<NamedEntityGraphDefinition> namedEntityGraphDefinitions) {
|
||||
final JpaMetamodelImpl jpaMetamodel = new JpaMetamodelImpl( inflightRuntimeMetamodel );
|
||||
|
||||
jpaMetamodel.processJpa(
|
||||
runtimeModelCreationContext,
|
||||
bootMetamodel,
|
||||
inflightRuntimeMetamodel,
|
||||
criteriaBuilder,
|
||||
jpaStaticMetaModelPopulationSetting,
|
||||
namedEntityGraphDefinitions
|
||||
);
|
||||
|
||||
return jpaMetamodel;
|
||||
}
|
||||
|
||||
private void processJpa(
|
||||
RuntimeModelCreationContext runtimeModelCreationContext,
|
||||
MetadataImplementor bootMetamodel,
|
||||
InflightRuntimeMetamodel inflightRuntimeMetamodel,
|
||||
SqmCriteriaNodeBuilder criteriaBuilder,
|
||||
JpaStaticMetaModelPopulationSetting jpaStaticMetaModelPopulationSetting,
|
||||
java.util.Collection<NamedEntityGraphDefinition> namedEntityGraphDefinitions) {
|
||||
if ( jpaStaticMetaModelPopulationSetting != JpaStaticMetaModelPopulationSetting.DISABLED ) {
|
||||
MetadataContext context = new MetadataContext(
|
||||
runtimeModelCreationContext,
|
||||
inflightRuntimeMetamodel,
|
||||
criteriaBuilder,
|
||||
bootMetamodel.getMappedSuperclassMappingsCopy(),
|
||||
jpaStaticMetaModelPopulationSetting
|
||||
);
|
||||
|
||||
for ( PersistentClass entityBinding : bootMetamodel.getEntityBindings() ) {
|
||||
locateOrBuildEntityType( entityBinding, context, typeConfiguration );
|
||||
}
|
||||
handleUnusedMappedSuperclasses( context, typeConfiguration );
|
||||
|
||||
context.wrapUp();
|
||||
|
||||
this.nameToImportNameMap.putAll( bootMetamodel.getImports() );
|
||||
|
||||
this.jpaEntityTypeMap.putAll( context.getEntityTypesByEntityName() );
|
||||
this.jpaMappedSuperclassTypeMap.putAll( context.getMappedSuperclassTypeMap() );
|
||||
|
||||
for ( EmbeddableDomainType<?> embeddable : context.getEmbeddableTypeSet() ) {
|
||||
this.jpaEmbeddableDescriptorMap.put( embeddable.getJavaType(), embeddable );
|
||||
}
|
||||
}
|
||||
|
||||
applyNamedEntityGraphs( namedEntityGraphDefinitions );
|
||||
}
|
||||
|
||||
private EntityDomainType<?> locateOrBuildEntityType(
|
||||
PersistentClass persistentClass,
|
||||
MetadataContext context,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
EntityDomainType<?> entityType = context.locateEntityType( persistentClass );
|
||||
if ( entityType == null ) {
|
||||
entityType = buildEntityType( persistentClass, context, typeConfiguration );
|
||||
}
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private 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, typeConfiguration );
|
||||
//no mappedSuperclass, check for a super entity
|
||||
if ( superType == null ) {
|
||||
final PersistentClass superPersistentClass = persistentClass.getSuperclass();
|
||||
superType = superPersistentClass == null
|
||||
? null
|
||||
: locateOrBuildEntityType( superPersistentClass, context, typeConfiguration );
|
||||
}
|
||||
|
||||
final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration()
|
||||
.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( javaType );
|
||||
final EntityTypeImpl entityType = new EntityTypeImpl(
|
||||
javaTypeDescriptor,
|
||||
superType,
|
||||
persistentClass,
|
||||
this
|
||||
);
|
||||
context.registerEntityType( persistentClass, entityType );
|
||||
context.popEntityWorkedOn( persistentClass );
|
||||
return entityType;
|
||||
}
|
||||
|
||||
private 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, typeConfiguration );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MappedSuperclassDomainType<?> locateOrBuildMappedSuperclassType(
|
||||
MappedSuperclass mappedSuperclass,
|
||||
MetadataContext context,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
MappedSuperclassDomainType<?> mappedSuperclassType = context.locateMappedSuperclassType( mappedSuperclass );
|
||||
if ( mappedSuperclassType == null ) {
|
||||
mappedSuperclassType = buildMappedSuperclassType( mappedSuperclass, context, typeConfiguration );
|
||||
}
|
||||
return mappedSuperclassType;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private MappedSuperclassTypeImpl<?> buildMappedSuperclassType(
|
||||
MappedSuperclass mappedSuperclass,
|
||||
MetadataContext context,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
final MappedSuperclass superMappedSuperclass = mappedSuperclass.getSuperMappedSuperclass();
|
||||
IdentifiableDomainType<?> superType = superMappedSuperclass == null
|
||||
? null
|
||||
: 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, typeConfiguration );
|
||||
}
|
||||
final JavaTypeDescriptor javaTypeDescriptor = context.getTypeConfiguration()
|
||||
.getJavaTypeDescriptorRegistry()
|
||||
.getDescriptor( mappedSuperclass.getMappedClass() );
|
||||
final MappedSuperclassTypeImpl mappedSuperclassType = new MappedSuperclassTypeImpl(
|
||||
javaTypeDescriptor,
|
||||
mappedSuperclass,
|
||||
superType,
|
||||
this
|
||||
);
|
||||
|
||||
context.registerMappedSuperclassType( mappedSuperclass, mappedSuperclassType );
|
||||
return mappedSuperclassType;
|
||||
}
|
||||
}
|
||||
|
@ -11,9 +11,9 @@
|
||||
import org.hibernate.mapping.MappedSuperclass;
|
||||
import org.hibernate.metamodel.model.domain.AbstractIdentifiableType;
|
||||
import org.hibernate.metamodel.model.domain.IdentifiableDomainType;
|
||||
import org.hibernate.metamodel.model.domain.JpaMetamodel;
|
||||
import org.hibernate.metamodel.model.domain.MappedSuperclassDomainType;
|
||||
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
@ -24,7 +24,7 @@ public MappedSuperclassTypeImpl(
|
||||
JavaTypeDescriptor<X> javaTypeDescriptor,
|
||||
MappedSuperclass mappedSuperclass,
|
||||
IdentifiableDomainType<? super X> superType,
|
||||
TypeConfiguration typeConfiguration) {
|
||||
JpaMetamodel jpaMetamodel) {
|
||||
super(
|
||||
javaTypeDescriptor.getJavaType().getName(),
|
||||
javaTypeDescriptor,
|
||||
@ -32,7 +32,7 @@ public MappedSuperclassTypeImpl(
|
||||
mappedSuperclass.getDeclaredIdentifierMapper() != null || ( superType != null && superType.hasIdClass() ),
|
||||
mappedSuperclass.hasIdentifierProperty(),
|
||||
mappedSuperclass.isVersioned(),
|
||||
typeConfiguration
|
||||
jpaMetamodel
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@
|
||||
import org.hibernate.pretty.MessageHelper;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
import org.hibernate.sql.results.spi.LoadingCollectionEntry;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
@ -809,9 +810,13 @@ public Object getCollection(Serializable key, SharedSessionContractImplementor s
|
||||
final PersistenceContext persistenceContext = session.getPersistenceContextInternal();
|
||||
|
||||
final CollectionKey collectionKey = new CollectionKey( persister, key );
|
||||
PersistentCollection collection = null;
|
||||
|
||||
// check if collection is currently being loaded
|
||||
PersistentCollection collection = persistenceContext.getLoadContexts()
|
||||
.locateLoadingCollection( persister, collectionKey );
|
||||
final LoadingCollectionEntry loadingCollectionEntry = persistenceContext.getLoadContexts().findLoadingCollectionEntry( collectionKey );
|
||||
if ( loadingCollectionEntry != null ) {
|
||||
collection = loadingCollectionEntry.getCollectionInstance();
|
||||
}
|
||||
|
||||
if ( collection == null ) {
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.NotYetImplementedFor6Exception;
|
||||
import org.hibernate.annotations.Nationalized;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
@ -303,8 +304,9 @@ public int hashCode(Object x) throws HibernateException {
|
||||
|
||||
@Override
|
||||
public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws SQLException {
|
||||
verifyConfigured();
|
||||
return enumValueConverter.readValue( rs, names[0], session );
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
// verifyConfigured();
|
||||
// return enumValueConverter.readValue( rs, names[0], session );
|
||||
}
|
||||
|
||||
private void verifyConfigured() {
|
||||
@ -315,8 +317,9 @@ private void verifyConfigured() {
|
||||
|
||||
@Override
|
||||
public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException {
|
||||
verifyConfigured();
|
||||
enumValueConverter.writeValue( st, (Enum) value, index, session );
|
||||
throw new NotYetImplementedFor6Exception( getClass() );
|
||||
// verifyConfigured();
|
||||
// enumValueConverter.writeValue( st, (Enum) value, index, session );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,9 +28,9 @@
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.jpa.test.BaseEntityManagerFunctionalTestCase;
|
||||
import org.hibernate.metamodel.internal.JpaMetaModelPopulationSetting;
|
||||
import org.hibernate.metamodel.internal.RuntimeModelCreationProcess;
|
||||
|
||||
import org.hibernate.testing.boot.BootstrapContextImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@ -96,9 +96,10 @@ public void testBuildingMetamodelWithParameterizedCollection() {
|
||||
SessionFactoryImplementor sfi = (SessionFactoryImplementor) metadata.buildSessionFactory();
|
||||
|
||||
new RuntimeModelCreationProcess(
|
||||
BootstrapContextImpl.INSTANCE,
|
||||
sfi,
|
||||
( (MetadataImplementor) metadata ).getTypeConfiguration()
|
||||
).create( (MetadataImplementor) metadata, JpaMetaModelPopulationSetting.IGNORE_UNSUPPORTED );
|
||||
).create( (MetadataImplementor) metadata );
|
||||
sfi.close();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user