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;
}
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;
}
}
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));
}
}
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;
}
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;
}
Aggregations