Fetch callables metadata
package eu.fasten.core.merge;
-import com.github.t9t.jooq.json.JsonbDSL;
import eu.fasten.core.data.ArrayImmutableDirectedGraph;
import eu.fasten.core.data.Constants;
import eu.fasten.core.data.DirectedGraph;
@@ -46,8 +45,6 @@ import org.jgrapht.graph.DefaultDirectedGraph;
import org.jgrapht.graph.DefaultEdge;
import org.jooq.Condition;
import org.jooq.DSLContext;
-import org.jooq.JSONB;
-import org.jooq.Record2;
import org.json.JSONObject;
import org.rocksdb.RocksDBException;
import org.slf4j.Logger;
@@ -174,64 +171,28 @@ public class DatabaseMerger {
return augmentGraphs(depGraphs);
}
-
/**
- * Fetches metadata of the nodes of first arg from database in the specified batch size.
+ * Fetches metadata of the nodes of first arg from database.
*
- * @param dg DirectedGraph to search for its callable's metadata in the database.
- * @param batchSize the size of the batch for querying the database.
+ * @param graph DirectedGraph to search for its callable's metadata in the database.
* @return Map of callable ids and their corresponding metadata in the form of
* JSONObject.
*/
- public Map<Long, JSONObject> getCallablesMetadata(final DirectedGraph dg,
- final int batchSize) {
+ public Map<Long, JSONObject> getCallablesMetadata(final DirectedGraph graph) {
final Map<Long, JSONObject> result = new HashMap<>();
- int batchCounter = 0;
- final List<Long> batch = new ArrayList<>();
-
- for (final var node : dg.nodes()) {
-
- batch.add(node);
- batchCounter++;
- if (batchCounter < batchSize){
- continue;
- }else {
final var metadata = dbContext
.select(Callables.CALLABLES.ID, Callables.CALLABLES.METADATA)
.from(Callables.CALLABLES)
- .where(Callables.CALLABLES.ID.equal(node))
+ .where(Callables.CALLABLES.ID.in(graph.nodes()))
.fetch();
for (final var callable : metadata) {
result.put(callable.value1(), new JSONObject(callable.value2().data()));
}
- batch.clear();
- batchCounter = 0;
- }
- }
return result;
}
- /**
- * Augment generated merged call graphs.
- *
- * @param depGraphs merged call graphs
- * @return augmented graph
- */
- private DirectedGraph augmentGraphs(final List<DirectedGraph> depGraphs) {
- var result = new ArrayImmutableDirectedGraph.Builder();
-
- for (final var depGraph : depGraphs) {
- for (final var node : depGraph.nodes()) {
- for (final var successor : depGraph.successors(node)) {
- addEdge(result, depGraph, node, successor, false);
- }
- }
- }
- return result.build();
- }
-
/**
* Merges a call graph with its dependencies using CHA algorithm.
*
@@ -653,6 +614,25 @@ public class DatabaseMerger {
}
}
+ /**
+ * Augment generated merged call graphs.
+ *
+ * @param depGraphs merged call graphs
+ * @return augmented graph
+ */
+ private DirectedGraph augmentGraphs(final List<DirectedGraph> depGraphs) {
+ var result = new ArrayImmutableDirectedGraph.Builder();
+
+ for (final var depGraph : depGraphs) {
+ for (final var node : depGraph.nodes()) {
+ for (final var successor : depGraph.successors(node)) {
+ addEdge(result, depGraph, node, successor, false);
+ }
+ }
+ }
+ return result.build();
+ }
+
/**
* Add a resolved edge to the {@link DirectedGraph}.
*
