Skip to content

Commit

Permalink
Ensure modifying project endpoints are transactional (#925)
Browse files Browse the repository at this point in the history
  • Loading branch information
nscuro authored Oct 1, 2024
1 parent b0581ff commit 8a40e69
Show file tree
Hide file tree
Showing 3 changed files with 342 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.Transaction;
import javax.jdo.metadata.MemberMetadata;
import javax.jdo.metadata.TypeMetadata;
import java.io.IOException;
Expand Down Expand Up @@ -741,20 +740,14 @@ private static Set<UUID> parseDirectDependenciesUuids(
}

/**
* Deletes a Project and all objects dependant on the project.
* Deletes a Project and all objects dependent on the project.
*
* @param project the Project to delete
* @param commitIndex specifies if the search index should be committed (an expensive operation)
*/
@Override
public void recursivelyDelete(final Project project, final boolean commitIndex) {
final Transaction trx = pm.currentTransaction();
final boolean isJoiningExistingTrx = trx.isActive();
try {
if (!isJoiningExistingTrx) {
trx.begin();
}

runInTransaction(() -> {
for (final Project child : project.getChildren()) {
// Note: This could be refactored such that each project is deleted
// in its own transaction. That would break semantics when it comes
Expand Down Expand Up @@ -791,16 +784,7 @@ public void recursivelyDelete(final Project project, final boolean commitIndex)
} finally {
projectQuery.closeAll();
}

if (!isJoiningExistingTrx) {
trx.commit();
}

} finally {
if (!isJoiningExistingTrx && trx.isActive()) {
trx.rollback();
}
}
});
}

/**
Expand Down
Loading

0 comments on commit 8a40e69

Please sign in to comment.