@Override public void check(AnnotationInstance annotationInstance) { AnnotationValue cascadeValue = annotationInstance.value("cascade"); assertNotNull( "Cascade is null in @OneToMany, but should be added a Cascade persist", cascadeValue); String[] enumArray = cascadeValue.asEnumArray(); assertEquals(expected.length, enumArray.length); assertArrayEquals(expected, enumArray); }
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); }