Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-11-2022 03:35 AM
Hello,
My question is basically a follow-up question to SDN custom query with multiple different domain types
It would be nice to get an Cypher-DSL Expression for a domain type, which exactly fetches the data needed by the mapping function if get from the Neo4jMappingContext (for non-cyclic types). This would make the queries more reliable (no user errors in creating the return statement), but especially would guarantee that no adoption of the query is necessary if the underlaying domain type changes.
I know that this can be done using CypherGenerator#createReturnStatementForMatch, but is there a way to do this using the public api?
01-12-2022 03:06 AM
Currently there is no such method in the CypherDSL.
If I understand you correctly, you do not want to have only a map projection of the plain properties of a node but also the relationships, right? This would be the equivalent result to the createReturnStatementForMatch
method.
What I think makes the subject a little bit complex -in contrast to keeping the surface of the CypherDSL simple- is the case cyclic pattern, that you have already mentioned.
This would mean that the code generator in the CypherDSL would have to get a sense of how the domain looks like beyond the current entity it is creating code for.
We are thinking about this.
01-12-2022 07:38 AM
Thanks for the answer.
Yes, exactly, I also want the relationships.
However, my gut feeling would be to not put this into the Cypher-DSL, but just add a function somewhere in SND6, maybe on the MappingContext (I may be totally wrong there).
Also, for cyclic types, I think getting the expression does not make sense, as SDN6 uses multiple queries in this case, and the idea behind the getting the expression is building a complex query, which fetches all the data, this does not work if additional queries are necessary (I hope this makes sense).
The function might look something like this:
public Expression createExpressionForNonCyclicType(Neo4jPersistentEntity<?> nodeDescription,
SymbolicName nodeName) {
Predicate<PropertyFilter.RelaxedPropertyPath> includeField = (pp -> true);
if (nodeDescription.containsPossibleCircles(includeField)) {
throw new IllegalArgumentException("there are possible circles, creating Expression not possible");
} else {
List<RelationshipDescription> processedRelationships = new ArrayList<>();
return projectPropertiesAndRelationships(
PropertyFilter.RelaxedPropertyPath.withRootType(nodeDescription.getUnderlyingClass()),
nodeDescription,
nodeName,
includeField,
null,
processedRelationships);
}
}
I don't know if this works for all corner cases, but I hope this makes the feature idea a bit clearer
All the sessions of the conference are now available online