Search in sources :

Example 1 with Temporal

use of jakarta.persistence.Temporal in project hibernate-orm by hibernate.

the class BasicValueBinder method prepareBasicAttribute.

private void prepareBasicAttribute(String declaringClassName, XProperty attributeDescriptor, XClass attributeType) {
    final Class<?> javaType = resolveJavaType(attributeType);
    implicitJavaTypeAccess = typeConfiguration -> javaType;
    final Temporal temporalAnn = attributeDescriptor.getAnnotation(Temporal.class);
    if (temporalAnn != null) {
        this.temporalPrecision = temporalAnn.value();
        if (this.temporalPrecision == null) {
            throw new IllegalStateException("No jakarta.persistence.TemporalType defined for @jakarta.persistence.Temporal " + "associated with attribute " + attributeDescriptor.getDeclaringClass().getName() + '.' + attributeDescriptor.getName());
        }
    } else {
        this.temporalPrecision = null;
    }
    if (javaType.isEnum()) {
        final Enumerated enumeratedAnn = attributeDescriptor.getAnnotation(Enumerated.class);
        if (enumeratedAnn != null) {
            this.enumType = enumeratedAnn.value();
            if (this.enumType == null) {
                throw new IllegalStateException("jakarta.persistence.EnumType was null on @jakarta.persistence.Enumerated " + " associated with attribute " + attributeDescriptor.getDeclaringClass().getName() + '.' + attributeDescriptor.getName());
            }
        }
    } else {
        if (attributeDescriptor.isAnnotationPresent(Enumerated.class)) {
            throw new AnnotationException(String.format("Attribute [%s.%s] was annotated as enumerated, but its java type is not an enum [%s]", declaringClassName, attributeDescriptor.getName(), attributeType.getName()));
        }
        this.enumType = null;
    }
    normalSupplementalDetails(attributeDescriptor);
}
Also used : MapKeyEnumerated(jakarta.persistence.MapKeyEnumerated) Enumerated(jakarta.persistence.Enumerated) Temporal(jakarta.persistence.Temporal) MapKeyTemporal(jakarta.persistence.MapKeyTemporal) AnnotationException(org.hibernate.AnnotationException)

Example 2 with Temporal

use of jakarta.persistence.Temporal in project hibernate-orm by hibernate.

the class BasicValueBinder method normalSupplementalDetails.

private void normalSupplementalDetails(XProperty attributeXProperty) {
    explicitJavaTypeAccess = typeConfiguration -> {
        final org.hibernate.annotations.JavaType javaTypeAnn = findAnnotation(attributeXProperty, org.hibernate.annotations.JavaType.class);
        if (javaTypeAnn != null) {
            final Class<? extends BasicJavaType<?>> javaType = normalizeJavaType(javaTypeAnn.value());
            if (javaType != null) {
                final ManagedBean<? extends BasicJavaType<?>> jtdBean = getManagedBeanRegistry().getBean(javaType);
                return jtdBean.getBeanInstance();
            }
        }
        final Target targetAnn = findAnnotation(attributeXProperty, Target.class);
        if (targetAnn != null) {
            return (BasicJavaType<?>) typeConfiguration.getJavaTypeRegistry().getDescriptor(targetAnn.value());
        }
        return null;
    };
    normalJdbcTypeDetails(attributeXProperty);
    normalMutabilityDetails(attributeXProperty);
    final Enumerated enumeratedAnn = attributeXProperty.getAnnotation(Enumerated.class);
    if (enumeratedAnn != null) {
        enumType = enumeratedAnn.value();
    }
    final Temporal temporalAnn = attributeXProperty.getAnnotation(Temporal.class);
    if (temporalAnn != null) {
        temporalPrecision = temporalAnn.value();
    }
}
Also used : MapKeyEnumerated(jakarta.persistence.MapKeyEnumerated) Enumerated(jakarta.persistence.Enumerated) Target(org.hibernate.annotations.Target) BasicJavaType(org.hibernate.type.descriptor.java.BasicJavaType) Temporal(jakarta.persistence.Temporal) MapKeyTemporal(jakarta.persistence.MapKeyTemporal)

Example 3 with Temporal

use of jakarta.persistence.Temporal in project hibernate-orm by hibernate.

the class BasicValueBinder method prepareCollectionElement.

private void prepareCollectionElement(XProperty attributeXProperty, XClass elementTypeXClass) {
    XClass xclass = elementTypeXClass == null && attributeXProperty.isArray() ? attributeXProperty.getElementClass() : elementTypeXClass;
    Class<?> javaType = resolveJavaType(xclass);
    implicitJavaTypeAccess = typeConfiguration -> javaType;
    final Temporal temporalAnn = attributeXProperty.getAnnotation(Temporal.class);
    if (temporalAnn != null) {
        temporalPrecision = temporalAnn.value();
        if (temporalPrecision == null) {
            throw new IllegalStateException("No jakarta.persistence.TemporalType defined for @jakarta.persistence.Temporal " + "associated with attribute " + attributeXProperty.getDeclaringClass().getName() + '.' + attributeXProperty.getName());
        }
    } else {
        temporalPrecision = null;
    }
    if (javaType.isEnum()) {
        final Enumerated enumeratedAnn = attributeXProperty.getAnnotation(Enumerated.class);
        if (enumeratedAnn != null) {
            enumType = enumeratedAnn.value();
            if (enumType == null) {
                throw new IllegalStateException("jakarta.persistence.EnumType was null on @jakarta.persistence.Enumerated " + " associated with attribute " + attributeXProperty.getDeclaringClass().getName() + '.' + attributeXProperty.getName());
            }
        }
    } else {
        enumType = null;
    }
    final TimeZoneStorage timeZoneStorageAnn = attributeXProperty.getAnnotation(TimeZoneStorage.class);
    timeZoneStorageType = timeZoneStorageAnn != null ? timeZoneStorageAnn.value() : null;
    normalSupplementalDetails(attributeXProperty);
    // 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, BasicJavaType> original = explicitJavaTypeAccess;
        explicitJavaTypeAccess = (typeConfiguration) -> {
            final BasicJavaType<?> originalResult = original.apply(typeConfiguration);
            if (originalResult != null) {
                return originalResult;
            }
            return (BasicJavaType<?>) typeConfiguration.getJavaTypeRegistry().getDescriptor(elementCollectionAnn.targetClass());
        };
    }
}
Also used : MapKeyEnumerated(jakarta.persistence.MapKeyEnumerated) Enumerated(jakarta.persistence.Enumerated) BasicJavaType(org.hibernate.type.descriptor.java.BasicJavaType) Temporal(jakarta.persistence.Temporal) MapKeyTemporal(jakarta.persistence.MapKeyTemporal) ElementCollection(jakarta.persistence.ElementCollection) TypeConfiguration(org.hibernate.type.spi.TypeConfiguration) XClass(org.hibernate.annotations.common.reflection.XClass) TimeZoneStorage(org.hibernate.annotations.TimeZoneStorage)

Aggregations

Enumerated (jakarta.persistence.Enumerated)3 MapKeyEnumerated (jakarta.persistence.MapKeyEnumerated)3 MapKeyTemporal (jakarta.persistence.MapKeyTemporal)3 Temporal (jakarta.persistence.Temporal)3 BasicJavaType (org.hibernate.type.descriptor.java.BasicJavaType)2 ElementCollection (jakarta.persistence.ElementCollection)1 AnnotationException (org.hibernate.AnnotationException)1 Target (org.hibernate.annotations.Target)1 TimeZoneStorage (org.hibernate.annotations.TimeZoneStorage)1 XClass (org.hibernate.annotations.common.reflection.XClass)1 TypeConfiguration (org.hibernate.type.spi.TypeConfiguration)1