-
Notifications
You must be signed in to change notification settings - Fork 616
Provide saveAs
overloads with a predicate for selecting projected attributes.
#2454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…jected attributes. Closes #2420.
BiPredicate<PropertyPath, Neo4jPersistentProperty> predicate, | ||
BiConsumer<PropertyPath, Neo4jPersistentProperty> sink | ||
) { | ||
this.pathsTraversed.clear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given this call and the current usage looks like new PropertyTraverser(..).traverse(..)
wouldn't it make sense to make those methods static?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The thing has state.
src/main/java/org/springframework/data/neo4j/core/Neo4jTemplate.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/neo4j/core/ReactiveNeo4jTemplate.java
Outdated
Show resolved
Hide resolved
* @return the saved instance. | ||
* @since 6.3 | ||
*/ | ||
default <T> T saveAs(T instance, BiPredicate<PropertyPath, Neo4jPersistentProperty> includeProperty) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we accept it, the instance should be @Nullable
. Would also make sense for the saveAllAs
method and the reactive counter-parts. (Would need an additional null check in the saveAllAs
/saveAllImpl
).
src/main/java/org/springframework/data/neo4j/core/Neo4jOperations.java
Outdated
Show resolved
Hide resolved
src/main/java/org/springframework/data/neo4j/core/ReactiveNeo4jOperations.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Gerrit Meier <[email protected]>
Given Node node2 = Node.builder()
.name("test123")
.parent(rootNode) // rootNode was queried before
.build();
neo4jTemplate.saveAs(node2, (propertyPath, property) -> {
if (propertyPath.stream().count() > 1){
// do not save deeper than level 1
return false;
}
if (!property.isRelationship()) {
return true;
}
return property.getName().equals("parent");
}); 3 write queries are triggered:
The 2nd query should be filtered out |
Sorry for the late reply. Could you please describe why you explicitly add |
With |
I would like to keep this out of this PR. |
Merged with f79ad5393a9f9a54ec800f00a71b3a87a8c257e4 |
This implements #2420. Please @Andy2003 check if this suites your needs.
Before you ask: Chances are minimal to have something similar for reading. For read it just feels like the wrong approach. If we are down there, one might ask for the relevance of the mapping process itself and just delegate to the client.
Thanks @meistermeier for your help on this. I did not touch anything that might be affected by spring-projects/spring-data-commons#2420
Funny coincidence that those things have the same issue number :D