Package 

Class NodeQueryExecutor

  • All Implemented Interfaces:

    
    public final class NodeQueryExecutor
    
                        

    Generates Cypher-DSL queries based on a NodeQuery, executes it and parses the result

    • Constructor Detail

      • NodeQueryExecutor

        NodeQueryExecutor(NodeQuery nodeQuery, ReactiveNeo4jClient client, Neo4jMappingContext mappingContext)
        Parameters:
        nodeQuery - the query to execute
        client - used to execute the query
        mappingContext - used to transform the result into a node
    • Method Detail

      • getClient

         final ReactiveNeo4jClient getClient()
      • createNodeQuery

         final StatementWithSymbolicName createNodeQuery(NodeQuery nodeQuery, StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere builder, Node node)

        Generates a query based on nodeQuery

        Parameters:
        nodeQuery - defines the query to convert
        builder - the start of the query, used to generate the full query
        node - associated node for conditions and relations
      • applyFilterConditions

         final StatementBuilder.OrderableOngoingReadingAndWith applyFilterConditions(NodeQueryOptions options, StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere builder, Node node)

        Applies all filter conditions to a builder and returns the resulting builder

        Parameters:
        options - options which define filters
        builder - builder for Cypher-DSL query
        node - the node to generate the filter conditions for
      • applyTotalCount

         final StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere applyTotalCount(NodeQueryOptions options, StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere builder, SymbolicName allNodesCollected, SymbolicName totalCount)

        If necessary, adds a with statement to the builder which fetches totalCount

        Parameters:
        options - options of the query, defines if totalCount must be fetched
        builder - ongoing statement builder
        allNodesCollected - name for the variable containing a collection of all nodes
        totalCount - name for the variable under which totalCount should be saved
      • createReturnStatement

         final StatementWithSymbolicName createReturnStatement(StatementBuilder.OngoingReadingWithoutWhere builder, SymbolicName nodesCollected, NodeQueryOptions options, SymbolicName totalCount)

        Creates the return statement and builds the query. If totalCount is not fetched, null is set as value for totalCount

        Parameters:
        builder - ongoing statement builder
        nodesCollected - name for the variable containing a collection of all nodes
        options - options of the query, defines if totalCount must be fetched
        totalCount - name for the variable under which totalCount should be saved
      • generateMainSubQuery

         final StatementWithSymbolicName generateMainSubQuery(NodeQuery nodeQuery, Node node, SymbolicName allNodesCollected)

        Generates a Cypher subquery which gets the list of all nodes, and applies pagination filtering, related nodes subqueries, ordering and result aggregation

        Parameters:
        nodeQuery - the currently converted query
        node - node which shall be used when unwinding allNodesCollected
        allNodesCollected - name of the input variable containing a collection of all nodes
      • generateMainSubQueryResultStatement

         final StatementWithSymbolicName generateMainSubQueryResultStatement(NodeDefinition nodeDefinition, List<SymbolicName> subQueryResultList, StatementBuilder.OngoingReading builder, SymbolicName nodeAlias, NodeQueryOptions options)

        Generates the result statement for the query generated by generateMainSubQuery. Also orders the nodes, and builds a statement out of the builder

        Parameters:
        nodeDefinition - definition for the currently queried node
        subQueryResultList - list of the result variable names of subqueries that should be present in the result
        builder - ongoing statement builder
        nodeAlias - name of the variable containing the node
        options - options for the query, defines order
      • applyAfterAndBefore

         final StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere applyAfterAndBefore(NodeQueryOptions options, SymbolicName nodeAlias, StatementBuilder.OngoingReading builder)

        Adds before and after filters to the builder

        Parameters:
        options - defines after and before
        nodeAlias - name of the variable containing the node
        builder - ongoing statement builder
      • applyResultLimiters

         final StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere applyResultLimiters(NodeQueryOptions options, StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere builder, SymbolicName nodeAlias)

        Orders the nodes and adds first and last filters

        Parameters:
        options - defines first and last
        builder - ongoing statement builder
        nodeAlias - name of the variable containing the node
      • applyPartsSubqueries

         final Pair<StatementBuilder.OngoingReading, List<SymbolicName>> applyPartsSubqueries(StatementBuilder.OngoingReading builder, Node node, NodeQuery nodeQuery)

        Generates subqueries for all subqueries defined in parts and adds them to the statement builder

        Parameters:
        builder - ongoing statement builder
        node - the current node, necessary to build relation condition for subquery
        nodeQuery - the query for which all subqueries should be applied
      • generateCursorFilterExpression

         final Condition generateCursorFilterExpression(Map<String, Object> cursor, Order<?> order, SymbolicName node, Boolean forwards)

        Generates a Condition which can be used to filter for items before/after a specific cursor

        Parameters:
        cursor - the parsed cursor
        order - order in which the nodes will be sorted, necessary to interpret cursor
        node - the name of the variable storing the node to filter
        forwards - if true, filters for items after the cursor, otherwise for items before the cursor (both inclusive)
      • generateOrderFields

         final List<SortItem> generateOrderFields(Order<?> order, SymbolicName node, Boolean reversed)

        Transforms an Order into a list of SortItem

        Parameters:
        order - the Order to transform
        node - name of the variable containing the node
        reversed - if true, the direction defined by order is reversed
      • parseQueryResult

         final NodeQueryResult<?> parseQueryResult(Value nodesValue, Value totalCountValue, NodeQuery nodeQuery)

        Parses the result of a query (a list of nodes, and optional a totalCount). Parses recursively

        Parameters:
        nodesValue - the returned node list value
        totalCountValue - the returned totalCount value
        nodeQuery - the query used to get the results
      • parseNode

         final Node parseNode(Value value, NodeDefinition nodeDefinition)

        Parses a single node Parses subqueries recursively

        Parameters:
        value - the returned value for the node
        nodeDefinition - defines the type of node to convert