private void addCascadePersistIfNotExist(
      DotName annName, Map<DotName, List<AnnotationInstance>> indexedAnnotationMap) {
    List<AnnotationInstance> annotationInstanceList = indexedAnnotationMap.get(annName);
    if (annotationInstanceList == null || annotationInstanceList.isEmpty()) {
      return;
    }
    List<AnnotationInstance> newAnnotationInstanceList =
        new ArrayList<AnnotationInstance>(annotationInstanceList.size());
    for (AnnotationInstance annotationInstance : annotationInstanceList) {
      AnnotationValue cascadeValue = annotationInstance.value("cascade");
      List<AnnotationValue> newAnnotationValueList = new ArrayList<AnnotationValue>();
      newAnnotationValueList.addAll(annotationInstance.values());
      if (cascadeValue == null) {
        AnnotationValue temp =
            AnnotationValue.createEnumValue("", JPADotNames.CASCADE_TYPE, "PERSIST");
        cascadeValue = AnnotationValue.createArrayValue("cascade", new AnnotationValue[] {temp});
      } else {
        newAnnotationValueList.remove(cascadeValue);
        String[] cascadeTypes = cascadeValue.asEnumArray();
        boolean hasPersistDefined = false;
        for (String type : cascadeTypes) {
          if ("PERSIST".equals(type)) {
            hasPersistDefined = true;
            continue;
          }
        }
        if (hasPersistDefined) {
          newAnnotationInstanceList.add(annotationInstance);
          continue;
        }
        String[] newCascadeTypes = new String[cascadeTypes.length + 1];
        newCascadeTypes[0] = "PERSIST";
        System.arraycopy(cascadeTypes, 0, newCascadeTypes, 1, cascadeTypes.length);
        AnnotationValue[] cascades = new AnnotationValue[newCascadeTypes.length];
        for (int i = 0; i < newCascadeTypes.length; i++) {
          cascades[i] =
              AnnotationValue.createEnumValue("", JPADotNames.CASCADE_TYPE, newCascadeTypes[i]);
        }
        cascadeValue = AnnotationValue.createArrayValue("cascade", cascades);
      }
      newAnnotationValueList.add(cascadeValue);

      AnnotationInstance newAnnotationInstance =
          MockHelper.create(
              annotationInstance.name(),
              annotationInstance.target(),
              MockHelper.toArray(newAnnotationValueList));
      newAnnotationInstanceList.add(newAnnotationInstance);
    }
    indexedAnnotationMap.put(annName, newAnnotationInstanceList);
  }
예제 #2
0
파일: MockHelper.java 프로젝트: enenuki/phd
/* 148:    */   
/* 149:    */   private static AnnotationValue enumValue(String name, DotName typeName, Enum value)
/* 150:    */   {
/* 151:182 */     if ((value != null) && (StringHelper.isNotEmpty(value.toString()))) {
/* 152:183 */       return AnnotationValue.createEnumValue(name, typeName, value.toString());
/* 153:    */     }
/* 154:185 */     return null;
/* 155:    */   }
예제 #3
0
 private static AnnotationValue enumValue(String name, DotName typeName, Enum value) {
   if (value != null && StringHelper.isNotEmpty(value.toString())) {
     return AnnotationValue.createEnumValue(name, typeName, value.toString());
   }
   return null;
 }