Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-19-2021 12:15 PM
I am new to the community so this is my first post, hopefully the answer is quite simple and I am just not great at reading java docs!
I am using the java driver to execute a series of write-only transactions and I would like to try and receive the update summary similar to what's provided in the browser.
I found that the result.consume() gives me a result summary but I am not sure if what I am looking for is something created from that, or something else.
I greatly appreciate any help!
What I have:
public void updateQuery( final String cypher, Map<String,Object> params)
{
try ( Session session = driver.session() )
{
Transaction tx = session.beginTransaction();
String[] commands = cypher.split(";");
for (String command : commands)
{
Result result = tx.run(command, params);
System.out.println(result.consume().toString());
}
tx.commit();
return;
}
}
What I am looking for:
Solved! Go to Solution.
03-22-2021 03:19 AM
03-22-2021 03:19 AM
03-22-2021 09:43 AM
Looks like that got me what I needed! Here is the script incase anyone wants it:
private String getResultSummaryString( ResultSummary summary) {
SummaryCounters counters = summary.counters();
List<String> resultList = new ArrayList<String>();
long duration = summary.resultAvailableAfter(TimeUnit.MILLISECONDS);
if ( counters.containsUpdates() ) {
int nodesCreated = counters.nodesCreated();
if ( nodesCreated > 0 ) {
resultList.add( "Created " + nodesCreated + " nodes" );
}
int nodesDeleted = counters.nodesDeleted();
if ( nodesDeleted > 0 ) {
resultList.add( "Deleted " + nodesDeleted + " nodes" );
}
int propertiesSet = counters.propertiesSet();
if ( propertiesSet > 0 ) {
resultList.add( "Set " + propertiesSet + " properties" );
}
int relationshipsCreated = counters.relationshipsCreated();
if ( relationshipsCreated > 0 ) {
resultList.add( "Created " + relationshipsCreated + " relationships" );
}
int relationshipsDeleted = counters.relationshipsDeleted();
if ( relationshipsDeleted > 0 ) {
resultList.add( "Deleted " + relationshipsDeleted + " relationships" );
}
}
resultList.add( "Completed in " + duration + "ms" );
return String.join(", ", resultList);
}
All the sessions of the conference are now available online