Skip to content

Commit

Permalink
#3470: adds possibility to pass query manager to AnalysisService to a…
Browse files Browse the repository at this point in the history
…void "Object with id 'x' is managed by a different persistence manager" error types

Signed-off-by: Sebastien Delcoigne <[email protected]>
  • Loading branch information
sebD committed Apr 7, 2024
1 parent fcf7c6c commit 067338c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void applyVex(final QueryManager qm, final Bom bom, final Project project
continue;
}

try (AnalysisService analysisService = new AnalysisService()) {
try (AnalysisService analysisService = new AnalysisService(qm)) {
for (org.cyclonedx.model.vulnerability.Vulnerability.Affect affect : vexVuln.getAffects()) {
final ObjectLocator ol = new ObjectLocator(bom, affect.getRef()).locate();
if ((ol.found() && ol.isMetadataComponent()) || (!ol.found() && BomLink.isBomLink(affect.getRef()))) {
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/org/dependencytrack/services/AnalysisService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,20 @@
public class AnalysisService implements AutoCloseable {

private final QueryManager qm;
private final boolean hasBorrowedQueryManager;

public AnalysisService() {
hasBorrowedQueryManager = false;
this.qm = new QueryManager();
}

public AnalysisService(QueryManager queryManager) {
hasBorrowedQueryManager = true;
this.qm = queryManager;
}



/**
* Retrieves an analysis from the database
*
Expand Down Expand Up @@ -159,11 +168,13 @@ public Analysis updateAnalysis(AnalysisDescription analysisDescription, Componen
analysisStateChange = true; // this is a new analysis - so set to true because it was previously null
makeFirstStateComment(qm, analysis, commenter);
makeFirstJustificationComment(qm, analysis, commenter);
for (int i=0; i<analysisDescription.getAnalysisResponses().size(); i++) {
if (i == 0) {
makeFirstAnalysisResponseComment(qm, analysis, analysisDescription.getAnalysisResponses().get(i), commenter);
} else {
makeAnalysisResponseComment(qm, analysis, analysisDescription.getAnalysisResponses().get(i), commenter);
if (analysisDescription.getAnalysisResponses() != null) {
for (int i = 0; i < analysisDescription.getAnalysisResponses().size(); i++) {
if (i == 0) {
makeFirstAnalysisResponseComment(qm, analysis, analysisDescription.getAnalysisResponses().get(i), commenter);
} else {
makeAnalysisResponseComment(qm, analysis, analysisDescription.getAnalysisResponses().get(i), commenter);
}
}
}
makeFirstDetailsComment(qm, analysis, commenter);
Expand Down Expand Up @@ -267,6 +278,8 @@ private boolean makeAnalysisSuppressionComment(final QueryManager qm, final Anal

@Override
public void close() {
this.qm.close();
if (!hasBorrowedQueryManager) {
this.qm.close();
}
}
}

0 comments on commit 067338c

Please sign in to comment.