/** * Add relation link from a given parent resource to a child resource. * * @param fieldName which relation link * @param newRelation the new relation */ public void addRelation(String fieldName, PersistentResource newRelation) { checkSharePermission(Collections.singleton(newRelation)); Object relation = this.getValueUnchecked(fieldName); if (relation instanceof Collection) { if (addToCollection((Collection) relation, fieldName, newRelation)) { this.markDirty(); } //Hook for updateToManyRelation transaction.updateToManyRelation(transaction, obj, fieldName, Sets.newHashSet(newRelation.getObject()), new LinkedHashSet<>(), requestScope); addInverseRelation(fieldName, newRelation.getObject()); } else { // Not a collection, but may be trying to create a ToOne relationship. // NOTE: updateRelation marks dirty. updateRelation(fieldName, Collections.singleton(newRelation)); } }
.forEach(toAdd -> { addToCollection(collection, fieldName, toAdd); addInverseRelation(fieldName, toAdd.getObject()); newRelationships.add(toAdd.getObject()); });
.forEach(toAdd -> { addToCollection(collection, fieldName, toAdd); addInverseRelation(fieldName, toAdd.getObject()); newRelationships.add(toAdd.getObject()); });
/** * Add relation link from a given parent resource to a child resource. * * @param fieldName which relation link * @param newRelation the new relation */ public void addRelation(String fieldName, PersistentResource newRelation) { checkSharePermission(Collections.singleton(newRelation)); Object relation = this.getValueUnchecked(fieldName); if (relation instanceof Collection) { if (addToCollection((Collection) relation, fieldName, newRelation)) { this.markDirty(); } //Hook for updateToManyRelation transaction.updateToManyRelation(transaction, obj, fieldName, Sets.newHashSet(newRelation.getObject()), new LinkedHashSet<>(), requestScope); addInverseRelation(fieldName, newRelation.getObject()); } else { // Not a collection, but may be trying to create a ToOne relationship. // NOTE: updateRelation marks dirty. updateRelation(fieldName, Collections.singleton(newRelation)); } }
addInverseRelation(fieldName, newValue); newResource.markDirty();
addInverseRelation(fieldName, newValue); newResource.markDirty();