use of org.hibernate.annotations.MapKeyJavaType in project hibernate-orm by hibernate.
the class BasicValueBinder method prepareMapKey.
private void prepareMapKey(XProperty mapAttribute, XClass modelPropertyTypeXClass) {
final XClass mapKeyClass;
if (modelPropertyTypeXClass == null) {
mapKeyClass = mapAttribute.getMapKey();
} else {
mapKeyClass = modelPropertyTypeXClass;
}
final Class<?> implicitJavaType = resolveJavaType(mapKeyClass);
implicitJavaTypeAccess = (typeConfiguration) -> implicitJavaType;
final MapKeyEnumerated mapKeyEnumeratedAnn = mapAttribute.getAnnotation(MapKeyEnumerated.class);
if (mapKeyEnumeratedAnn != null) {
enumType = mapKeyEnumeratedAnn.value();
}
final MapKeyTemporal mapKeyTemporalAnn = mapAttribute.getAnnotation(MapKeyTemporal.class);
if (mapKeyTemporalAnn != null) {
temporalPrecision = mapKeyTemporalAnn.value();
}
explicitJdbcTypeAccess = typeConfiguration -> {
final MapKeyJdbcType jdbcTypeAnn = findAnnotation(mapAttribute, MapKeyJdbcType.class);
if (jdbcTypeAnn != null) {
final Class<? extends JdbcType> jdbcTypeImpl = normalizeJdbcType(jdbcTypeAnn.value());
if (jdbcTypeImpl != null) {
return getManagedBeanRegistry().getBean(jdbcTypeImpl).getBeanInstance();
}
}
final MapKeyJdbcTypeCode jdbcTypeCodeAnn = findAnnotation(mapAttribute, MapKeyJdbcTypeCode.class);
if (jdbcTypeCodeAnn != null) {
final int jdbcTypeCode = jdbcTypeCodeAnn.value();
if (jdbcTypeCode != Integer.MIN_VALUE) {
return typeConfiguration.getJdbcTypeRegistry().getDescriptor(jdbcTypeCode);
}
}
return null;
};
explicitJavaTypeAccess = typeConfiguration -> {
final MapKeyJavaType javaTypeAnn = findAnnotation(mapAttribute, MapKeyJavaType.class);
if (javaTypeAnn != null) {
final Class<? extends BasicJavaType<?>> jdbcTypeImpl = normalizeJavaType(javaTypeAnn.value());
if (jdbcTypeImpl != null) {
final ManagedBean<? extends BasicJavaType> jdbcTypeBean = getManagedBeanRegistry().getBean(jdbcTypeImpl);
return jdbcTypeBean.getBeanInstance();
}
}
final MapKeyClass mapKeyClassAnn = mapAttribute.getAnnotation(MapKeyClass.class);
if (mapKeyClassAnn != null) {
return (BasicJavaType<?>) typeConfiguration.getJavaTypeRegistry().getDescriptor(mapKeyClassAnn.value());
}
return null;
};
explicitMutabilityAccess = typeConfiguration -> {
final MapKeyMutability mutabilityAnn = findAnnotation(mapAttribute, MapKeyMutability.class);
if (mutabilityAnn != null) {
final Class<? extends MutabilityPlan<?>> mutability = normalizeMutability(mutabilityAnn.value());
if (mutability != null) {
final ManagedBean<? extends MutabilityPlan<?>> jtdBean = getManagedBeanRegistry().getBean(mutability);
return jtdBean.getBeanInstance();
}
}
// see if the value's type Class is annotated `@Immutable`
if (implicitJavaTypeAccess != null) {
final Class<?> attributeType = ReflectHelper.getClass(implicitJavaTypeAccess.apply(typeConfiguration));
if (attributeType != null) {
if (attributeType.isAnnotationPresent(Immutable.class)) {
return ImmutableMutabilityPlan.instance();
}
}
}
// if the value is converted, see if the converter Class is annotated `@Immutable`
if (converterDescriptor != null) {
final Mutability converterMutabilityAnn = converterDescriptor.getAttributeConverterClass().getAnnotation(Mutability.class);
if (converterMutabilityAnn != null) {
final ManagedBean<? extends MutabilityPlan<?>> jtdBean = getManagedBeanRegistry().getBean(converterMutabilityAnn.value());
return jtdBean.getBeanInstance();
}
if (converterDescriptor.getAttributeConverterClass().isAnnotationPresent(Immutable.class)) {
return ImmutableMutabilityPlan.instance();
}
}
final Class<? extends UserType> customTypeImpl = Kind.MAP_KEY.mappingAccess.customType(mapAttribute);
if (customTypeImpl != null) {
if (customTypeImpl.isAnnotationPresent(Immutable.class)) {
return ImmutableMutabilityPlan.instance();
}
}
// generally, this will trigger usage of the `JavaType#getMutabilityPlan`
return null;
};
}
Aggregations