-
- All Implemented Interfaces:
public final class NodeQueryExecutor
Generates Cypher-DSL queries based on a NodeQuery, executes it and parses the result
-
-
Field Summary
Fields Modifier and Type Field Description private Integer
nameCounter
private final HashMap<String, NodeSubQuery>
subQueryLookup
private final NodeQuery
nodeQuery
private final ReactiveNeo4jClient
client
private final Neo4jMappingContext
mappingContext
-
Constructor Summary
Constructors Constructor Description NodeQueryExecutor(NodeQuery nodeQuery, ReactiveNeo4jClient client, Neo4jMappingContext mappingContext)
-
Method Summary
Modifier and Type Method Description final Integer
getNameCounter()
Counter for unique name generation final Unit
setNameCounter(Integer nameCounter)
Counter for unique name generation final HashMap<String, NodeSubQuery>
getSubQueryLookup()
lookup for generated subqueries final NodeQuery
getNodeQuery()
final ReactiveNeo4jClient
getClient()
final Neo4jMappingContext
getMappingContext()
final NodeQueryResult<?>
execute()
Executes the query final StatementWithSymbolicName
createRootNodeQuery()
Generates the query for nodeQuery final StatementWithSymbolicName
createNodeQuery(NodeQuery nodeQuery, StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere builder, Node node)
Generates a query based on nodeQuery
final StatementBuilder.OrderableOngoingReadingAndWith
applyFilterConditions(NodeQueryOptions options, StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere builder, Node node)
Applies all filter conditions to a builder and returns the resulting builder final StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere
applyTotalCount(NodeQueryOptions options, StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere builder, SymbolicName allNodesCollected, SymbolicName totalCount)
If necessary, adds a with statement to the builder
which fetches totalCountfinal StatementWithSymbolicName
createReturnStatement(StatementBuilder.OngoingReadingWithoutWhere builder, SymbolicName nodesCollected, NodeQueryOptions options, SymbolicName totalCount)
Creates the return statement and builds the query. 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 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. final StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere
applyAfterAndBefore(NodeQueryOptions options, SymbolicName nodeAlias, StatementBuilder.OngoingReading builder)
Adds before and after filters to the builder
final StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere
applyResultLimiters(NodeQueryOptions options, StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere builder, SymbolicName nodeAlias)
Orders the nodes and adds first and last filters 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 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 final List<SortItem>
generateOrderFields(Order<?> order, SymbolicName node, Boolean reversed)
Transforms an Order into a list of SortItem final StatementWithSymbolicName
createSubQuery(NodeSubQuery subQuery, Node node)
Creates a subquery using a Cypher subquery Uses NodeSubQuery.onlyOnTypes to only fetch related nodes when necessary final SymbolicName
generateUniqueName()
Generates a new unique name final Node
createNodeDefinitionNode(NodeDefinition nodeDefinition)
Creates a Node for a NodeDefinition. final NodeQueryResult<?>
parseQueryResult(Value nodesValue, Value totalCountValue, NodeQuery nodeQuery)
Parses the result of a query (a list of nodes, and optional a totalCount). final Node
parseNode(Value value, NodeDefinition nodeDefinition)
Parses a single node Parses subqueries recursively -
-
Constructor Detail
-
NodeQueryExecutor
NodeQueryExecutor(NodeQuery nodeQuery, ReactiveNeo4jClient client, Neo4jMappingContext mappingContext)
- Parameters:
nodeQuery
- the query to executeclient
- used to execute the querymappingContext
- used to transform the result into a node
-
-
Method Detail
-
getNameCounter
final Integer getNameCounter()
Counter for unique name generation
-
setNameCounter
final Unit setNameCounter(Integer nameCounter)
Counter for unique name generation
-
getSubQueryLookup
final HashMap<String, NodeSubQuery> getSubQueryLookup()
lookup for generated subqueries
-
getNodeQuery
final NodeQuery getNodeQuery()
-
getClient
final ReactiveNeo4jClient getClient()
-
getMappingContext
final Neo4jMappingContext getMappingContext()
-
execute
final NodeQueryResult<?> execute()
Executes the query
-
createRootNodeQuery
final StatementWithSymbolicName createRootNodeQuery()
Generates the query for nodeQuery
-
createNodeQuery
final StatementWithSymbolicName createNodeQuery(NodeQuery nodeQuery, StatementBuilder.OrderableOngoingReadingAndWithWithoutWhere builder, Node node)
Generates a query based on
nodeQuery
- Parameters:
nodeQuery
- defines the query to convertbuilder
- the start of the query, used to generate the full querynode
- 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 filtersbuilder
- builder for Cypher-DSL querynode
- 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 fetchedbuilder
- ongoing statement builderallNodesCollected
- name for the variable containing a collection of all nodestotalCount
- 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 buildernodesCollected
- name for the variable containing a collection of all nodesoptions
- options of the query, defines if totalCount must be fetchedtotalCount
- 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 querynode
- node which shall be used when unwindingallNodesCollected
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 nodesubQueryResultList
- list of the result variable names of subqueries that should be present in the resultbuilder
- ongoing statement buildernodeAlias
- name of the variable containing the nodeoptions
- 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 beforenodeAlias
- name of the variable containing the nodebuilder
- 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 lastbuilder
- ongoing statement buildernodeAlias
- 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 buildernode
- the current node, necessary to build relation condition for subquerynodeQuery
- 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 cursororder
- order in which the nodes will be sorted, necessary to interpret cursornode
- the name of the variable storing the node to filterforwards
- iftrue
, 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 transformnode
- name of the variable containing the nodereversed
- iftrue
, the direction defined byorder
is reversed
-
createSubQuery
final StatementWithSymbolicName createSubQuery(NodeSubQuery subQuery, Node node)
Creates a subquery using a Cypher subquery Uses NodeSubQuery.onlyOnTypes to only fetch related nodes when necessary
- Parameters:
subQuery
- the subquery to convertnode
- parent side defining node of the relation
-
generateUniqueName
final SymbolicName generateUniqueName()
Generates a new unique name
-
createNodeDefinitionNode
final Node createNodeDefinitionNode(NodeDefinition nodeDefinition)
Creates a Node for a NodeDefinition.
- Parameters:
nodeDefinition
- the definition for which to create the Node
-
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 valuetotalCountValue
- the returned totalCount valuenodeQuery
- 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 nodenodeDefinition
- defines the type of node to convert
-
-
-
-