Arrays.asList(ann.cascade()), Boolean.TRUE, ann.mappedBy(), Relation.ForeignKey.ONE_TO_MANY);
private void readToOne(OneToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName())); } manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
@Override protected CascadeType[] getCascade(Field field) { return field.getAnnotation(OneToMany.class).cascade(); } },
/** * INTERNAL: (Overridden in XMLOneToManyAccessor) */ public List<String> getCascadeTypes() { if (m_oneToMany == null) { return new ArrayList<String>(); } else { return getCascadeTypes(m_oneToMany.cascade()); } }
collectionBinder.setCascadeStrategy( getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false
@Override public CascadeType[] getCascadeTypes() { return getRelationshipAnnotation().cascade(); }
/** * Determine whether an object denoted by the given property is merged into persistence context together with the * owning object. This is true if the property is ManyToMany, or if it is OneToMany with certain CascadeType * defined. */ public boolean isCascade(MetaProperty metaProperty) { Objects.requireNonNull(metaProperty, "metaProperty is null"); OneToMany oneToMany = metaProperty.getAnnotatedElement().getAnnotation(OneToMany.class); if (oneToMany != null) { final Collection<CascadeType> cascadeTypes = Arrays.asList(oneToMany.cascade()); if (cascadeTypes.contains(CascadeType.ALL) || cascadeTypes.contains(CascadeType.MERGE)) { return true; } } ManyToMany manyToMany = metaProperty.getAnnotatedElement().getAnnotation(ManyToMany.class); if (manyToMany != null && StringUtils.isBlank(manyToMany.mappedBy())) { return true; } 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; }
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; }
/** * Retrieves cascade from metamodel attribute * * @return an empty collection if no jpa relation annotation can be found. */ public Collection<CascadeType> getCascades(PluralAttribute<?, ?, ?> attribute) { if (attribute.getJavaMember() instanceof AccessibleObject) { AccessibleObject accessibleObject = (AccessibleObject) attribute.getJavaMember(); OneToMany oneToMany = accessibleObject.getAnnotation(OneToMany.class); if (oneToMany != null) { return newArrayList(oneToMany.cascade()); } ManyToMany manyToMany = accessibleObject.getAnnotation(ManyToMany.class); if (manyToMany != null) { return newArrayList(manyToMany.cascade()); } } return newArrayList(); }
/** * Retrieves cascade from metamodel attribute * * @param attribute given pluaral attribute * @return an empty collection if no jpa relation annotation can be found. */ public Collection<CascadeType> getCascades(PluralAttribute<?, ?, ?> attribute) { if (attribute.getJavaMember() instanceof AccessibleObject) { AccessibleObject accessibleObject = (AccessibleObject) attribute.getJavaMember(); OneToMany oneToMany = accessibleObject.getAnnotation(OneToMany.class); if (oneToMany != null) { return newArrayList(oneToMany.cascade()); } ManyToMany manyToMany = accessibleObject.getAnnotation(ManyToMany.class); if (manyToMany != null) { return newArrayList(manyToMany.cascade()); } } return newArrayList(); }
private void introspectOneToMany(OneToMany oneToMany) { Class targetClass = oneToMany.targetEntity(); if (! void.class.equals(targetClass)) setTargetEntity(targetClass); setCascadeTypes(oneToMany.cascade()); setFetch(oneToMany.fetch()); _mappedBy = oneToMany.mappedBy(); }
private void readToOne(OneToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { String msg = errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()); throw new RuntimeException(msg); } manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(TableJoin.LEFT_OUTER); }
private void readToOne(OneToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { String msg = errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()); throw new RuntimeException(msg); } manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(TableJoin.LEFT_OUTER); }
private void readToOne(OneToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { String msg = errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()); throw new RuntimeException(msg); } manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
private void readToOne(OneToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName())); } manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
/** * Parse @OneToMany. */ private void parseOneToMany(FieldMetaData fmd, OneToMany anno) { switch (fmd.getDeclaredTypeCode()) { case JavaTypes.ARRAY: case JavaTypes.COLLECTION: case JavaTypes.MAP: if (JavaTypes.maybePC(fmd.getElement())) break; // no break default: throw new MetaDataException(_loc.get("bad-meta-anno", fmd, "OneToMany")); } fmd.setInDefaultFetchGroup(anno.fetch() == FetchType.EAGER); if (isMappingOverrideMode() && !StringUtils.isEmpty(anno.mappedBy())) fmd.setMappedBy(anno.mappedBy()); if (anno.targetEntity() != void.class) fmd.getElement().setDeclaredType(anno.targetEntity()); setCascades(fmd.getElement(), anno.cascade()); }
collectionBinder.setCascadeStrategy( getCascadeStrategy( oneToManyAnn.cascade(), hibernateCascade, oneToManyAnn.orphanRemoval(), false