private AnnotationInstance overrideSchemaCatalogByDefault(
     AnnotationInstance annotationInstance, EntityMappingsMocker.Default defaults) {
   List<AnnotationValue> newAnnotationValueList = new ArrayList<AnnotationValue>();
   newAnnotationValueList.addAll(annotationInstance.values());
   boolean schemaDefined = false;
   boolean catalogDefined = false;
   if (annotationInstance.value("schema") != null) {
     schemaDefined = true;
   }
   if (annotationInstance.value("catalog") != null) {
     catalogDefined = true;
   }
   if (schemaDefined && catalogDefined) {
     return annotationInstance;
   }
   if (!catalogDefined && StringHelper.isNotEmpty(defaults.getCatalog())) {
     newAnnotationValueList.add(
         AnnotationValue.createStringValue("catalog", defaults.getCatalog()));
   }
   if (!schemaDefined && StringHelper.isNotEmpty(defaults.getSchema())) {
     newAnnotationValueList.add(AnnotationValue.createStringValue("schema", defaults.getSchema()));
   }
   return MockHelper.create(
       annotationInstance.name(),
       annotationInstance.target(),
       MockHelper.toArray(newAnnotationValueList));
 }
  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);
  }
 private void mockTableIfNonExist(
     Map<DotName, List<AnnotationInstance>> annotationsMap, DotName annName) {
   if (annName == JPADotNames.TABLE
       && !annotationsMap.containsKey(JPADotNames.TABLE)
       && annotationsMap.containsKey(JPADotNames.ENTITY)) {
     // if an entity doesn't have a @Table, we create one here
     AnnotationInstance entity =
         JandexHelper.getSingleAnnotation(annotationsMap, JPADotNames.ENTITY);
     AnnotationInstance table =
         MockHelper.create(
             JPADotNames.TABLE, entity.target(), MockHelper.EMPTY_ANNOTATION_VALUE_ARRAY);
     List<AnnotationInstance> annotationInstanceList = new ArrayList<AnnotationInstance>(1);
     annotationInstanceList.add(table);
     annotationsMap.put(JPADotNames.TABLE, annotationInstanceList);
   }
 }
 // @Table, @CollectionTable, @JoinTable, @SecondaryTable
 private void overrideSchemaCatalogByDefault(
     DotName annName,
     Map<DotName, List<AnnotationInstance>> indexedAnnotationMap,
     EntityMappingsMocker.Default defaults) {
   List<AnnotationInstance> annotationInstanceList = indexedAnnotationMap.get(annName);
   if (annotationInstanceList == null || annotationInstanceList.isEmpty()) {
     return;
   }
   List<AnnotationInstance> newAnnotationInstanceList =
       new ArrayList<AnnotationInstance>(annotationInstanceList.size());
   for (AnnotationInstance annotationInstance : annotationInstanceList) {
     if (annName.equals(IndexedAnnotationFilter.SECONDARY_TABLES)) {
       AnnotationInstance[] secondaryTableAnnotationInstanceArray =
           annotationInstance.value().asNestedArray();
       AnnotationValue[] newAnnotationValueArray =
           new AnnotationValue[secondaryTableAnnotationInstanceArray.length];
       for (int i = 0; i < secondaryTableAnnotationInstanceArray.length; i++) {
         newAnnotationValueArray[i] =
             MockHelper.nestedAnnotationValue(
                 "",
                 overrideSchemaCatalogByDefault(
                     secondaryTableAnnotationInstanceArray[i], defaults));
       }
       AnnotationInstance secondaryTablesAnnotationInstance =
           MockHelper.create(
               annName,
               annotationInstance.target(),
               new AnnotationValue[] {
                 AnnotationValue.createArrayValue("value", newAnnotationValueArray)
               });
       newAnnotationInstanceList.add(secondaryTablesAnnotationInstance);
     } else {
       newAnnotationInstanceList.add(overrideSchemaCatalogByDefault(annotationInstance, defaults));
     }
   }
   indexedAnnotationMap.put(annName, newAnnotationInstanceList);
 }