Skip to content

Commit

Permalink
Merge pull request #3713 from nscuro/remove-trx-rollback-workaround
Browse files Browse the repository at this point in the history
Remove workarounds for #2677
  • Loading branch information
nscuro authored May 15, 2024
2 parents faade57 + d572c52 commit db1232c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 23 deletions.
18 changes: 0 additions & 18 deletions src/main/java/org/dependencytrack/persistence/QueryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
import javax.jdo.FetchPlan;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.Transaction;
import javax.json.JsonObject;
import java.security.Principal;
import java.util.ArrayList;
Expand Down Expand Up @@ -1416,23 +1415,6 @@ public <T> Query<T> getObjectsByUuidsQuery(final Class<T> clazz, final List<UUID
return query;
}

/**
* Convenience method to ensure that any active transaction is rolled back.
* <p>
* Calling this method may sometimes be necessary due to {@link AlpineQueryManager#persist(Object)}
* no performing a rollback in case committing the transaction fails. This can impact other persistence
* operations performed in the same session (e.g. {@code NucleusTransactionException: Invalid state. Transaction has already started}).
*
* @see <a href="https://github.com/DependencyTrack/dependency-track/issues/2677">Issue 2677</a>
* @since 4.8.0
*/
public void ensureNoActiveTransaction() {
final Transaction trx = pm.currentTransaction();
if (trx != null && trx.isActive()) {
trx.rollback();
}
}

public void recursivelyDeleteTeam(Team team) {
runInTransaction(() -> {
pm.deletePersistentAll(team.getApiKeys());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public void inform(final Event e) {
// Refreshing the object by querying for it again is preventative
LOGGER.info("Performing component repository metadata analysis against " + components.size() + " components");
for (final Component component : components) {
qm.ensureNoActiveTransaction(); // Workaround for https://github.com/DependencyTrack/dependency-track/issues/2677
analyze(qm, qm.getObjectById(Component.class, component.getId()));
}
LOGGER.info("Completed component repository metadata analysis against " + components.size() + " components");
Expand All @@ -102,7 +101,6 @@ public void inform(final Event e) {
final List<Component> components = qm.getAllComponents(project);
LOGGER.debug("Performing component repository metadata analysis against " + components.size() + " components in project: " + project.getUuid());
for (final Component component : components) {
qm.ensureNoActiveTransaction(); // Workaround for https://github.com/DependencyTrack/dependency-track/issues/2677
analyze(qm, component);
}
LOGGER.debug("Completed component repository metadata analysis against " + components.size() + " components in project: " + project.getUuid());
Expand Down Expand Up @@ -188,7 +186,6 @@ private void analyze(final QueryManager qm, final Component component, final IMe
component multiple times concurrently, and is safe to ignore. \
[targetHost=%s, source=%s, target=%s]\
""".formatted(repository.getUrl(), repository.getType(), PurlUtil.silentPurlCoordinatesOnly(component.getPurl())), e);
qm.ensureNoActiveTransaction(); // Workaround for https://github.com/DependencyTrack/dependency-track/issues/2677
return;
} else {
throw e;
Expand All @@ -215,7 +212,6 @@ private void analyze(final QueryManager qm, final Component component, final IMe
component multiple times concurrently, and is safe to ignore. \
[targetHost=%s, source=%s, target=%s]\
""".formatted(repository.getUrl(), repository.getType(), PurlUtil.silentPurlCoordinatesOnly(component.getPurl())), e);
qm.ensureNoActiveTransaction(); // Workaround for https://github.com/DependencyTrack/dependency-track/issues/2677
return;
} else {
throw e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ protected synchronized void updateAnalysisCacheStats(QueryManager qm, Vulnerabil
component identity multiple times concurrently, and is safe to ignore. \
[targetHost=%s, source=%s, target=%s]\
""".formatted(targetHost, source, target), e);
qm.ensureNoActiveTransaction(); // Workaround for https://github.com/DependencyTrack/dependency-track/issues/2677
} else {
throw e;
}
Expand Down

0 comments on commit db1232c

Please sign in to comment.