本文整理汇总了Java中org.neo4j.driver.v1.StatementResult.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java StatementResult.hasNext方法的具体用法?Java StatementResult.hasNext怎么用?Java StatementResult.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.neo4j.driver.v1.StatementResult
的用法示例。
在下文中一共展示了StatementResult.hasNext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldAuthenticateAndAuthorizeKalleMoraeusAsAdmin
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
@Test
public void shouldAuthenticateAndAuthorizeKalleMoraeusAsAdmin() throws Exception
{
Driver driver = GraphDatabase.driver( server.boltURI(), AuthTokens.basic( "moraeus", "suearom" ) );
Session session = driver.session();
session.run( "CREATE (a:Person {name:'Kalle Moraeus', title:'Riksspelman'})" );
StatementResult result =
session.run( "MATCH (a:Person) WHERE a.name = 'Kalle Moraeus' RETURN a.name AS name, a.title AS title" );
assertTrue( result.hasNext() );
while ( result.hasNext() )
{
Record record = result.next();
assertThat( record.get( "name" ).asString(), equalTo( "Kalle Moraeus" ) );
assertThat( record.get( "title" ).asString(), equalTo( "Riksspelman" ) );
System.out.println( record.get( "title" ).asString() + " " + record.get( "name" ).asString() );
}
session.close();
driver.close();
}
示例2: run
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public static SubGraph run(String query, SubGraph searchResult1, SubGraph linkedSearchResult1, ApiLocatorContext context){
SubGraph r = new SubGraph();
r.getNodes().addAll(searchResult1.getNodes());
r.cost = searchResult1.cost;
List<LuceneSearchResult> luceneSearchResults=context.getLuceneSearcher().query(query);
luceneSearchResults.sort((LuceneSearchResult a, LuceneSearchResult b)->{
Double aDist=new Double(dist(a.nodeSet,searchResult1.getNodes(),context));
Double bDist=new Double(dist(b.nodeSet,searchResult1.getNodes(),context));
return aDist.compareTo(bDist);
});
for (int i=0;i<3&&i<luceneSearchResults.size();i++) {
r.getNodes().add(luceneSearchResults.get(i).id);
for (long node:linkedSearchResult1.getNodes()){
Session session=context.connection.session();
StatementResult rs=session.run("match (a)-[r]-(b) where id(a)="+node+" and id(b)="+luceneSearchResults.get(i).id+" return id(r)");
while (rs.hasNext()){
Record item=rs.next();
r.getEdges().add(item.get("id(r)").asLong());
}
session.close();
}
}
return r;
}
示例3: run
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public String run(String branchId) {
final DbServices dbServices = DbServicesManager.getDbServices(branchId);
try (Transaction tx = dbServices.beginTx()) {
final StatementResult result = dbServices.execute(GET_LAST_COMMIT_HASH);
JSONObject response = new JSONObject();
while (result.hasNext()) {
Record next = result.next();
Object commitHash = next.get("commitHash");
response.put("commitHash", commitHash);
}
return response.toString();
} catch (Exception e) {
e.printStackTrace();
}
return "ERROR";
}
示例4: getLabels
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public Map<String, String> getLabels(boolean refresh) {
if (labels == null || refresh) {
Map<String, String> old = labels == null ?
new LinkedHashMap<String, String>() : new LinkedHashMap<>(labels);
labels = new LinkedHashMap<>();
StatementResult result = this.neo4jConnectionManager.execute("CALL db.labels()");
Set<String> colors = new HashSet<>();
while (result.hasNext()) {
Record record = result.next();
String label = record.get("label").asString();
String color = old.get(label);
while (color == null || colors.contains(color)) {
color = Neo4jConversionUtils.getRandomLabelColor();
}
colors.add(color);
labels.put(label, color);
}
}
return labels;
}
示例5: executeOperation
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
@Override
public void executeOperation(OperationType operation, CypherDriverConnectionStore<QueryStore> state,
ResultReporter resultReporter) throws DbException {
Session session = state.getSession();
OperationResult tuple = null;
int resultCount = 0;
final String queryString = getQueryString(state, operation);
state.logQuery(operation.getClass().getSimpleName(), queryString);
final StatementResult result = session.run(queryString);
if (result.hasNext()) {
final Record record = result.next();
resultCount++;
tuple = convertSingleResult(record);
if (state.isPrintResults()) {
System.out.println(tuple.toString());
}
}
session.close();
resultReporter.report(resultCount, tuple, operation);
}
示例6: getPerson
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
@TransactionAttribute(REQUIRES_NEW)
public String getPerson(String name) {
Session session = injectedDriver.session();
try {
StatementResult result = session.run("MATCH (a:Person) WHERE a.name = '" + name + "' RETURN a.name AS name, a.title AS title");
if (result.hasNext()) {
Record record = result.next();
return record.toString();
}
return name + " not found";
}
finally {
session.close();
}
}
示例7: get
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public static Neo4jNode get(long id, SnowGraphContext context){
Neo4jNode node=null;
Session session = context.getNeo4jBoltDriver().session();
String stat = "match (n) where id(n)=" + id + " return id(n), labels(n)[0], n";
StatementResult rs = session.run(stat);
while (rs.hasNext()) {
Record item=rs.next();
node=new Neo4jNode(item.get("id(n)").asLong(),item.get("labels(n)[0]").asString());
node.properties.putAll(item.get("n").asMap());
node.properties.put("id",node.id);
node.properties.put("label",node.label);
}
session.close();
return node;
}
示例8: getNeo4jRelationList
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public static List<Neo4jRelation> getNeo4jRelationList(long nodeId, SnowGraphContext context){
List<Neo4jRelation> list=new ArrayList<>();
Session session = context.getNeo4jBoltDriver().session();
String stat = "match p=(n)-[r]-(x) where id(n)=" + nodeId + " return id(r), id(startNode(r)), id(endNode(r)), type(r)";
StatementResult rs = session.run(stat);
while (rs.hasNext()) {
Record item=rs.next();
list.add(new Neo4jRelation(item.get("id(startNode(r))").asLong(),item.get("id(endNode(r))").asLong(),item.get("id(r)").asLong(),item.get("type(r)").asString()));
}
session.close();
return list;
}
示例9: get
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public static Neo4jRelation get(long rId, SnowGraphContext context){
Neo4jRelation r=null;
Session session = context.getNeo4jBoltDriver().session();
String stat = "match p=(n)-[r]-(x) where id(r)=" + rId + " return id(r), id(startNode(r)), id(endNode(r)), type(r)";
StatementResult rs = session.run(stat);
while (rs.hasNext()) {
Record item=rs.next();
r=new Neo4jRelation(item.get("id(startNode(r))").asLong(),item.get("id(endNode(r))").asLong(),item.get("id(r)").asLong(),item.get("type(r)").asString());
}
session.close();
return r;
}
示例10: run
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public static SubGraph run(SubGraph searchResult1, ApiLocatorContext context){
SubGraph r = new SubGraph();
r.getNodes().addAll(searchResult1.getNodes());
r.cost = searchResult1.cost;
for (long node : searchResult1.getNodes()) {
Session session = context.connection.session();
String stat = "match p=(n1)-[:" + CodeInDocxFileExtractor.API_EXPLAINED_BY + "]->(n2) where id(n1)=" + node + " unwind relationships(p) as r return id(r), id(startNode(r)), id(endNode(r))";
StatementResult rs = session.run(stat);
while (rs.hasNext()) {
Record item=rs.next();
long node1 = item.get("id(startNode(r))").asLong();
long node2 = item.get("id(endNode(r))").asLong();
long rel = item.get("id(r)").asLong();
r.getNodes().add(node1);
r.getNodes().add(node2);
r.getEdges().add(rel);
}
session.close();
}
return r;
}
示例11: run
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public static SubGraph run(SubGraph searchResult1, ApiLocatorContext context){
SubGraph r = new SubGraph();
r.getNodes().addAll(searchResult1.getNodes());
r.cost = searchResult1.cost;
Set<Long> flags = new HashSet<>();
for (long seed1 : searchResult1.getNodes()) {
if (flags.contains(seed1))
continue;
for (long seed2 : searchResult1.getNodes()) {
if (seed1 == seed2)
continue;
if (flags.contains(seed2))
continue;
Session session = context.connection.session();
String stat = "match p=shortestPath((n1)-[:" + codeRels + "*..10]-(n2)) where id(n1)=" + seed1 + " and id(n2)=" + seed2
+ " unwind relationships(p) as r return id(startNode(r)), id(endNode(r)), id(r)";
StatementResult rs = session.run(stat);
while (rs.hasNext()) {
Record item=rs.next();
long node1 = item.get("id(startNode(r))").asLong();
long node2 = item.get("id(endNode(r))").asLong();
long rel = item.get("id(r)").asLong();
r.getNodes().add(node1);
r.getNodes().add(node2);
r.getEdges().add(rel);
flags.add(seed2);
}
session.close();
}
flags.add(seed1);
}
return r;
}
示例12: query
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public SubGraph query(String queryString) {
if (queryString.matches("^[\\d\\s]+$")){ // 只有结点id构成的query
List<Long> idList=new ArrayList<>();
String[] eles = queryString.trim().split("\\s+");
for (String e:eles)
if (e.length()>0) {
Session session = context.connection.session();
long id=Long.parseLong(e);
String stat="match (n) where id(n)="+id+" return id(n)";
StatementResult rs = session.run(stat);
if (rs.hasNext()) {
idList.add(id);
}
session.close();
}
return idTest(idList);
}
/*
* seedMap: - key: 定位到的代码元素结点的集合 - value: 这个集合的离散度,离散度越低,说明这个图的质量越好
*/
candidateMap.clear(); // 清空candidateMap, 对于每个query即时生成
List<SubGraph> graphs = myFindSubGraphs(queryString);
if (graphs.size() > 0) {
return graphs.get(0);
}
return new SubGraph();
}
示例13: runAnalyses
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
public void runAnalyses(String branchId) {
final DbServices dbServices = DbServicesManager.getDbServices(branchId);
final Collection<String> analysisQueries = ResourceReader.getAnalysisQueries();
for (String query : analysisQueries) {
try (Transaction tx = dbServices.beginTx()) {
StatementResult result = dbServices.execute(query);
while (result.hasNext()) {
Record record = result.next();
String message = record.get("message").asString();
String entityName = record.get("entityName").asString();
String compilationUnitPath = record.get("compilationUnitPath").asString();
int line = Integer.parseInt(record.get("line").asString());
int column = Integer.parseInt(record.get("column").asString());
if (entityName.isEmpty()) {
logger.info(String.format("%s at %d:%d in %s", message, line, column, compilationUnitPath));
} else {
logger.info(String.format("%s: %s at %d:%d in %s", message, entityName, line, column, compilationUnitPath));
}
}
tx.success();
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例14: getTypes
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
private Set<String> getTypes(boolean refresh) {
if (types == null || refresh) {
types = new HashSet<>();
StatementResult result = this.neo4jConnectionManager.execute("CALL db.relationshipTypes()");
while (result.hasNext()) {
Record record = result.next();
types.add(record.get("relationshipType").asString());
}
}
return types;
}
示例15: executeOperation
import org.neo4j.driver.v1.StatementResult; //导入方法依赖的package包/类
@Override
public void executeOperation(LdbcShortQuery5MessageCreator operation,
DbConnectionState dbConnectionState,
ResultReporter resultReporter) throws DbException {
Driver driver = ((Neo4jDbConnectionState) dbConnectionState).getDriver();
String statement =
" MATCH (m:Message {id:{id}})-[:HAS_CREATOR]->(p:Person)"
+ " RETURN"
+ " p.id AS personId,"
+ " p.firstName AS firstName,"
+ " p.lastName AS lastName";
Value parameters = parameters(
"id", String.valueOf(operation.messageId()));
// Execute the query and get the results.
try (Session session = driver.session(AccessMode.READ)) {
try (Transaction tx = session.beginTransaction()) {
StatementResult result = tx.run(statement, parameters);
tx.success();
tx.close();
if (result.hasNext()) {
Record record = result.next();
resultReporter.report(
0,
new LdbcShortQuery5MessageCreatorResult(
Long.valueOf(record.get("personId").asString()),
record.get("firstName").asString(),
record.get("lastName").asString()),
operation);
} else {
resultReporter.report(0, null, operation);
}
}
}
}