@Override public void writeRelation(final EdmEntitySet sourceEntitySet, final Object sourceEntity, final EdmEntitySet targetEntitySet, final Map<String, Object> targetEntityValues) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { // get common data DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName()); DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName()); AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo( sourceStore.getDataTypeClass(), targetStore.getDataTypeClass()); // get and validate source fields Field sourceField = commonNavInfo.getFromField(); if (sourceField == null) { throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore + "', targetStore='" + targetStore + "')."); } // get related target entity Object targetEntity = targetStore.createInstance(); ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues); targetEntity = targetStore.read(targetEntity); // set at source setValueAtNavigationField(sourceEntity, sourceField, targetEntity); // set at target Field targetField = commonNavInfo.getToField(); if (targetField != null) { setValueAtNavigationField(targetEntity, targetField, sourceEntity); } }
@Override public void writeRelation(final EdmEntitySet sourceEntitySet, final Object sourceEntity, final EdmEntitySet targetEntitySet, final Map<String, Object> targetEntityValues) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { // get common data DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName()); DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName()); AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo( sourceStore.getDataTypeClass(), targetStore.getDataTypeClass()); // get and validate source fields Field sourceField = commonNavInfo.getFromField(); if (sourceField == null) { throw new AnnotationRuntimeException("Missing source field for related data (sourceStore='" + sourceStore + "', targetStore='" + targetStore + "')."); } // get related target entity Object targetEntity = targetStore.createInstance(); ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues); targetEntity = targetStore.read(targetEntity); // set at source setValueAtNavigationField(sourceEntity, sourceField, targetEntity); // set at target Field targetField = commonNavInfo.getToField(); if (targetField != null) { setValueAtNavigationField(targetEntity, targetField, sourceEntity); } }
@Override public void writeRelation(final EdmEntitySet sourceEntitySet, final Object sourceEntity, final EdmEntitySet targetEntitySet, final Map<String, Object> targetEntityValues) throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException { // get common data DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName()); DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName()); AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo( sourceStore.getDataTypeClass(), targetStore.getDataTypeClass()); // get and validate source fields Field sourceField = commonNavInfo.getFromField(); if (sourceField == null) { throw new AnnotationRuntimeException("Missing source field for related data (sourceStore='" + sourceStore + "', targetStore='" + targetStore + "')."); } // get related target entity Object targetEntity = targetStore.createInstance(); ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues); targetEntity = targetStore.read(targetEntity); // set at source setValueAtNavigationField(sourceEntity, sourceField, targetEntity); // set at target Field targetField = commonNavInfo.getToField(); if (targetField != null) { setValueAtNavigationField(targetEntity, targetField, sourceEntity); } }