-
Notifications
You must be signed in to change notification settings - Fork 617
Setting most generic class for source of relationship #2527
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
103c3c2
Test-Case for #2526 (Projecting rich relation for inherited nodes fails)
Andy2003 ad16b0b
Setting most generic class for source of relationship.
Andy2003 73261d4
Setting most generic class for source of relationship
Andy2003 6ada466
GH-2526 - extend tests
meistermeier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
...a/org/springframework/data/neo4j/integration/issues/gh2526/AccountingMeasurementMeta.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2011-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.neo4j.integration.issues.gh2526; | ||
|
||
import static org.springframework.data.neo4j.core.schema.Relationship.Direction.*; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import org.springframework.data.neo4j.core.schema.Node; | ||
import org.springframework.data.neo4j.core.schema.Relationship; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
@Node | ||
@Data | ||
@Setter(AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) | ||
@SuperBuilder(toBuilder = true) | ||
public class AccountingMeasurementMeta extends MeasurementMeta { | ||
|
||
private String formula; | ||
|
||
@Relationship(type = "WEIGHTS", direction = OUTGOING) private MeasurementMeta baseMeasurement; | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/org/springframework/data/neo4j/integration/issues/gh2526/BaseNodeEntity.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2011-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.neo4j.integration.issues.gh2526; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.NonFinal; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import org.springframework.data.neo4j.core.schema.GeneratedValue; | ||
import org.springframework.data.neo4j.core.schema.Id; | ||
import org.springframework.data.neo4j.core.support.UUIDStringGenerator; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
@org.springframework.data.neo4j.core.schema.Node | ||
@NonFinal | ||
@Data | ||
@Setter(AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(onlyExplicitlyIncluded = true) | ||
@SuperBuilder(toBuilder = true) | ||
public class BaseNodeEntity { | ||
|
||
@Id | ||
@GeneratedValue(UUIDStringGenerator.class) | ||
@EqualsAndHashCode.Include private String nodeId; | ||
} |
26 changes: 26 additions & 0 deletions
26
...est/java/org/springframework/data/neo4j/integration/issues/gh2526/BaseNodeRepository.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2011-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.neo4j.integration.issues.gh2526; | ||
|
||
import org.springframework.data.neo4j.repository.Neo4jRepository; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
public interface BaseNodeRepository extends Neo4jRepository<BaseNodeEntity, String> { | ||
|
||
<R> R findByNodeId(String nodeIds, Class<R> clazz); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/org/springframework/data/neo4j/integration/issues/gh2526/DataPoint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2011-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.neo4j.integration.issues.gh2526; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Value; | ||
import lombok.With; | ||
|
||
import org.springframework.data.annotation.Immutable; | ||
import org.springframework.data.neo4j.core.schema.RelationshipId; | ||
import org.springframework.data.neo4j.core.schema.RelationshipProperties; | ||
import org.springframework.data.neo4j.core.schema.TargetNode; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
@RelationshipProperties | ||
@Value | ||
@With | ||
@AllArgsConstructor | ||
@Immutable | ||
@EqualsAndHashCode(onlyExplicitlyIncluded = true) | ||
public class DataPoint { | ||
|
||
@RelationshipId Long id; | ||
|
||
boolean manual; | ||
|
||
@TargetNode | ||
@EqualsAndHashCode.Include Measurand measurand; | ||
} |
100 changes: 100 additions & 0 deletions
100
src/test/java/org/springframework/data/neo4j/integration/issues/gh2526/GH2526IT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Copyright 2011-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.neo4j.integration.issues.gh2526; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
import static org.assertj.core.api.InstanceOfAssertFactories.*; | ||
|
||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.neo4j.driver.Driver; | ||
import org.neo4j.driver.Session; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.neo4j.config.AbstractNeo4jConfig; | ||
import org.springframework.data.neo4j.core.DatabaseSelectionProvider; | ||
import org.springframework.data.neo4j.core.transaction.Neo4jBookmarkManager; | ||
import org.springframework.data.neo4j.core.transaction.Neo4jTransactionManager; | ||
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; | ||
import org.springframework.data.neo4j.test.BookmarkCapture; | ||
import org.springframework.data.neo4j.test.Neo4jExtension; | ||
import org.springframework.data.neo4j.test.Neo4jIntegrationTest; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
@Neo4jIntegrationTest | ||
public class GH2526IT { | ||
|
||
protected static Neo4jExtension.Neo4jConnectionSupport neo4jConnectionSupport; | ||
|
||
@BeforeEach | ||
void setupData(@Autowired Driver driver, @Autowired BookmarkCapture bookmarkCapture) { | ||
|
||
try (Session session = driver.session()) { | ||
session.run("MATCH (n) DETACH DELETE n").consume(); | ||
session.run("CREATE (o1:Measurand {measurandId: 'o1'})" | ||
+ "CREATE (acc1:AccountingMeasurementMeta:BaseNodeEntity {nodeId: 'acc1'})" | ||
+ "CREATE (o1)-[:IS_MEASURED_BY{ manual: true }]->(acc1)").consume(); | ||
bookmarkCapture.seedWith(session.lastBookmark()); | ||
} | ||
} | ||
|
||
@Test | ||
// GH-2526 | ||
void testRichRelationWithInheritance(@Autowired BaseNodeRepository repository) { | ||
Projection m = repository.findByNodeId("acc1", Projection.class); | ||
assertThat(m).isNotNull(); | ||
assertThat(m).extracting(Projection::getDataPoints, collection(DataPoint.class)) | ||
.extracting(DataPoint::isManual, DataPoint::getMeasurand).contains(tuple(true, new Measurand("o1"))); | ||
} | ||
|
||
interface Projection { | ||
String getNodeId(); | ||
|
||
Set<DataPoint> getDataPoints(); | ||
} | ||
|
||
@Configuration | ||
@EnableTransactionManagement | ||
@EnableNeo4jRepositories | ||
static class Config extends AbstractNeo4jConfig { | ||
|
||
@Bean | ||
public BookmarkCapture bookmarkCapture() { | ||
return new BookmarkCapture(); | ||
} | ||
|
||
@Override | ||
public PlatformTransactionManager transactionManager(Driver driver, | ||
DatabaseSelectionProvider databaseNameProvider) { | ||
|
||
BookmarkCapture bookmarkCapture = bookmarkCapture(); | ||
return new Neo4jTransactionManager(driver, databaseNameProvider, Neo4jBookmarkManager.create(bookmarkCapture)); | ||
} | ||
|
||
@Bean | ||
public Driver driver() { | ||
|
||
return neo4jConnectionSupport.getDriver(); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/org/springframework/data/neo4j/integration/issues/gh2526/Measurand.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2011-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.neo4j.integration.issues.gh2526; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Value; | ||
|
||
import org.springframework.data.annotation.Immutable; | ||
import org.springframework.data.neo4j.core.schema.Id; | ||
import org.springframework.data.neo4j.core.schema.Node; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
@Node | ||
@Value | ||
@AllArgsConstructor | ||
@Immutable | ||
public class Measurand { | ||
|
||
@Id String measurandId; | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/org/springframework/data/neo4j/integration/issues/gh2526/MeasurementMeta.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2011-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.springframework.data.neo4j.integration.issues.gh2526; | ||
|
||
import static org.springframework.data.neo4j.core.schema.Relationship.Direction.*; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
import java.util.Set; | ||
|
||
import org.springframework.data.neo4j.core.schema.Relationship; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
@org.springframework.data.neo4j.core.schema.Node | ||
@Data | ||
@Setter(AccessLevel.PRIVATE) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true) | ||
@SuperBuilder(toBuilder = true) | ||
public class MeasurementMeta extends BaseNodeEntity { | ||
|
||
@Relationship(type = "IS_MEASURED_BY", direction = INCOMING) private Set<DataPoint> dataPoints; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This solution does not seem to work consistently. I could detect invocations where
parent.getRelationships()
returns an empty list.@michael-simons / @meistermeier do you have any idea how to get a consistent behavior?
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.
making
source
lazy (Lazy<NodeDescription<?>>
) seems to solve this issue