Search in sources :

Example 1 with AccessType

use of javax.persistence.AccessType in project hibernate-orm by hibernate.

the class PropertyAccessMixedImpl method getAccessType.

protected static AccessType getAccessType(Class<?> containerJavaType, String propertyName) {
    Field field = fieldOrNull(containerJavaType, propertyName);
    AccessType fieldAccessType = getAccessTypeOrNull(field);
    if (fieldAccessType != null) {
        return fieldAccessType;
    }
    AccessType methodAccessType = getAccessTypeOrNull(getterMethodOrNull(containerJavaType, propertyName));
    if (methodAccessType != null) {
        return methodAccessType;
    }
    // No @Access on property or field; check to see if containerJavaType has an explicit @Access
    AccessType classAccessType = getAccessTypeOrNull(containerJavaType);
    if (classAccessType != null) {
        return classAccessType;
    }
    return field != null ? AccessType.FIELD : AccessType.PROPERTY;
}
Also used : Field(java.lang.reflect.Field) AccessType(javax.persistence.AccessType)

Example 2 with AccessType

use of javax.persistence.AccessType in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getAccessType.

private Access getAccessType(Element tree, XMLContext.Default defaults) {
    String access = tree == null ? null : tree.attributeValue("access");
    if (access != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Access.class);
        AccessType type;
        try {
            type = AccessType.valueOf(access);
        } catch (IllegalArgumentException e) {
            throw new AnnotationException(access + " is not a valid access type. Check you xml confguration.");
        }
        ad.setValue("value", type);
        return AnnotationFactory.create(ad);
    } else if (defaults.canUseJavaAnnotations() && isPhysicalAnnotationPresent(Access.class)) {
        return getPhysicalAnnotation(Access.class);
    } else if (defaults.getAccess() != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Access.class);
        ad.setValue("value", defaults.getAccess());
        return AnnotationFactory.create(ad);
    } else {
        return null;
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) ClassLoaderAccess(org.hibernate.boot.spi.ClassLoaderAccess) Access(javax.persistence.Access) AnnotationException(org.hibernate.AnnotationException) AccessType(javax.persistence.AccessType)

Example 3 with AccessType

use of javax.persistence.AccessType in project hibernate-orm by hibernate.

the class JPAOverriddenAnnotationReader method getAccessType.

private void getAccessType(List<Annotation> annotationList, Element element) {
    if (element == null) {
        return;
    }
    String access = element.attributeValue("access");
    if (access != null) {
        AnnotationDescriptor ad = new AnnotationDescriptor(Access.class);
        AccessType type;
        try {
            type = AccessType.valueOf(access);
        } catch (IllegalArgumentException e) {
            throw new AnnotationException(access + " is not a valid access type. Check you xml confguration.");
        }
        if ((AccessType.PROPERTY.equals(type) && this.element instanceof Method) || (AccessType.FIELD.equals(type) && this.element instanceof Field)) {
            return;
        }
        ad.setValue("value", type);
        annotationList.add(AnnotationFactory.create(ad));
    }
}
Also used : AnnotationDescriptor(org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor) Field(java.lang.reflect.Field) AnnotationException(org.hibernate.AnnotationException) Method(java.lang.reflect.Method) AccessType(javax.persistence.AccessType)

Example 4 with AccessType

use of javax.persistence.AccessType in project hibernate-orm by hibernate.

the class PersistentAttributesHelper method inferTypeName.

/**
	 * Consistent with hasAnnotation()
	 */
private static String inferTypeName(CtClass ctClass, String attributeName) {
    AccessType classAccessType = getAccessTypeOrNull(ctClass);
    CtField field = findFieldOrNull(ctClass, attributeName);
    CtMethod getter = findGetterOrNull(ctClass, attributeName);
    if (classAccessType == AccessType.FIELD || (field != null && getAccessTypeOrNull(field) == AccessType.FIELD)) {
        return field == null ? null : inferFieldTypeName(field);
    }
    if (classAccessType == AccessType.PROPERTY || (getter != null && getAccessTypeOrNull(getter) == AccessType.PROPERTY)) {
        return getter == null ? null : inferMethodTypeName(getter);
    }
    String found = (getter == null ? null : inferMethodTypeName(getter));
    if (found == null && field != null) {
        return inferFieldTypeName(field);
    }
    return found;
}
Also used : CtField(javassist.CtField) AccessType(javax.persistence.AccessType) CtMethod(javassist.CtMethod)

Example 5 with AccessType

use of javax.persistence.AccessType in project hibernate-orm by hibernate.

the class PersistentAttributesHelper method getAnnotation.

public static <T extends Annotation> T getAnnotation(CtClass ctClass, String attributeName, Class<T> annotation) {
    AccessType classAccessType = getAccessTypeOrNull(ctClass);
    CtField field = findFieldOrNull(ctClass, attributeName);
    CtMethod getter = findGetterOrNull(ctClass, attributeName);
    if (classAccessType == AccessType.FIELD || (field != null && getAccessTypeOrNull(field) == AccessType.FIELD)) {
        return field == null ? null : getAnnotationOrNull(field, annotation);
    }
    if (classAccessType == AccessType.PROPERTY || (getter != null && getAccessTypeOrNull(getter) == AccessType.PROPERTY)) {
        return getter == null ? null : getAnnotationOrNull(getter, annotation);
    }
    T found = (getter == null ? null : getAnnotationOrNull(getter, annotation));
    if (found == null && field != null) {
        return getAnnotationOrNull(field, annotation);
    }
    return found;
}
Also used : CtField(javassist.CtField) AccessType(javax.persistence.AccessType) CtMethod(javassist.CtMethod)

Aggregations

AccessType (javax.persistence.AccessType)5 Field (java.lang.reflect.Field)2 CtField (javassist.CtField)2 CtMethod (javassist.CtMethod)2 AnnotationException (org.hibernate.AnnotationException)2 AnnotationDescriptor (org.hibernate.annotations.common.annotationfactory.AnnotationDescriptor)2 Method (java.lang.reflect.Method)1 Access (javax.persistence.Access)1 ClassLoaderAccess (org.hibernate.boot.spi.ClassLoaderAccess)1