-
Notifications
You must be signed in to change notification settings - Fork 2
Working with Neo4j
Neo4j is a graph database service that is run on the local machine. We have bundled the service together with Microbat as a docker container. In order to record traces in Neo4j, please follow instructions to start neo4j on your local machine.
The default user and password is neo4j for the first time. Microbat uses "neo4j" and "microbat" as the username and password respectively.
Database transactions are executed with a session.
A session can be created using driver.session()
.
With a session
, we insert transactions by supplying an anonymous function tx -> tx.run(query)
,
where query
refers to the Cypher query for Neo4j.
Write transactions can be run with session.writeTransaction()
.
Read transactions return the parameterized type of the input function.
For example, session.readTransaction(fn)
has the same return type as fn
.
For interpolated query strings, we can use a hashmap to represent the parameters more succinctly. For example:
String query = "MERGE (a:Location {locationId: $locationId, traceId: $traceId, className: $className, lineNumber: $lineNumber, isConditional: $isConditional, isReturn: $isReturn})"
The values can be supplied with tx.run(query, parameters("locationId", "here", ...))
or alternatively,
Map<String, Object> props = new HashMap<>();
props.put("locationId", bp.getDeclaringCompilationUnitName() + "_" + bp.getLineNumber());
props.put("traceId", traceId);
props.put("className", bp.getDeclaringCompilationUnitName());
props.put("lineNumber", bp.getLineNumber());
props.put("isConditional", bp.isConditional());
props.put("isReturn", bp.isReturnStatement());
return tx.run(query, props);
where all the mapping of the parameters are specified props
.