Skip to content

Commit

Permalink
HHH-14856 - Introduce @CustomType;
Browse files Browse the repository at this point in the history
HHH-14865 - Re-work @Any and @ManyToAny support;
HHH-14863 - Compositional definition of basic value mappings;
HHH-14864 - Drop legacy Type-based annotations

layer in missed support for `@MapKeyClass` and `@ElementCollection#targetClass` in BasicValue resolution as part of BasicValueBinder handling
  • Loading branch information
sebersole committed Oct 7, 2021
1 parent 9ad34c2 commit 95aa824
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
Expand Up @@ -44,6 +44,7 @@
* @see MapKeyJavaType
* @see CollectionIdJavaType
* @see ListIndexJavaType
* @see AnyKeyJavaType
*
* @since 6.0
*/
Expand Down
Expand Up @@ -11,6 +11,8 @@

import org.hibernate.type.descriptor.java.BasicJavaTypeDescriptor;

import jakarta.persistence.MapKeyClass;

import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
Expand All @@ -19,6 +21,8 @@
/**
* Form of {@link JavaType} for describing the key of a Map
*
* @see MapKeyClass
*
* @since 6.0
*/
@java.lang.annotation.Target({METHOD, FIELD, ANNOTATION_TYPE})
Expand Down
Expand Up @@ -8,7 +8,6 @@

import java.io.Serializable;
import java.lang.reflect.ParameterizedType;
import java.sql.Types;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -84,11 +83,12 @@

import org.jboss.logging.Logger;

import jakarta.persistence.DiscriminatorType;
import jakarta.persistence.ElementCollection;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.Id;
import jakarta.persistence.Lob;
import jakarta.persistence.MapKeyClass;
import jakarta.persistence.MapKeyEnumerated;
import jakarta.persistence.MapKeyTemporal;
import jakarta.persistence.Temporal;
Expand Down Expand Up @@ -139,7 +139,7 @@ public enum Kind {
private Map explicitLocalTypeParams;

private Function<TypeConfiguration, JdbcTypeDescriptor> explicitJdbcTypeAccess;
private Function<TypeConfiguration, BasicJavaTypeDescriptor> explicitJtdAccess;
private Function<TypeConfiguration, BasicJavaTypeDescriptor> explicitJavaTypeAccess;
private Function<TypeConfiguration, MutabilityPlan> explicitMutabilityAccess;
private Function<TypeConfiguration, java.lang.reflect.Type> implicitJavaTypeAccess;

Expand Down Expand Up @@ -390,7 +390,7 @@ private void prepareCollectionId(XProperty modelXProperty) {
explicitBasicTypeName = null;
implicitJavaTypeAccess = (typeConfiguration) -> null;

explicitJtdAccess = (typeConfiguration) -> {
explicitJavaTypeAccess = (typeConfiguration) -> {
final CollectionIdJavaType javaTypeAnn = modelXProperty.getAnnotation( CollectionIdJavaType.class );
if ( javaTypeAnn != null ) {
final Class<? extends BasicJavaTypeDescriptor<?>> javaType = normalizeJavaType( javaTypeAnn.value() );
Expand Down Expand Up @@ -515,7 +515,7 @@ private void prepareMapKey(
return null;
};

explicitJtdAccess = typeConfiguration -> {
explicitJavaTypeAccess = typeConfiguration -> {
final MapKeyJavaType javaTypeAnn = mapAttribute.getAnnotation( MapKeyJavaType.class );
if ( javaTypeAnn != null ) {
final Class<? extends BasicJavaTypeDescriptor<?>> jdbcTypeImpl = normalizeJavaType( javaTypeAnn.value() );
Expand All @@ -525,6 +525,11 @@ private void prepareMapKey(
}
}

final MapKeyClass mapKeyClassAnn = mapAttribute.getAnnotation( MapKeyClass.class );
if ( mapKeyClassAnn != null ) {
return (BasicJavaTypeDescriptor) typeConfiguration.getJavaTypeDescriptorRegistry().getDescriptor( mapKeyClassAnn.value() );
}

return null;
};

Expand Down Expand Up @@ -575,7 +580,7 @@ private void prepareListIndex(XProperty listAttribute) {
.getServiceRegistry()
.getService( ManagedBeanRegistry.class );

explicitJtdAccess = (typeConfiguration) -> {
explicitJavaTypeAccess = (typeConfiguration) -> {
final ListIndexJavaType javaTypeAnn = listAttribute.getAnnotation( ListIndexJavaType.class );
if ( javaTypeAnn != null ) {
final Class<? extends BasicJavaTypeDescriptor<?>> javaType = normalizeJavaType( javaTypeAnn.value() );
Expand Down Expand Up @@ -609,8 +614,6 @@ private void prepareListIndex(XProperty listAttribute) {

private void prepareCollectionElement(XProperty attributeXProperty, XClass elementTypeXClass) {

// todo (6.0) : @SqlType / @SqlTypeDescriptor

Class<T> javaType;
//noinspection unchecked
if ( elementTypeXClass == null && attributeXProperty.isArray() ) {
Expand Down Expand Up @@ -659,6 +662,24 @@ private void prepareCollectionElement(XProperty attributeXProperty, XClass eleme
}

normalSupplementalDetails( attributeXProperty, buildingContext );

// layer in support for JPA's approach for specifying a specific Java type for the collection elements...
final ElementCollection elementCollectionAnn = attributeXProperty.getAnnotation( ElementCollection.class );
if ( elementCollectionAnn != null
&& elementCollectionAnn.targetClass() != null
&& elementCollectionAnn.targetClass() != void.class ) {
final Function<TypeConfiguration, BasicJavaTypeDescriptor> original = explicitJavaTypeAccess;
explicitJavaTypeAccess = (typeConfiguration) -> {
final BasicJavaTypeDescriptor originalResult = original.apply( typeConfiguration );
if ( originalResult != null ) {
return originalResult;
}

return (BasicJavaTypeDescriptor) typeConfiguration
.getJavaTypeDescriptorRegistry()
.getDescriptor( elementCollectionAnn.targetClass() );
};
}
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -761,7 +782,7 @@ private void prepareAnyKey(XProperty modelXProperty) {
.getServiceRegistry()
.getService( ManagedBeanRegistry.class );

explicitJtdAccess = (typeConfiguration) -> {
explicitJavaTypeAccess = (typeConfiguration) -> {
final AnyKeyJavaType javaTypeAnn = modelXProperty.getAnnotation( AnyKeyJavaType.class );
if ( javaTypeAnn != null ) {
final Class<? extends BasicJavaTypeDescriptor<?>> javaType = normalizeJavaType( javaTypeAnn.value() );
Expand Down Expand Up @@ -891,7 +912,7 @@ private void normalSupplementalDetails(
.getServiceRegistry()
.getService( ManagedBeanRegistry.class );

explicitJtdAccess = typeConfiguration -> {
explicitJavaTypeAccess = typeConfiguration -> {
final JavaType javaTypeAnn = attributeXProperty.getAnnotation( JavaType.class );
if ( javaTypeAnn != null ) {
final Class<? extends BasicJavaTypeDescriptor<?>> javaType = normalizeJavaType( javaTypeAnn.value() );
Expand Down Expand Up @@ -1162,7 +1183,7 @@ else if ( isLob || isSerializable() ) {
basicValue.setJpaAttributeConverterDescriptor( converterDescriptor );

basicValue.setImplicitJavaTypeAccess( implicitJavaTypeAccess );
basicValue.setExplicitJavaTypeAccess( explicitJtdAccess );
basicValue.setExplicitJavaTypeAccess( explicitJavaTypeAccess );
basicValue.setExplicitJdbcTypeAccess( explicitJdbcTypeAccess );
basicValue.setExplicitMutabilityPlanAccess( explicitMutabilityAccess );

Expand Down

0 comments on commit 95aa824

Please sign in to comment.