use of org.hibernate.annotations.CollectionIdJdbcTypeCode in project hibernate-orm by hibernate.
the class BasicValueBinder method prepareCollectionId.
private void prepareCollectionId(XProperty modelXProperty) {
final CollectionId collectionIdAnn = modelXProperty.getAnnotation(CollectionId.class);
if (collectionIdAnn == null) {
throw new MappingException("idbag mapping missing @CollectionId");
}
final ManagedBeanRegistry beanRegistry = getManagedBeanRegistry();
explicitBasicTypeName = null;
implicitJavaTypeAccess = (typeConfiguration) -> null;
explicitJavaTypeAccess = (typeConfiguration) -> {
final CollectionIdJavaType javaTypeAnn = findAnnotation(modelXProperty, CollectionIdJavaType.class);
if (javaTypeAnn != null) {
final Class<? extends BasicJavaType<?>> javaType = normalizeJavaType(javaTypeAnn.value());
if (javaType != null) {
final ManagedBean<? extends BasicJavaType<?>> bean = beanRegistry.getBean(javaType);
return bean.getBeanInstance();
}
}
return null;
};
explicitJdbcTypeAccess = (typeConfiguration) -> {
final CollectionIdJdbcType jdbcTypeAnn = findAnnotation(modelXProperty, CollectionIdJdbcType.class);
if (jdbcTypeAnn != null) {
final Class<? extends JdbcType> jdbcType = normalizeJdbcType(jdbcTypeAnn.value());
if (jdbcType != null) {
final ManagedBean<? extends JdbcType> managedBean = beanRegistry.getBean(jdbcType);
return managedBean.getBeanInstance();
}
}
final CollectionIdJdbcTypeCode jdbcTypeCodeAnn = findAnnotation(modelXProperty, CollectionIdJdbcTypeCode.class);
if (jdbcTypeCodeAnn != null) {
if (jdbcTypeCodeAnn.value() != Integer.MIN_VALUE) {
return typeConfiguration.getJdbcTypeRegistry().getDescriptor(jdbcTypeCodeAnn.value());
}
}
return null;
};
explicitMutabilityAccess = (typeConfiguration) -> {
final CollectionIdMutability mutabilityAnn = findAnnotation(modelXProperty, CollectionIdMutability.class);
if (mutabilityAnn != null) {
final Class<? extends MutabilityPlan<?>> mutability = normalizeMutability(mutabilityAnn.value());
if (mutability != null) {
final ManagedBean<? extends MutabilityPlan<?>> jtdBean = beanRegistry.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 there is a converter, check it for mutability-related annotations
if (converterDescriptor != null) {
final Mutability converterMutabilityAnn = converterDescriptor.getAttributeConverterClass().getAnnotation(Mutability.class);
if (converterMutabilityAnn != null) {
final ManagedBean<? extends MutabilityPlan<?>> jtdBean = beanRegistry.getBean(converterMutabilityAnn.value());
return jtdBean.getBeanInstance();
}
if (converterDescriptor.getAttributeConverterClass().isAnnotationPresent(Immutable.class)) {
return ImmutableMutabilityPlan.instance();
}
}
final Class<? extends UserType> customTypeImpl = Kind.ATTRIBUTE.mappingAccess.customType(modelXProperty);
if (customTypeImpl.isAnnotationPresent(Immutable.class)) {
return ImmutableMutabilityPlan.instance();
}
// generally, this will trigger usage of the `JavaType#getMutabilityPlan`
return null;
};
// todo (6.0) - handle generator
final String generator = collectionIdAnn.generator();
}
Aggregations