private void setType(CascadeType type) { if (type.equals(CascadeType.ALL)){ save = true; delete = true; } if (type.equals(CascadeType.REMOVE)){ delete = true; } if (type.equals(CascadeType.PERSIST)){ save = true; } if (type.equals(CascadeType.MERGE)){ save = true; } if (save || delete){ validate = true; } }
private void setType(CascadeType type) { if (type.equals(CascadeType.ALL)){ save = true; delete = true; } if (type.equals(CascadeType.REMOVE)){ delete = true; } if (type.equals(CascadeType.PERSIST)){ save = true; } if (type.equals(CascadeType.MERGE)){ save = true; } if (save || delete){ validate = true; } }
public static boolean collectionOneToManyWithCascade(Object entity, Field field, CascadeType cascadeAcao) { if (!isCollectionOneToMany(entity, field)) { return false; } OneToMany oneToMany = field.getAnnotation(OneToMany.class); boolean cascade = false; for (CascadeType cascadeType : oneToMany.cascade()) { if (cascadeType.equals(CascadeType.ALL) || cascadeType.equals(cascadeAcao)) { cascade = true; break; } } return cascade; }
public static boolean collectionOneToManyWithCascade(Object entity, Field field, CascadeType cascadeAcao) { if (!isCollectionOneToMany(entity, field)) { return false; } OneToMany oneToMany = field.getAnnotation(OneToMany.class); boolean cascade = false; for (CascadeType cascadeType : oneToMany.cascade()) { if (cascadeType.equals(CascadeType.ALL) || cascadeType.equals(cascadeAcao)) { cascade = true; break; } } return cascade; }
public static boolean isOneToOneAndCascadeRemove(Object entityMaster, EntityType<?> entiyType) { for (Field field : entityMaster.getClass().getDeclaredFields()) { if (!ReflectionUtils.getGenericClass(field).equals(entiyType.getJavaType())) { continue; } OneToOne oneToOne = field.getAnnotation(OneToOne.class); if (oneToOne == null) { continue; } return Arrays .stream(oneToOne.cascade()) .anyMatch(c -> CascadeType.ALL.equals(c) || CascadeType.REMOVE.equals(c)); } return false; }
public static boolean isOneToOneAndCascadeRemove(Object entityMaster, EntityType<?> entiyType) { for (Field field : entityMaster.getClass().getDeclaredFields()) { if (!ReflectionUtils.getGenericClass(field).equals(entiyType.getJavaType())) { continue; } OneToOne oneToOne = field.getAnnotation(OneToOne.class); if (oneToOne == null) { continue; } return Arrays .stream(oneToOne.cascade()) .anyMatch(c -> CascadeType.ALL.equals(c) || CascadeType.REMOVE.equals(c)); } return false; }
public static boolean isOneToManyAndCascadeRemove(Object entityMaster, EntityType<?> entiyType) { for (Field field : entityMaster.getClass().getDeclaredFields()) { if (!Collection.class.isAssignableFrom(field.getType())) { continue; } if (!ReflectionUtils.getGenericClass(field).equals(entiyType.getJavaType())) { continue; } OneToMany oneToMany = field.getAnnotation(OneToMany.class); if (oneToMany == null) { continue; } return Arrays .stream(oneToMany.cascade()) .anyMatch(c -> CascadeType.ALL.equals(c) || CascadeType.REMOVE.equals(c)); } return false; }
public static boolean isOneToManyAndCascadeRemove(Object entityMaster, EntityType<?> entiyType) { for (Field field : entityMaster.getClass().getDeclaredFields()) { if (!Collection.class.isAssignableFrom(field.getType())) { continue; } if (!ReflectionUtils.getGenericClass(field).equals(entiyType.getJavaType())) { continue; } OneToMany oneToMany = field.getAnnotation(OneToMany.class); if (oneToMany == null) { continue; } return Arrays .stream(oneToMany.cascade()) .anyMatch(c -> CascadeType.ALL.equals(c) || CascadeType.REMOVE.equals(c)); } return false; }
private Type getRelationType(final Entity businessObject, final String methodName) throws SBusinessDataRepositoryException { final String fieldName = ClassReflector.getFieldName(methodName); Annotation[] annotations; try { annotations = businessObject.getClass().getDeclaredField(fieldName).getAnnotations(); } catch (final NoSuchFieldException e) { return null; } catch (final SecurityException e) { throw new SBusinessDataRepositoryException(e); } for (final Annotation annotation : annotations) { final Set<Class<? extends Annotation>> annotationKeySet = getAnnotationKeySet(); if (annotationKeySet.contains(annotation.annotationType())) { try { final Method cascade = annotation.getClass().getMethod("cascade"); final CascadeType[] cascadeTypes = (CascadeType[]) cascade.invoke(annotation); if (CascadeType.MERGE.equals(cascadeTypes[0])) { return Type.AGGREGATION; } if (CascadeType.ALL.equals(cascadeTypes[0])) { return Type.COMPOSITION; } } catch (final Exception e) { throw new SBusinessDataRepositoryException(e); } } } return null; }
private Type getRelationType(final Entity businessObject, final String methodName) throws SBusinessDataRepositoryException { final String fieldName = ClassReflector.getFieldName(methodName); Annotation[] annotations; try { annotations = businessObject.getClass().getDeclaredField(fieldName).getAnnotations(); } catch (final NoSuchFieldException e) { return null; } catch (final SecurityException e) { throw new SBusinessDataRepositoryException(e); } for (final Annotation annotation : annotations) { final Set<Class<? extends Annotation>> annotationKeySet = getAnnotationKeySet(); if (annotationKeySet.contains(annotation.annotationType())) { try { final Method cascade = annotation.getClass().getMethod("cascade"); final CascadeType[] cascadeTypes = (CascadeType[]) cascade.invoke(annotation); if (CascadeType.MERGE.equals(cascadeTypes[0])) { return Type.AGGREGATION; } if (CascadeType.ALL.equals(cascadeTypes[0])) { return Type.COMPOSITION; } } catch (final Exception e) { throw new SBusinessDataRepositoryException(e); } } } return null; }