Ejemplo n.º 1
0
 /**
  * Get {@link javax.persistence.AccessType } from {@link javax.persistence.Access @Access} on the
  * attribute of the given class
  */
 static XMLAccessType getAccessFromAttributeAnnotation(
     DotName className, String attributeName, IndexBuilder indexBuilder) {
   Map<DotName, List<AnnotationInstance>> indexedAnnotations =
       indexBuilder.getIndexedAnnotations(className);
   if (indexedAnnotations != null && indexedAnnotations.containsKey(ACCESS)) {
     List<AnnotationInstance> annotationInstances = indexedAnnotations.get(ACCESS);
     if (MockHelper.isNotEmpty(annotationInstances)) {
       for (AnnotationInstance annotationInstance : annotationInstances) {
         AnnotationTarget indexedPropertyTarget = annotationInstance.target();
         if (indexedPropertyTarget == null) {
           continue;
         }
         if (JandexHelper.getPropertyName(indexedPropertyTarget).equals(attributeName)) {
           XMLAccessType accessType =
               JandexHelper.getValueAsEnum(annotationInstance, "value", XMLAccessType.class);
           /** here we ignore @Access(FIELD) on property (getter) and @Access(PROPERTY) on field */
           XMLAccessType targetAccessType = annotationTargetToAccessType(indexedPropertyTarget);
           if (accessType.equals(targetAccessType)) {
             return targetAccessType;
           } else {
             LOG.warn(
                 String.format(
                     "%s.%s has @Access on %s, but it tries to assign the access type to %s, this is not allowed by JPA spec, and will be ignored.",
                     className, attributeName, targetAccessType, accessType));
           }
         }
       }
     }
   }
   return null;
 }
Ejemplo n.º 2
0
 void collectGlobalConfigurationFromIndex(GlobalAnnotations globalAnnotations) {
   for (DotName annName : DefaultConfigurationHelper.GLOBAL_ANNOTATIONS) {
     List<AnnotationInstance> annotationInstanceList = index.getAnnotations(annName);
     if (MockHelper.isNotEmpty(annotationInstanceList)) {
       globalAnnotations.addIndexedAnnotationInstance(annotationInstanceList);
     }
   }
   globalAnnotations.filterIndexedAnnotations();
 }
Ejemplo n.º 3
0
 private static XMLAccessType getAccessFromIdPosition(
     Map<DotName, List<AnnotationInstance>> annotations) {
   if (annotations == null || annotations.isEmpty() || !(annotations.containsKey(ID))) {
     return null;
   }
   List<AnnotationInstance> idAnnotationInstances = annotations.get(ID);
   if (MockHelper.isNotEmpty(idAnnotationInstances)) {
     return processIdAnnotations(idAnnotationInstances);
   }
   return null;
 }
Ejemplo n.º 4
0
 private static XMLAccessType getAccess(Map<DotName, List<AnnotationInstance>> annotations) {
   if (annotations == null || annotations.isEmpty() || !isEntityObject(annotations)) {
     return null;
   }
   List<AnnotationInstance> accessAnnotationInstances = annotations.get(JPADotNames.ACCESS);
   if (MockHelper.isNotEmpty(accessAnnotationInstances)) {
     for (AnnotationInstance annotationInstance : accessAnnotationInstances) {
       if (annotationInstance.target() != null
           && annotationInstance.target() instanceof ClassInfo) {
         return JandexHelper.getValueAsEnum(annotationInstance, "value", XMLAccessType.class);
       }
     }
   }
   return null;
 }