Skip to content

Commit

Permalink
fix: Xplan validation erroneously throws warning on missing objects
Browse files Browse the repository at this point in the history
Closes #890
  • Loading branch information
emanuelaepure10 authored and stempler committed Jul 11, 2024
1 parent c984fb6 commit 23bcc04
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Nullable;

Expand Down Expand Up @@ -136,7 +135,7 @@ public InstanceCollection next() {
List<InstanceReference> instances = getNextAtomicPart();
biggestAtom = Math.max(biggestAtom, instances.size());

if (part.size() + instances.size() > maxObjects) {
if (part.size() > 0 && part.size() + instances.size() > maxObjects) {
// add to part candidates for later use
nextCandidates.add(instances);
if (!verticesLeft()) {
Expand Down Expand Up @@ -199,7 +198,14 @@ public InstanceCollection next() {
*/
private List<InstanceReference> getNextAtomicPart() {
// select an arbitrary vertex
Vertex vtx = graph.someVertex();
Vertex vtx = null;

if (handleFirst != null) {
vtx = graph.getVertex(handleFirst);
}
if (vtx == null) {
vtx = graph.someVertex();
}
if (vtx != null) {
// get all vertices associated with that vertex
final Set<Vertex> visited = new LinkedHashSet<>();
Expand Down Expand Up @@ -236,22 +242,20 @@ public Boolean compute(LoopBundle<Vertex> loop) {
result.add(ref);
}
else {
Iterable<Vertex> referers = associated.getVertices(Direction.IN);
Set<String> ids = new HashSet<>();
if (referers != null) {
for (Vertex referer : referers) {
Object ident = referer.getId();
if (ident != null) {
ids.add(ident.toString());
}
for (Vertex referer : associated.getVertices(Direction.IN)) {
Object ident = referer.getId();
if (ident != null) {
ids.add(ident.toString());
}
}

if (ids.isEmpty()) {
log.warn("Encountered referenced object w/o associated instance: "
+ associated.getId());
}
else {
String enumIds = ids.stream().collect(Collectors.joining(", "));
String enumIds = String.join(", ", ids);
log.warn("Encountered referenced object w/o associated instance: "
+ associated.getId() + " - referenced from " + enumIds);
}
Expand Down Expand Up @@ -294,23 +298,37 @@ public void remove() {

private boolean partitioned = false;

private final T handleFirst;

/**
* Create a new reference graph from the given instance collection.
*
* @param inspector the instance inspector to use
* @param instances the
* @param handleFirst the ID of the first instance to handle, optional and
* can be null
*/
public ReferenceGraph(IdentityReferenceInspector<T> inspector, InstanceCollection instances) {
public ReferenceGraph(IdentityReferenceInspector<T> inspector, InstanceCollection instances,
T handleFirst) {
this.graph = new CustomTinkerGraph();
this.inspector = inspector;
this.originalCollection = instances;
this.handleFirst = handleFirst;

populate(instances);

// identified vertices no longer needed after populate
identifiedVertices.clear();
}

/**
* @param inspector the instance inspector to use
* @param instances the
*/
public ReferenceGraph(IdentityReferenceInspector<T> inspector, InstanceCollection instances) {
this(inspector, instances, null);
}

/**
* Populate the graph with the instances from the given collection.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private void partitionByPlan(ProgressIndicator progress, IOReporter reporter)
for (String planId : planIdToInstancesMapping.keySet()) {
MultiInstanceCollection mic = new MultiInstanceCollection(
Arrays.asList(planIdToInstancesMapping.get(planId), nonPlanInstances));
ReferenceGraph<String> rg = new ReferenceGraph<String>(new XMLInspector(), mic);
ReferenceGraph<String> rg = new ReferenceGraph<String>(new XMLInspector(), mic, planId);

Iterator<InstanceCollection> p = rg.partition(1, reporter);
while (p.hasNext()) {
Expand Down

0 comments on commit 23bcc04

Please sign in to comment.