Search in sources :

Example 1 with ListIndexJavaType

use of org.hibernate.annotations.ListIndexJavaType in project hibernate-orm by hibernate.

the class BasicValueBinder method prepareListIndex.

private void prepareListIndex(XProperty listAttribute) {
    implicitJavaTypeAccess = typeConfiguration -> Integer.class;
    final ManagedBeanRegistry beanRegistry = buildingContext.getBootstrapContext().getServiceRegistry().getService(ManagedBeanRegistry.class);
    explicitJavaTypeAccess = (typeConfiguration) -> {
        final ListIndexJavaType javaTypeAnn = findAnnotation(listAttribute, ListIndexJavaType.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 ListIndexJdbcType jdbcTypeAnn = findAnnotation(listAttribute, ListIndexJdbcType.class);
        if (jdbcTypeAnn != null) {
            final Class<? extends JdbcType> jdbcType = normalizeJdbcType(jdbcTypeAnn.value());
            if (jdbcType != null) {
                final ManagedBean<? extends JdbcType> bean = beanRegistry.getBean(jdbcType);
                return bean.getBeanInstance();
            }
        }
        final ListIndexJdbcTypeCode jdbcTypeCodeAnn = findAnnotation(listAttribute, ListIndexJdbcTypeCode.class);
        if (jdbcTypeCodeAnn != null) {
            return typeConfiguration.getJdbcTypeRegistry().getDescriptor(jdbcTypeCodeAnn.value());
        }
        return null;
    };
}
Also used : ManagedBeanRegistry(org.hibernate.resource.beans.spi.ManagedBeanRegistry) ListIndexJavaType(org.hibernate.annotations.ListIndexJavaType) ListIndexJdbcTypeCode(org.hibernate.annotations.ListIndexJdbcTypeCode) ListIndexJdbcType(org.hibernate.annotations.ListIndexJdbcType)

Aggregations

ListIndexJavaType (org.hibernate.annotations.ListIndexJavaType)1 ListIndexJdbcType (org.hibernate.annotations.ListIndexJdbcType)1 ListIndexJdbcTypeCode (org.hibernate.annotations.ListIndexJdbcTypeCode)1 ManagedBeanRegistry (org.hibernate.resource.beans.spi.ManagedBeanRegistry)1