java - neo4j ExecutionResult: Extract multiple columns (since javaColumnAs only works once) -


i doing cyper query this:

stringbuilderstringlogger logger = new stringbuilderstringlogger(new stringbuilder()); graphdatabaseservice neo4jdb = database.getdatabase(); executionresult result = engine.execute("match (n:person{name:'test'}) match n-[r]->m return n,r,m;"); 

so want out n, r , m. tried following:

node node = iteratorutil.single(result.javacolumnas("n")); relationship relationship = iteratorutil.single(result.javacolumnas("r")); node othernode = iteratorutil.single(result.javacolumnas("m")); 

now not seem work. fhe first request works, second 1 return empty iterator , therefore null relationship or object. reason is, executionresul lazy iterator. if go through once (like javacolumnas, iterates on it), can not out of afterwards. find explanation: https://groups.google.com/forum/#!searchin/neo4j/javacolumnas/neo4j/oup_2b8maly/sp39sfym9_4j

now if way, works correctly.

node node = null; relationship relationship = null; node othernode = null;  (map<string, object> row : iteratorutil.asiterable(result.javaiterator())) {     (map.entry<string, object> column : row.entryset()) {          switch (column.getkey()){             case "n":                 node = (node) column.getvalue();                 break;             case "r":                 relationship = (relationship) column.getvalue();                 break;             case "m":                 othernode = (node) column.getvalue();                 break;         }         system.out.println(column.getkey() + ": " + column.getvalue() + "; ");     } } 

now hope not 1 thinks not nice code tried first. there way nicer?

since you're returning multiple columns, pick them name row (which map key column name, , value column value):

for (map<string, object> row : result) {    node = (node) row.get("n");            relationship = (relationship) row.get("r");    othernode = (node) row.get("m");  } 

ps: posted example please parameterize queries


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -