org.neo4j.graphdb.Result.next()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(92)

本文整理了Java中org.neo4j.graphdb.Result.next方法的一些代码示例,展示了Result.next的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Result.next方法的具体详情如下:
包路径:org.neo4j.graphdb.Result
类名称:Result
方法名:next

Result.next介绍

暂无

代码示例

代码示例来源:origin: neo4j/neo4j

public void consume()
{
  while ( originalResult.hasNext() )
  {
    queryResult.add( originalResult.next() );
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
  public void collections_in_collections_look_alright()
  {
    Result result = db.execute( "CREATE (n:TheNode) RETURN [[ [1,2],[3,4] ],[[5,6]]] as x" );
    Map<String, Object> next = result.next();
    @SuppressWarnings( "unchecked" ) //We know it's a collection.
    List<List<Object>> x = (List<List<Object>>)next.get( "x" );
    Iterable objects = x.get( 0 );

    assertThat(objects, isA(Iterable.class));
  }
}

代码示例来源:origin: neo4j/neo4j

@SuppressWarnings( "unchecked" )
@Test
public void shouldNotReturnInternalPointWhenInArray()
{
  // when
  Result execute = graphDb.execute( "RETURN [point({longitude: 144.317718, latitude: -37.031738})] AS ps" );
  // then
  List<Point> points = (List<Point>)execute.next().get( "ps" );
  assertThat( points.get(0), Matchers.instanceOf(Point.class));
}

代码示例来源:origin: neo4j/neo4j

private Callable<Number> countNodes()
  {
    return () ->
    {
      try ( Transaction transaction = database.beginTx() )
      {
        Result result = database.execute( "MATCH (n) RETURN count(n) as count" );
        Map<String,Object> resultMap = result.next();
        return (Number) resultMap.get( "count" );
      }
    };
  }
}

代码示例来源:origin: neo4j/neo4j

private void verifyResult( Result result )
{
  Map firstRowValue = (Map) result.next().values().iterator().next();
  assertThat( firstRowValue.get( "key" ), is( "Value" ) );
  List theList = (List) firstRowValue.get( "collectionKey" );
  assertThat( ((Map) theList.get( 0 )).get( "inner" ), is( "Map1" ) );
  assertThat( ((Map) theList.get( 1 )).get( "inner" ), is( "Map2" ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldProduceWellFormedJsonEvenIfResultIteratorThrowsExceptionOnNext() throws Exception
  mockAccept( executionResult );
  when( executionResult.columns() ).thenReturn( new ArrayList<>( data.keySet() ) );
  when( executionResult.hasNext() ).thenReturn( true, true, false );
  when( executionResult.next() ).thenReturn( data ).thenThrow( new RuntimeException( "Stuff went wrong!" ) );

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldThrowAppropriateException()
{
  try
  {
    db.execute( "RETURN rand()/0" ).next();
  }
  catch ( QueryExecutionException ex )
  {
    assertThat( ex.getCause(), instanceOf( QueryExecutionKernelException.class ) );
    assertThat( ex.getCause().getCause(), instanceOf( ArithmeticException.class ) );
  }
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

private long executeNumericResultStatement(@Name("statement") String statement, @Name("params") Map<String, Object> parameters) {
  long sum = 0;
  try (Result result = db.execute(statement, parameters)) {
    while (result.hasNext()) {
      Collection<Object> row = result.next().values();
      for (Object value : row) {
        if (value instanceof Number) {
          sum += ((Number)value).longValue();
        }
      }
    }
  }
  return sum;
}

代码示例来源:origin: neo4j/neo4j

@Test
public void executeCountStoreQueryWithSingleRetry()
{
  Result result = database.execute( "MATCH (n:toRetry) RETURN count(n)" );
  assertEquals( 1, testCursorContext.getAdditionalAttempts() );
  while ( result.hasNext() )
  {
    assertEquals( 1L, result.next().get( "count(n)" ) );
  }
}

代码示例来源:origin: neo4j/neo4j

@SuppressWarnings( "unchecked" )
@Test
public void shouldNotReturnInternalPointWhenInMap()
{
  // when
  Result execute = graphDb.execute( "RETURN {p: point({longitude: 144.317718, latitude: -37.031738})} AS m" );
  // then
  Map<String,Object> points = (Map<String, Object>)execute.next().get( "m" );
  assertThat( points.get("p"), Matchers.instanceOf(Point.class));
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldProduceWellFormedJsonEvenIfResultIteratorThrowsExceptionOnHasNext() throws Exception
  mockAccept( executionResult );
  when( executionResult.columns() ).thenReturn( new ArrayList<>( data.keySet() ) );
  when( executionResult.hasNext() ).thenReturn( true ).thenThrow(
      new RuntimeException( "Stuff went wrong!" ) );
  when( executionResult.next() ).thenReturn( data );

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldCloseTransactionsWhenIteratingResults()
{
  // Given an execution result that has been started but not exhausted
  createNode();
  createNode();
  Result executionResult = db.execute( "CYPHER runtime=interpreted MATCH (n) RETURN n" );
  executionResult.next();
  assertThat( activeTransaction(), is( notNullValue() ) );
  // When
  executionResult.close();
  // Then
  assertThat( activeTransaction(), is( nullValue() ) );
}

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

private Object executeStatement(BlockingQueue<RowResult> queue, String stmt, Map<String, Object> params, boolean addStatistics, long timeout) throws InterruptedException {
  try (Result result = db.execute(stmt,params)) {
    long time = System.currentTimeMillis();
    int row = 0;
    while (result.hasNext()) {
      terminationGuard.check();
      queue.put(new RowResult(row++, result.next()));
    }
    if (addStatistics) {
      queue.offer(new RowResult(-1, toMap(result.getQueryStatistics(), System.currentTimeMillis() - time, row)), timeout,TimeUnit.SECONDS);
    }
    return row;
  }
}

代码示例来源:origin: neo4j/neo4j

private void executeDistantFriendsCountQuery( int userId )
{
  Map<String,Object> params = singletonMap( "userId", (long) randomInt( userId ) );
  try ( Result result = db.execute(
      "MATCH (user:User { userId: {userId} } ) -[:FRIEND]- () -[:FRIEND]- (distantFriend) " +
      "RETURN COUNT(distinct distantFriend)", params ) )
  {
    while ( result.hasNext() )
    {
      result.next();
    }
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void executeQueryWithSingleRetry()
{
  Result result = database.execute( "MATCH (n) RETURN n.c" );
  assertEquals( 1, testCursorContext.getAdditionalAttempts() );
  while ( result.hasNext() )
  {
    assertEquals( "d", result.next().get( "n.c" ) );
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldHandleMapWithPointsAsInput()
{
  // Given
  Point point1 = (Point) db.execute( "RETURN point({latitude: 12.78, longitude: 56.7}) as point"  ).next().get( "point" );
  Point point2 = (Point) db.execute( "RETURN point({latitude: 12.18, longitude: 56.2}) as point"  ).next().get( "point" );
  // When
  double distance = (double) db.execute( "RETURN distance({points}['p1'], {points}['p2']) as dist",
      map( "points", map("p1", point1, "p2", point2) ) ).next().get( "dist" );
  // Then
  assertThat(Math.round( distance ), equalTo(86107L));
}

代码示例来源:origin: neo4j/neo4j

@Test
public void fulltextIndexMustIgnoreNonStringPropertiesForPopulation()
    if ( nodes.hasNext() )
      fail( "did not expect to find any nodes, but found at least: " + nodes.next() );
    if ( relationships.hasNext() )
      fail( "did not expect to find any relationships, but found at least: " + relationships.next() );

代码示例来源:origin: neo4j-contrib/neo4j-apoc-procedures

private void assertResultsAreEqual( String query1, String query2 )
{
  try ( Transaction ignore = db.beginTx() )
  {
    Result result1 = db.execute( query1 );
    Result result2 = db.execute( query2 );
    while ( result1.hasNext() )
    {
      assertTrue( result2.hasNext() );
      assertThat( result1.next(), equalTo( result2.next() ) );
    }
    assertFalse( result2.hasNext() );
  }
}

代码示例来源:origin: neo4j/neo4j

private static void mockAccept( Result mock )
{
  doAnswer( invocation ->
  {
    Result result = (Result) invocation.getMock();
    Result.ResultVisitor visitor = invocation.getArgument( 0 );
    while ( result.hasNext() )
    {
      visitor.visit( new MapRow( result.next() ) );
    }
    return null;
  } ).when( mock )
      .accept( (Result.ResultVisitor<RuntimeException>) any( Result.ResultVisitor.class ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void executeLabelScanQueryWithSingleRetry()
{
  Result result = database.execute( "MATCH (n:toRetry) RETURN n.c" );
  assertEquals( 1, testCursorContext.getAdditionalAttempts() );
  while ( result.hasNext() )
  {
    assertEquals( "d", result.next().get( "n.c" ) );
  }
}

相关文章