Skip to content

Commit

Permalink
Merge pull request #114 from kbss-cvut/fix/108-delete-context-when-sy…
Browse files Browse the repository at this point in the history
…stem-or-fault-tree-is-deleted

#108 Delete context when fault tree or system is deleted context
  • Loading branch information
kostobog authored Jun 9, 2024
2 parents 2e98d20 + 7e50061 commit 8914b16
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/BaseDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public URI getContext(T entity){
return entity.getContext();
}

public void deleteContext(URI context){
Objects.requireNonNull(context);
em.createNativeQuery("DELETE {GRAPH ?context { ?s ?p ?o}} WHERE {GRAPH ?context { ?s ?p ?o}}")
.setParameter("context", context)
.executeUpdate();
}

public URI getContext(URI uri){
List<URI> contexts = em.createNativeQuery("SELECT DISTINCT ?context {GRAPH ?context {?uri a ?type}}", URI.class)
.setParameter("uri", uri)
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/cz/cvut/kbss/analysis/dao/GenericDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,17 @@ public interface GenericDao<T extends HasIdentifier> {
* @return {@literal true} if entity exists, {@literal false} otherwise
*/
boolean existsWithPredicate(String predicate, String value);

/**
* Find the context of the entityUri
* @param entityUri
* @return
*/
URI getContext(URI entityUri);

/**
* Deletes all triples in provided context
* @param context
*/
void deleteContext(URI context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.Validator;

import java.net.URI;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -46,6 +47,13 @@ protected void prePersist(@NonNull T instance) {
}


@Transactional
@Override
public void remove(@NonNull URI instanceUri) {
URI context = getPrimaryDao().getContext(instanceUri);
getPrimaryDao().deleteContext(context);
}

@Transactional(readOnly = true)
public List<T> findAllSummaries(){
return ((ManagedEntityDao<T>)getPrimaryDao()).findAllSummaries().stream().map(this::postLoad).toList();
Expand Down

0 comments on commit 8914b16

Please sign in to comment.