use of org.neo4j.driver.v1.Statement in project open-kilda by telstra.
the class NeoDriver method getPath.
/**
* {@inheritDoc}
*/
@Override
public ImmutablePair<PathInfoData, PathInfoData> getPath(Flow flow, Strategy strategy) throws UnroutablePathException {
long latency = 0L;
List<PathNode> forwardNodes = new LinkedList<>();
List<PathNode> reverseNodes = new LinkedList<>();
if (!flow.isOneSwitchFlow()) {
Statement statement = getPathQuery(flow, strategy);
logger.debug("QUERY: {}", statement.toString());
try (Session session = driver.session()) {
StatementResult result = session.run(statement);
try {
Record record = result.next();
LinkedList<Relationship> isls = new LinkedList<>();
record.get(0).asPath().relationships().forEach(isls::add);
int seqId = 0;
for (Relationship isl : isls) {
latency += isl.get("latency").asLong();
forwardNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, isl.get("latency").asLong()));
seqId++;
forwardNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, 0L));
seqId++;
}
seqId = 0;
Collections.reverse(isls);
for (Relationship isl : isls) {
reverseNodes.add(new PathNode(isl.get("dst_switch").asString(), isl.get("dst_port").asInt(), seqId, isl.get("latency").asLong()));
seqId++;
reverseNodes.add(new PathNode(isl.get("src_switch").asString(), isl.get("src_port").asInt(), seqId, 0L));
seqId++;
}
} catch (NoSuchRecordException e) {
throw new UnroutablePathException(flow);
}
}
} else {
logger.info("No path computation for one-switch flow");
}
return new ImmutablePair<>(new PathInfoData(latency, forwardNodes), new PathInfoData(latency, reverseNodes));
}
use of org.neo4j.driver.v1.Statement in project cypher-for-gremlin by opencypher.
the class GremlinServerStatementResultTest method singleMore.
@Test(expected = NoSuchRecordException.class)
public void singleMore() {
List<Map<String, Object>> results = Arrays.asList(getRow(1), getRow(2));
StatementResult statementResult = new GremlinServerDriver.GremlinServerStatementResult(serverInfo, statement, results.iterator());
statementResult.single();
}
use of org.neo4j.driver.v1.Statement in project cypher-for-gremlin by opencypher.
the class GremlinServerStatementResultTest method consume.
@Test
public void consume() {
List<Map<String, Object>> results = Arrays.asList(getRow(1), getRow(2));
StatementResult statementResult = new GremlinServerDriver.GremlinServerStatementResult(serverInfo, statement, results.iterator());
assertThat(statementResult.hasNext()).isTrue();
assertThat(statementResult.consume().server()).isEqualTo(serverInfo);
assertThat(statementResult.hasNext()).isFalse();
}
use of org.neo4j.driver.v1.Statement in project cypher-for-gremlin by opencypher.
the class GremlinServerStatementResultTest method single.
@Test
public void single() {
List<Map<String, Object>> results = Arrays.asList(getRow(1));
StatementResult statementResult = new GremlinServerDriver.GremlinServerStatementResult(serverInfo, statement, results.iterator());
assertThat(statementResult.single().get(KEY1).asInt()).isEqualTo(1);
}
use of org.neo4j.driver.v1.Statement in project structr by structr.
the class SessionTransaction method getStrings.
public QueryResult<String> getStrings(final String statement, final Map<String, Object> map) {
final long t0 = System.currentTimeMillis();
try {
final StatementResult result = tx.run(statement, map);
final Record record = result.next();
final Value value = record.get(0);
return new QueryResult<String>() {
@Override
public void close() {
result.consume();
}
@Override
public Iterator<String> iterator() {
return value.asList(Values.ofString()).iterator();
}
};
} catch (TransientException tex) {
closed = true;
throw new RetryException(tex);
} catch (NoSuchRecordException nex) {
throw new NotFoundException(nex);
} catch (ServiceUnavailableException ex) {
throw new NetworkException(ex.getMessage(), ex);
} finally {
logQuery(statement, map, t0);
}
}
Aggregations