}
@Override
public void updateLink(OEntityId sourceEntity, String targetNavProp, OEntityKey oldTargetEntityKey, OEntityId newTargetEntity) {
Entity entity = findEntity(sourceEntity.getEntitySetName(), sourceEntity.getEntityKey());
EdmEntitySet ees = metadata.getEdmEntitySet(sourceEntity.getEntitySetName());
String targetEntityKind = ees.getType().findNavigationProperty(targetNavProp).getToRole().getRole();
Entity newEntity = null;
if (newTargetEntity != null) {
newEntity = findEntity(newTargetEntity.getEntitySetName(), newTargetEntity.getEntityKey());
if (!newEntity.getKind().equals(targetEntityKind)) {
throw new NotImplementedException("EdmNavigationProperty " + targetNavProp + " is not of expected kind. Expecting " + targetEntityKind + ", got " + newEntity.getKind() + ".");
}
}
EdmMultiplicity multiplicity = ees.getType().findNavigationProperty(targetNavProp).getToRole().getMultiplicity();
if (multiplicity == EdmMultiplicity.ZERO_TO_ONE) {
entity.setProperty(targetNavProp, newEntity != null ? newEntity.getKey() : null);
} else {
@SuppressWarnings("unchecked")
Collection<Key> keys = (Collection<Key>) entity.getProperty(targetNavProp);