Fetch missing nodes in dbMerge
@@ -233,23 +233,23 @@ public class DatabaseMerger {
final long startTime = System.currentTimeMillis();
- try (var cursor = getArcs(callGraphData, dbContext)) {
+ var cursor = getArcs(callGraphData, dbContext);
while (cursor.hasNext()) {
var arcRecord = cursor.fetchNext();
var arc = new Arc(arcRecord.value1(), arcRecord.value2(), arcRecord.value3());
if (callGraphData.isExternal(arc.target)) {
- if (!resolve(result, callGraphData, arc, typeMap.get(arc.target), false)) {
+ var node = typeMap.containsKey(arc.target) ? typeMap.get(arc.target) : fetchMissingNode(arc.target, dbContext);
+ if (!resolve(result, callGraphData, arc, node, false)) {
addEdge(result, callGraphData, arc.source, arc.target, false);
}
} else {
- if (!resolve(result, callGraphData, arc, typeMap.get(arc.source), callGraphData.isExternal(arc.source))) {
+ var node = typeMap.containsKey(arc.source) ? typeMap.get(arc.source) : fetchMissingNode(arc.source, dbContext);
+ if (!resolve(result, callGraphData, arc, node, callGraphData.isExternal(arc.source))) {
addEdge(result, callGraphData, arc.source, arc.target, callGraphData.isExternal(arc.source));
}
}
}
- } catch (Exception e) {
- logger.error("Unable to fetch data from metadata database");
- }
+
logger.info("Stitched in {} seconds", new DecimalFormat("#0.000")
.format((System.currentTimeMillis() - startTime) / 1000d));
logger.info("Merged call graphs in {} seconds", new DecimalFormat("#0.000")
@@ -375,7 +375,6 @@ public class DatabaseMerger {
.where(arcsCondition)
.fetchSize(10000)
.fetchLazy();
- //.map(arc -> new Arc(arc.value1(), arc.value2(), arc.value3()));
}
/**
@@ -437,6 +436,27 @@ public class DatabaseMerger {
return typeMap;
}
+ /**
+ * Tries to fetch a FastenURI from a metadata database with a given callable ID or throws
+ * a new RuntimeException if no callable is found.
+ *
+ * @param callableId ID of a callable to fetch
+ * @param dbContext DSL context
+ * @return Node
+ */
+ private Node fetchMissingNode(final Long callableId, final DSLContext dbContext) {
+ var callable = dbContext
+ .select(Callables.CALLABLES.FASTEN_URI)
+ .from(Callables.CALLABLES)
+ .where(Callables.CALLABLES.ID.eq(callableId))
+ .fetchOne();
+ if (callable == null) {
+ throw new RuntimeException("Callable with ID " + callableId
+ + " couldn't be found in the metadata database");
+ }
+ return new Node(FastenJavaURI.create(callable.value1()).decanonicalize());
+ }
+
/**
* Create a mapping from types and method signatures to callable IDs.
*
