|
4 | 4 | */ |
5 | 5 | package org.hibernate.boot.models.spi; |
6 | 6 |
|
7 | | -import com.fasterxml.classmate.ResolvedType; |
8 | 7 | import jakarta.persistence.AttributeConverter; |
9 | | -import org.hibernate.boot.model.convert.internal.AutoApplicableConverterDescriptorBypassedImpl; |
10 | | -import org.hibernate.boot.model.convert.internal.AutoApplicableConverterDescriptorStandardImpl; |
11 | | -import org.hibernate.boot.model.convert.internal.ConverterHelper; |
12 | | -import org.hibernate.boot.model.convert.spi.AutoApplicableConverterDescriptor; |
13 | 8 | import org.hibernate.boot.model.convert.spi.ConverterDescriptor; |
14 | | -import org.hibernate.boot.model.convert.spi.JpaAttributeConverterCreationContext; |
15 | 9 | import org.hibernate.boot.model.convert.spi.RegisteredConversion; |
16 | | -import org.hibernate.boot.spi.ClassmateContext; |
17 | 10 | import org.hibernate.models.spi.AnnotationDescriptor; |
18 | | -import org.hibernate.resource.beans.spi.ManagedBean; |
19 | | -import org.hibernate.type.descriptor.converter.internal.JpaAttributeConverterImpl; |
20 | | -import org.hibernate.type.descriptor.converter.spi.JpaAttributeConverter; |
21 | | -import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry; |
22 | 11 |
|
23 | 12 | import java.lang.annotation.Annotation; |
24 | | -import java.util.List; |
25 | 13 | import java.util.Objects; |
26 | 14 |
|
27 | 15 | /** |
@@ -92,84 +80,4 @@ public AnnotationDescriptor<? extends Annotation> getSource() { |
92 | 80 | public String toString() { |
93 | 81 | return "ConversionRegistration( " + converterType.getName() + ", " + source.getAnnotationType().getSimpleName() + ", " + autoApply + ")"; |
94 | 82 | } |
95 | | - |
96 | | - public ConverterDescriptor<?,?> makeConverterDescriptor(ClassmateContext classmateContext) { |
97 | | - final List<ResolvedType> resolvedParamTypes = |
98 | | - ConverterHelper.resolveConverterClassParamTypes( converterType, classmateContext ); |
99 | | - final ResolvedType relationalType = resolvedParamTypes.get( 1 ); |
100 | | - final ResolvedType domainTypeToMatch = |
101 | | - void.class.equals( explicitDomainType ) |
102 | | - ? resolvedParamTypes.get( 0 ) |
103 | | - : classmateContext.getTypeResolver().resolve( explicitDomainType ); |
104 | | - return converterDescriptor( converterType, domainTypeToMatch, relationalType, autoApply ); |
105 | | - } |
106 | | - |
107 | | - static <X,Y> ConverterDescriptor<X,Y> converterDescriptor( |
108 | | - Class<? extends AttributeConverter<? extends X, ? extends Y>> converterType, |
109 | | - ResolvedType domainTypeToMatch, ResolvedType relationalType, boolean autoApply) { |
110 | | - @SuppressWarnings("unchecked") // work around weird fussiness in wildcard capture |
111 | | - final Class<? extends AttributeConverter<X, Y>> converterClass = |
112 | | - (Class<? extends AttributeConverter<X, Y>>) converterType; |
113 | | - return new ConverterDescriptorImpl<>( converterClass, domainTypeToMatch, relationalType, autoApply ); |
114 | | - } |
115 | | - |
116 | | - private static class ConverterDescriptorImpl<X,Y> implements ConverterDescriptor<X,Y> { |
117 | | - private final Class<? extends AttributeConverter<X, Y>> converterType; |
118 | | - private final ResolvedType domainTypeToMatch; |
119 | | - private final ResolvedType relationalType; |
120 | | - private final boolean autoApply; |
121 | | - |
122 | | - private final AutoApplicableConverterDescriptor autoApplyDescriptor; |
123 | | - |
124 | | - public ConverterDescriptorImpl( |
125 | | - Class<? extends AttributeConverter<X, Y>> converterType, |
126 | | - ResolvedType domainTypeToMatch, |
127 | | - ResolvedType relationalType, |
128 | | - boolean autoApply) { |
129 | | - this.converterType = converterType; |
130 | | - this.domainTypeToMatch = domainTypeToMatch; |
131 | | - this.relationalType = relationalType; |
132 | | - this.autoApply = autoApply; |
133 | | - |
134 | | - this.autoApplyDescriptor = autoApply |
135 | | - ? new AutoApplicableConverterDescriptorStandardImpl( this ) |
136 | | - : AutoApplicableConverterDescriptorBypassedImpl.INSTANCE; |
137 | | - } |
138 | | - |
139 | | - @Override |
140 | | - public Class<? extends AttributeConverter<X,Y>> getAttributeConverterClass() { |
141 | | - return converterType; |
142 | | - } |
143 | | - |
144 | | - @Override |
145 | | - public ResolvedType getDomainValueResolvedType() { |
146 | | - return domainTypeToMatch; |
147 | | - } |
148 | | - |
149 | | - @Override |
150 | | - public ResolvedType getRelationalValueResolvedType() { |
151 | | - return relationalType; |
152 | | - } |
153 | | - |
154 | | - @Override |
155 | | - public AutoApplicableConverterDescriptor getAutoApplyDescriptor() { |
156 | | - return autoApplyDescriptor; |
157 | | - } |
158 | | - |
159 | | - @Override |
160 | | - public JpaAttributeConverter<X, Y> createJpaAttributeConverter(JpaAttributeConverterCreationContext context) { |
161 | | - final var converterBean = context.getManagedBeanRegistry().getBean( converterType ); |
162 | | - |
163 | | - final JavaTypeRegistry javaTypeRegistry = context.getTypeConfiguration().getJavaTypeRegistry(); |
164 | | - javaTypeRegistry.resolveDescriptor( domainTypeToMatch.getErasedType() ); |
165 | | - |
166 | | - return new JpaAttributeConverterImpl<>( |
167 | | - (ManagedBean<? extends AttributeConverter<X, Y>>) converterBean, |
168 | | - javaTypeRegistry.getDescriptor( converterBean.getBeanClass() ), |
169 | | - javaTypeRegistry.resolveDescriptor( domainTypeToMatch.getErasedType() ), |
170 | | - javaTypeRegistry.resolveDescriptor( relationalType.getErasedType() ) |
171 | | - ); |
172 | | - } |
173 | | - } |
174 | | - |
175 | 83 | } |
0 commit comments