- final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
- final AnchorEntity anchorEntity =
- anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
- return toAnchor(anchorEntity);
+ return toAnchor(getAnchorEntity(dataspaceName, anchorName));
+ }
+
+ @Transactional
+ @Override
+ public void deleteAnchor(final String dataspaceName, final String anchorName) {
+ final var anchorEntity = getAnchorEntity(dataspaceName, anchorName);
+ fragmentRepository.deleteByAnchorIn(Set.of(anchorEntity));
+ anchorRepository.delete(anchorEntity);
+ }
+
+ private AnchorEntity getAnchorEntity(final String dataspaceName, final String anchorName) {
+ final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ return anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);