HHH-16783 split @Any discriminator handling into two subclasses
This commit is contained in:
parent
925d09528d
commit
3a8e66d600
|
@ -252,7 +252,8 @@ public class AttributeFactory {
|
|||
final org.hibernate.type.Type type = typeContext.getHibernateValue().getType();
|
||||
if ( type instanceof EntityType ) {
|
||||
final EntityType entityType = (EntityType) type;
|
||||
final IdentifiableDomainType<Y> domainType = context.locateIdentifiableType( entityType.getAssociatedEntityName() );
|
||||
final IdentifiableDomainType<Y> domainType =
|
||||
context.locateIdentifiableType( entityType.getAssociatedEntityName() );
|
||||
if ( domainType == null ) {
|
||||
// Due to the use of generics, it can happen that a mapped super class uses a type
|
||||
// for an attribute that is not a managed type. Since this case is not specifically mentioned
|
||||
|
@ -274,9 +275,7 @@ public class AttributeFactory {
|
|||
(Any) typeContext.getHibernateValue(),
|
||||
anyType,
|
||||
(JavaType<Class>) baseJtd,
|
||||
context.getTypeConfiguration(),
|
||||
context.getMetamodel(),
|
||||
context.getRuntimeModelCreationContext().getSessionFactory()
|
||||
context.getRuntimeModelCreationContext().getSessionFactory().getMappingMetamodel()
|
||||
);
|
||||
}
|
||||
case EMBEDDABLE: {
|
||||
|
@ -344,7 +343,8 @@ public class AttributeFactory {
|
|||
DomainType<?> metaModelType,
|
||||
MetadataContext context) {
|
||||
if ( typeContext.getValueClassification() == ValueClassification.BASIC ) {
|
||||
final ConverterDescriptor descriptor = ( (SimpleValue) typeContext.getHibernateValue() ).getJpaAttributeConverterDescriptor();
|
||||
final ConverterDescriptor descriptor =
|
||||
( (SimpleValue) typeContext.getHibernateValue() ).getJpaAttributeConverterDescriptor();
|
||||
if ( descriptor != null ) {
|
||||
return context.getJavaTypeRegistry().resolveDescriptor(
|
||||
descriptor.getRelationalValueResolvedType().getErasedType()
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* 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.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.metamodel.mapping.internal.DiscriminatorValueDetailsImpl;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Implements the default discriminator assignment strategy defined by JPA,
|
||||
* that is, the discriminator value is the JPA (unqualified) entity name.
|
||||
* This strategy is used when no explicit discriminator mapping is specified.
|
||||
*
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class DefaultDiscriminatorConverter<O,R> extends DiscriminatorConverter<O,R> {
|
||||
|
||||
public static <O,R> DefaultDiscriminatorConverter<O,R> fromMappingMetamodel(
|
||||
NavigableRole role,
|
||||
JavaType<O> domainJavaType,
|
||||
BasicType<R> underlyingJdbcMapping,
|
||||
MappingMetamodelImplementor mappingMetamodel) {
|
||||
return new DefaultDiscriminatorConverter<>(
|
||||
role,
|
||||
domainJavaType,
|
||||
underlyingJdbcMapping.getJavaTypeDescriptor(),
|
||||
mappingMetamodel
|
||||
);
|
||||
}
|
||||
|
||||
private final MappingMetamodelImplementor mappingMetamodel;
|
||||
|
||||
public DefaultDiscriminatorConverter(
|
||||
NavigableRole discriminatorRole,
|
||||
JavaType<O> domainJavaType,
|
||||
JavaType<R> relationalJavaType,
|
||||
MappingMetamodelImplementor mappingMetamodel) {
|
||||
super( discriminatorRole, domainJavaType, relationalJavaType );
|
||||
this.mappingMetamodel = mappingMetamodel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiscriminatorValueDetails getDetailsForRelationalForm(R relationalForm) {
|
||||
return getDetailsForDiscriminatorValue( relationalForm );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiscriminatorValueDetails getDetailsForEntityName(String entityName) {
|
||||
EntityPersister persister = mappingMetamodel.findEntityDescriptor( entityName );
|
||||
if ( persister!= null ) {
|
||||
return new DiscriminatorValueDetailsImpl( entityName, persister );
|
||||
}
|
||||
|
||||
throw new AssertionFailure( "Unrecognized entity name: " + entityName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiscriminatorValueDetails getDetailsForDiscriminatorValue(Object value) {
|
||||
if ( value instanceof String ) {
|
||||
String entityName = mappingMetamodel.getImportedName( (String) value );
|
||||
EntityPersister persister = mappingMetamodel.findEntityDescriptor( entityName );
|
||||
if ( persister!= null ) {
|
||||
return new DiscriminatorValueDetailsImpl( entityName, persister );
|
||||
}
|
||||
}
|
||||
|
||||
throw new HibernateException( "Unrecognized discriminator value: " + value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachValueDetail(Consumer<DiscriminatorValueDetails> consumer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> X fromValueDetails(Function<DiscriminatorValueDetails,X> handler) {
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -6,94 +6,31 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.mapping;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.hibernate.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.RepresentationMode;
|
||||
import org.hibernate.metamodel.mapping.internal.DiscriminatorValueDetailsImpl;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.persister.entity.EntityPersister;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
import static org.hibernate.persister.entity.DiscriminatorHelper.NOT_NULL_DISCRIMINATOR;
|
||||
import static org.hibernate.persister.entity.DiscriminatorHelper.NULL_DISCRIMINATOR;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Conversion of discriminator values between the entity name/Class domain form and
|
||||
* its generally CHARACTER or INTEGER based relational form
|
||||
*
|
||||
* @param <O> The domain type - either <ul>
|
||||
* <li>
|
||||
* the {@linkplain EntityMappingType#getMappedJavaType() entity Class} for unnamed entities
|
||||
* </li>
|
||||
* <li>
|
||||
* the {@linkplain EntityMappingType#getEntityName() entity name} for named entities
|
||||
* </li>
|
||||
* </ul>
|
||||
* @param <R> The Java type of the relational form of the discriminator
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
* @author Gavin King
|
||||
*/
|
||||
public class DiscriminatorConverter<O,R> implements BasicValueConverter<O,R> {
|
||||
public static <O,R> DiscriminatorConverter<O,R> fromValueMappings(
|
||||
NavigableRole role,
|
||||
JavaType<O> domainJavaType,
|
||||
BasicType<R> underlyingJdbcMapping,
|
||||
Map<Object,String> valueMappings,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
final MappingMetamodelImplementor mappingMetamodel = sessionFactory.getMappingMetamodel();
|
||||
final List<DiscriminatorValueDetails> valueDetailsList = CollectionHelper.arrayList( valueMappings.size() );
|
||||
valueMappings.forEach( (value, entityName) -> {
|
||||
final DiscriminatorValueDetails valueDetails = new DiscriminatorValueDetailsImpl(
|
||||
value,
|
||||
mappingMetamodel.getEntityDescriptor( entityName )
|
||||
);
|
||||
valueDetailsList.add( valueDetails );
|
||||
} );
|
||||
|
||||
return new DiscriminatorConverter<>(
|
||||
role,
|
||||
domainJavaType,
|
||||
underlyingJdbcMapping.getJavaTypeDescriptor(),
|
||||
valueDetailsList,
|
||||
mappingMetamodel
|
||||
);
|
||||
}
|
||||
public abstract class DiscriminatorConverter<O,R> implements BasicValueConverter<O,R> {
|
||||
|
||||
private final NavigableRole discriminatorRole;
|
||||
private final JavaType<O> domainJavaType;
|
||||
private final JavaType<R> relationalJavaType;
|
||||
|
||||
private final Map<Object, DiscriminatorValueDetails> discriminatorValueToEntityNameMap;
|
||||
private final Map<String,DiscriminatorValueDetails> entityNameToDiscriminatorValueMap;
|
||||
private final MappingMetamodelImplementor mappingMetamodel;
|
||||
|
||||
public DiscriminatorConverter(
|
||||
NavigableRole discriminatorRole,
|
||||
JavaType<O> domainJavaType,
|
||||
JavaType<R> relationalJavaType,
|
||||
List<DiscriminatorValueDetails> valueMappings,
|
||||
MappingMetamodelImplementor mappingMetamodel) {
|
||||
JavaType<R> relationalJavaType) {
|
||||
this.discriminatorRole = discriminatorRole;
|
||||
this.domainJavaType = domainJavaType;
|
||||
this.relationalJavaType = relationalJavaType;
|
||||
this.mappingMetamodel = mappingMetamodel;
|
||||
|
||||
this.discriminatorValueToEntityNameMap = CollectionHelper.concurrentMap( valueMappings.size() );
|
||||
this.entityNameToDiscriminatorValueMap = CollectionHelper.concurrentMap( valueMappings.size() );
|
||||
valueMappings.forEach( (valueDetails) -> {
|
||||
discriminatorValueToEntityNameMap.put( valueDetails.getValue(), valueDetails );
|
||||
entityNameToDiscriminatorValueMap.put( valueDetails.getIndicatedEntityName(), valueDetails );
|
||||
} );
|
||||
}
|
||||
|
||||
public NavigableRole getNavigableRole() {
|
||||
|
@ -131,46 +68,6 @@ public class DiscriminatorConverter<O,R> implements BasicValueConverter<O,R> {
|
|||
: (O) indicatedEntity.getEntityName();
|
||||
}
|
||||
|
||||
public DiscriminatorValueDetails getDetailsForEntityName(String entityName) {
|
||||
DiscriminatorValueDetails valueDetails = entityNameToDiscriminatorValueMap.get( entityName );
|
||||
if ( valueDetails!= null) {
|
||||
return valueDetails;
|
||||
}
|
||||
|
||||
EntityPersister persister = mappingMetamodel.findEntityDescriptor( entityName );
|
||||
if ( persister!= null ) {
|
||||
return new DiscriminatorValueDetailsImpl( entityName, persister );
|
||||
}
|
||||
|
||||
throw new AssertionFailure( "Unrecognized entity name: " + entityName );
|
||||
}
|
||||
|
||||
public DiscriminatorValueDetails getDetailsForDiscriminatorValue(Object value) {
|
||||
if ( value == null ) {
|
||||
return discriminatorValueToEntityNameMap.get( NULL_DISCRIMINATOR );
|
||||
}
|
||||
|
||||
final DiscriminatorValueDetails valueMatch = discriminatorValueToEntityNameMap.get( value );
|
||||
if ( valueMatch != null ) {
|
||||
return valueMatch;
|
||||
}
|
||||
|
||||
final DiscriminatorValueDetails notNullMatch = discriminatorValueToEntityNameMap.get( NOT_NULL_DISCRIMINATOR );
|
||||
if ( notNullMatch != null ) {
|
||||
return notNullMatch;
|
||||
}
|
||||
|
||||
if ( value instanceof String ) {
|
||||
String entityName = mappingMetamodel.getImportedName( (String) value );
|
||||
EntityPersister persister = mappingMetamodel.findEntityDescriptor( entityName );
|
||||
if ( persister!= null ) {
|
||||
return new DiscriminatorValueDetailsImpl( entityName, persister );
|
||||
}
|
||||
}
|
||||
|
||||
throw new HibernateException( "Unrecognized discriminator value: " + value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public R toRelationalValue(O domainForm) {
|
||||
assert domainForm == null || domainForm instanceof String || domainForm instanceof Class;
|
||||
|
@ -192,22 +89,16 @@ public class DiscriminatorConverter<O,R> implements BasicValueConverter<O,R> {
|
|||
return (R) discriminatorValueDetails.getValue();
|
||||
}
|
||||
|
||||
public abstract DiscriminatorValueDetails getDetailsForDiscriminatorValue(Object relationalForm);
|
||||
|
||||
public abstract DiscriminatorValueDetails getDetailsForEntityName(String entityName);
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DiscriminatorConverter(" + discriminatorRole.getFullPath() + ")";
|
||||
}
|
||||
|
||||
public void forEachValueDetail(Consumer<DiscriminatorValueDetails> consumer) {
|
||||
discriminatorValueToEntityNameMap.forEach( (value, detail) -> consumer.accept( detail ) );
|
||||
}
|
||||
public abstract void forEachValueDetail(Consumer<DiscriminatorValueDetails> consumer);
|
||||
|
||||
public <X> X fromValueDetails(Function<DiscriminatorValueDetails,X> handler) {
|
||||
for ( DiscriminatorValueDetails detail : discriminatorValueToEntityNameMap.values() ) {
|
||||
final X result = handler.apply( detail );
|
||||
if ( result != null ) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public abstract <X> X fromValueDetails(Function<DiscriminatorValueDetails,X> handler);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* 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.AssertionFailure;
|
||||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.internal.util.collections.CollectionHelper;
|
||||
import org.hibernate.metamodel.mapping.internal.DiscriminatorValueDetailsImpl;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.hibernate.persister.entity.DiscriminatorHelper.NOT_NULL_DISCRIMINATOR;
|
||||
import static org.hibernate.persister.entity.DiscriminatorHelper.NULL_DISCRIMINATOR;
|
||||
|
||||
/**
|
||||
* Conversion of discriminator values between the entity name/Class domain form and
|
||||
* its generally CHARACTER or INTEGER based relational form
|
||||
*
|
||||
* @param <O> The domain type - either <ul>
|
||||
* <li>
|
||||
* the {@linkplain EntityMappingType#getMappedJavaType() entity Class} for unnamed entities
|
||||
* </li>
|
||||
* <li>
|
||||
* the {@linkplain EntityMappingType#getEntityName() entity name} for named entities
|
||||
* </li>
|
||||
* </ul>
|
||||
* @param <R> The Java type of the relational form of the discriminator
|
||||
*
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
public class MappedDiscriminatorConverter<O,R> extends DiscriminatorConverter<O,R> {
|
||||
|
||||
public static <O,R> MappedDiscriminatorConverter<O,R> fromValueMappings(
|
||||
NavigableRole role,
|
||||
JavaType<O> domainJavaType,
|
||||
BasicType<R> underlyingJdbcMapping,
|
||||
Map<Object,String> valueMappings,
|
||||
MappingMetamodelImplementor mappingMetamodel) {
|
||||
final List<DiscriminatorValueDetails> valueDetailsList = CollectionHelper.arrayList( valueMappings.size() );
|
||||
valueMappings.forEach( (value, entityName) -> {
|
||||
final DiscriminatorValueDetails valueDetails = new DiscriminatorValueDetailsImpl(
|
||||
value,
|
||||
mappingMetamodel.getEntityDescriptor( entityName )
|
||||
);
|
||||
valueDetailsList.add( valueDetails );
|
||||
} );
|
||||
|
||||
return new MappedDiscriminatorConverter<>(
|
||||
role,
|
||||
domainJavaType,
|
||||
underlyingJdbcMapping.getJavaTypeDescriptor(),
|
||||
valueDetailsList
|
||||
);
|
||||
}
|
||||
|
||||
private final Map<Object, DiscriminatorValueDetails> discriminatorValueToEntityNameMap;
|
||||
private final Map<String,DiscriminatorValueDetails> entityNameToDiscriminatorValueMap;
|
||||
|
||||
public MappedDiscriminatorConverter(
|
||||
NavigableRole discriminatorRole,
|
||||
JavaType<O> domainJavaType,
|
||||
JavaType<R> relationalJavaType,
|
||||
List<DiscriminatorValueDetails> valueMappings) {
|
||||
super( discriminatorRole, domainJavaType, relationalJavaType );
|
||||
|
||||
this.discriminatorValueToEntityNameMap = CollectionHelper.concurrentMap( valueMappings.size() );
|
||||
this.entityNameToDiscriminatorValueMap = CollectionHelper.concurrentMap( valueMappings.size() );
|
||||
valueMappings.forEach( (valueDetails) -> {
|
||||
discriminatorValueToEntityNameMap.put( valueDetails.getValue(), valueDetails );
|
||||
entityNameToDiscriminatorValueMap.put( valueDetails.getIndicatedEntityName(), valueDetails );
|
||||
} );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiscriminatorValueDetails getDetailsForRelationalForm(R relationalForm) {
|
||||
return getDetailsForDiscriminatorValue( relationalForm );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiscriminatorValueDetails getDetailsForEntityName(String entityName) {
|
||||
DiscriminatorValueDetails valueDetails = entityNameToDiscriminatorValueMap.get( entityName );
|
||||
if ( valueDetails!= null) {
|
||||
return valueDetails;
|
||||
}
|
||||
|
||||
throw new AssertionFailure( "Unrecognized entity name: " + entityName );
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiscriminatorValueDetails getDetailsForDiscriminatorValue(Object value) {
|
||||
if ( value == null ) {
|
||||
return discriminatorValueToEntityNameMap.get( NULL_DISCRIMINATOR );
|
||||
}
|
||||
|
||||
final DiscriminatorValueDetails valueMatch = discriminatorValueToEntityNameMap.get( value );
|
||||
if ( valueMatch != null ) {
|
||||
return valueMatch;
|
||||
}
|
||||
|
||||
final DiscriminatorValueDetails notNullMatch = discriminatorValueToEntityNameMap.get( NOT_NULL_DISCRIMINATOR );
|
||||
if ( notNullMatch != null ) {
|
||||
return notNullMatch;
|
||||
}
|
||||
|
||||
throw new HibernateException( "Unrecognized discriminator value: " + value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEachValueDetail(Consumer<DiscriminatorValueDetails> consumer) {
|
||||
discriminatorValueToEntityNameMap.forEach( (value, detail) -> consumer.accept( detail ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public <X> X fromValueDetails(Function<DiscriminatorValueDetails,X> handler) {
|
||||
for ( DiscriminatorValueDetails detail : discriminatorValueToEntityNameMap.values() ) {
|
||||
final X result = handler.apply( detail );
|
||||
if ( result != null ) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -15,15 +15,18 @@ import org.hibernate.engine.FetchTiming;
|
|||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||
import org.hibernate.internal.util.IndexedConsumer;
|
||||
import org.hibernate.metamodel.mapping.DefaultDiscriminatorConverter;
|
||||
import org.hibernate.metamodel.mapping.DiscriminatedAssociationModelPart;
|
||||
import org.hibernate.metamodel.mapping.DiscriminatorConverter;
|
||||
import org.hibernate.metamodel.mapping.DiscriminatorMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
|
||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.metamodel.mapping.MappedDiscriminatorConverter;
|
||||
import org.hibernate.metamodel.mapping.MappingType;
|
||||
import org.hibernate.metamodel.mapping.SelectableConsumer;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.spi.NavigablePath;
|
||||
import org.hibernate.sql.ast.spi.FromClauseAccess;
|
||||
import org.hibernate.sql.ast.spi.SqlAstCreationState;
|
||||
|
@ -39,6 +42,7 @@ import org.hibernate.sql.results.graph.FetchOptions;
|
|||
import org.hibernate.sql.results.graph.FetchParent;
|
||||
import org.hibernate.sql.results.graph.basic.BasicFetch;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
|
||||
import org.hibernate.type.descriptor.java.ClassJavaType;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
|
||||
|
@ -81,7 +85,7 @@ public class AnyDiscriminatorPart implements DiscriminatorMapping, FetchOptions
|
|||
boolean partitioned,
|
||||
BasicType<?> underlyingJdbcMapping,
|
||||
Map<Object,String> valueToEntityNameMap,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
MappingMetamodelImplementor mappingMetamodel) {
|
||||
this.navigableRole = partRole;
|
||||
this.declaringType = declaringType;
|
||||
this.table = table;
|
||||
|
@ -95,13 +99,20 @@ public class AnyDiscriminatorPart implements DiscriminatorMapping, FetchOptions
|
|||
this.partitioned = partitioned;
|
||||
|
||||
this.underlyingJdbcMapping = underlyingJdbcMapping;
|
||||
this.valueConverter = DiscriminatorConverter.fromValueMappings(
|
||||
partRole,
|
||||
ClassJavaType.INSTANCE,
|
||||
underlyingJdbcMapping,
|
||||
valueToEntityNameMap,
|
||||
sessionFactory
|
||||
);
|
||||
this.valueConverter = valueToEntityNameMap.isEmpty()
|
||||
? DefaultDiscriminatorConverter.fromMappingMetamodel(
|
||||
partRole,
|
||||
ClassJavaType.INSTANCE,
|
||||
underlyingJdbcMapping,
|
||||
mappingMetamodel
|
||||
)
|
||||
: MappedDiscriminatorConverter.fromValueMappings(
|
||||
partRole,
|
||||
ClassJavaType.INSTANCE,
|
||||
underlyingJdbcMapping,
|
||||
valueToEntityNameMap,
|
||||
mappingMetamodel
|
||||
);
|
||||
}
|
||||
|
||||
public DiscriminatorConverter<?,?> getValueConverter() {
|
||||
|
|
|
@ -95,7 +95,7 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption
|
|||
bootValueMapping.isPartitionKey(),
|
||||
(BasicType<?>) metaType.getBaseType(),
|
||||
metaType.getDiscriminatorValuesToEntityNameMap(),
|
||||
creationProcess.getCreationContext().getSessionFactory()
|
||||
creationProcess.getCreationContext().getSessionFactory().getMappingMetamodel()
|
||||
);
|
||||
|
||||
|
||||
|
@ -163,14 +163,18 @@ public class DiscriminatedAssociationMapping implements MappingType, FetchOption
|
|||
}
|
||||
|
||||
public Object resolveDiscriminatorValueToEntityMapping(EntityMappingType entityMappingType) {
|
||||
final DiscriminatorValueDetails details = discriminatorPart.getValueConverter().getDetailsForEntityName( entityMappingType.getEntityName() );
|
||||
final DiscriminatorValueDetails details =
|
||||
discriminatorPart.getValueConverter()
|
||||
.getDetailsForEntityName( entityMappingType.getEntityName() );
|
||||
return details != null
|
||||
? details.getValue()
|
||||
: null;
|
||||
}
|
||||
|
||||
public EntityMappingType resolveDiscriminatorValueToEntityMapping(Object discriminatorValue) {
|
||||
final DiscriminatorValueDetails details = discriminatorPart.getValueConverter().getDetailsForDiscriminatorValue( discriminatorValue );
|
||||
final DiscriminatorValueDetails details =
|
||||
discriminatorPart.getValueConverter().
|
||||
getDetailsForDiscriminatorValue( discriminatorValue );
|
||||
return details != null
|
||||
? details.getIndicatedEntity()
|
||||
: null;
|
||||
|
|
|
@ -6,26 +6,22 @@
|
|||
*/
|
||||
package org.hibernate.metamodel.model.domain.internal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.mapping.Any;
|
||||
import org.hibernate.mapping.Column;
|
||||
import org.hibernate.metamodel.MappingMetamodel;
|
||||
import org.hibernate.metamodel.mapping.DiscriminatorConverter;
|
||||
import org.hibernate.metamodel.mapping.internal.AnyDiscriminatorPart;
|
||||
import org.hibernate.metamodel.mapping.DefaultDiscriminatorConverter;
|
||||
import org.hibernate.metamodel.mapping.MappedDiscriminatorConverter;
|
||||
import org.hibernate.metamodel.model.domain.AnyMappingDomainType;
|
||||
import org.hibernate.metamodel.model.domain.NavigableRole;
|
||||
import org.hibernate.metamodel.model.domain.SimpleDomainType;
|
||||
import org.hibernate.metamodel.spi.MappingMetamodelImplementor;
|
||||
import org.hibernate.type.AnyType;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.MetaType;
|
||||
import org.hibernate.type.descriptor.converter.spi.BasicValueConverter;
|
||||
import org.hibernate.type.descriptor.java.ClassJavaType;
|
||||
import org.hibernate.type.descriptor.java.JavaType;
|
||||
import org.hibernate.type.descriptor.java.ObjectJavaType;
|
||||
import org.hibernate.type.internal.ConvertedBasicTypeImpl;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
|
@ -40,9 +36,7 @@ public class AnyMappingDomainTypeImpl implements AnyMappingDomainType<Class> {
|
|||
Any bootAnyMapping,
|
||||
AnyType anyType,
|
||||
JavaType<Class> baseJtd,
|
||||
TypeConfiguration typeConfiguration,
|
||||
MappingMetamodel mappingMetamodel,
|
||||
SessionFactoryImplementor sessionFactory) {
|
||||
MappingMetamodelImplementor mappingMetamodel) {
|
||||
this.anyType = anyType;
|
||||
this.baseJtd = baseJtd;
|
||||
|
||||
|
@ -53,12 +47,19 @@ public class AnyMappingDomainTypeImpl implements AnyMappingDomainType<Class> {
|
|||
anyDiscriminatorType = new ConvertedBasicTypeImpl<>(
|
||||
navigableRole.getFullPath(),
|
||||
discriminatorBaseType.getJdbcType(),
|
||||
DiscriminatorConverter.fromValueMappings(
|
||||
bootAnyMapping.getMetaValues().isEmpty()
|
||||
? DefaultDiscriminatorConverter.fromMappingMetamodel(
|
||||
navigableRole,
|
||||
(JavaType) ClassJavaType.INSTANCE,
|
||||
ClassJavaType.INSTANCE,
|
||||
discriminatorBaseType,
|
||||
mappingMetamodel
|
||||
)
|
||||
: MappedDiscriminatorConverter.fromValueMappings(
|
||||
navigableRole,
|
||||
ClassJavaType.INSTANCE,
|
||||
discriminatorBaseType,
|
||||
bootAnyMapping.getMetaValues(),
|
||||
sessionFactory
|
||||
mappingMetamodel
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -167,6 +167,7 @@ import org.hibernate.metamodel.mapping.EntityVersionMapping;
|
|||
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
||||
import org.hibernate.metamodel.mapping.JdbcMapping;
|
||||
import org.hibernate.metamodel.mapping.ManagedMappingType;
|
||||
import org.hibernate.metamodel.mapping.MappedDiscriminatorConverter;
|
||||
import org.hibernate.metamodel.mapping.MappingModelHelper;
|
||||
import org.hibernate.metamodel.mapping.ModelPart;
|
||||
import org.hibernate.metamodel.mapping.NaturalIdMapping;
|
||||
|
@ -2274,12 +2275,12 @@ public abstract class AbstractEntityPersister
|
|||
}
|
||||
|
||||
//noinspection rawtypes
|
||||
final DiscriminatorConverter converter = DiscriminatorConverter.fromValueMappings(
|
||||
final DiscriminatorConverter converter = MappedDiscriminatorConverter.fromValueMappings(
|
||||
getNavigableRole().append( EntityDiscriminatorMapping.ROLE_NAME ),
|
||||
domainJavaType,
|
||||
underlingJdbcMapping,
|
||||
getSubclassByDiscriminatorValue(),
|
||||
factory
|
||||
factory.getMappingMetamodel()
|
||||
);
|
||||
|
||||
//noinspection unchecked,rawtypes
|
||||
|
|
Loading…
Reference in New Issue