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