-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GH-576 - Fix deletion of relationship with the same type between the …
…same nodes. Co-authored-by: Michael Simons <michael.simons@neo4j.com>
- Loading branch information
1 parent
bd59df5
commit 18c4f90
Showing
7 changed files
with
293 additions
and
47 deletions.
There are no files selected for viewing
This file contains 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
98 changes: 98 additions & 0 deletions
98
test/src/test/java/org/neo4j/ogm/cypher/compiler/CypherContextTest.java
This file contains 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,98 @@ | ||
/* | ||
* Copyright (c) 2002-2019 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product may include a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of the source | ||
* code for these subcomponents is subject to the terms and | ||
* conditions of the subcomponent's license, as noted in the LICENSE file. | ||
*/ | ||
package org.neo4j.ogm.cypher.compiler; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.function.Predicate; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.neo4j.ogm.cypher.ComparisonOperator; | ||
import org.neo4j.ogm.cypher.Filter; | ||
import org.neo4j.ogm.domain.gh576.DataItem; | ||
import org.neo4j.ogm.domain.gh576.FormulaItem; | ||
import org.neo4j.ogm.domain.gh576.Variable; | ||
import org.neo4j.ogm.session.Session; | ||
import org.neo4j.ogm.session.SessionFactory; | ||
import org.neo4j.ogm.testutil.MultiDriverTestClass; | ||
import org.neo4j.ogm.testutil.TestUtils; | ||
import org.neo4j.test.rule.RepeatRule; | ||
|
||
/** | ||
* @author Andreas Berger | ||
* @author Michael J. Simons | ||
*/ | ||
public class CypherContextTest extends MultiDriverTestClass { | ||
|
||
@Rule | ||
public RepeatRule repeatRule = new RepeatRule(false, 10); | ||
|
||
private static SessionFactory sessionFactory; | ||
|
||
private static String createTestDataStatement = TestUtils.readCQLFile("org/neo4j/ogm/cql/nodes.cql").toString(); | ||
|
||
private Session session; | ||
|
||
@BeforeClass | ||
public static void initSesssionFactory() { | ||
sessionFactory = new SessionFactory(driver, "org.neo4j.ogm.domain.gh576"); | ||
} | ||
|
||
@Before | ||
public void init() throws IOException { | ||
session = sessionFactory.openSession(); | ||
session.purgeDatabase(); | ||
session.clear(); | ||
|
||
session.query(createTestDataStatement, Collections.emptyMap()); | ||
} | ||
|
||
@Test // GH-576 | ||
public void shouldDeregisterRelationshipEntities() { | ||
Collection<DataItem> dataItems; | ||
FormulaItem formulaItem; | ||
|
||
Filter filter = new Filter("nodeId", ComparisonOperator.EQUALS, "m1"); | ||
|
||
dataItems = session.loadAll(DataItem.class, filter); | ||
assertThat(dataItems).hasSize(1); | ||
|
||
formulaItem = (FormulaItem) dataItems.iterator().next(); | ||
assertThat(formulaItem.getVariables()).hasSize(3); | ||
|
||
Predicate<Variable> isVariableAWithDataItemM2 = v -> v.getVariable().equals("A") && v.getDataItem().getNodeId() | ||
.equals("m2"); | ||
formulaItem.getVariables().removeIf(isVariableAWithDataItemM2); | ||
assertThat(formulaItem.getVariables()).hasSize(2); | ||
|
||
session.save(formulaItem); | ||
|
||
dataItems = session.loadAll(DataItem.class, filter); | ||
assertThat(dataItems).hasSize(1); | ||
|
||
formulaItem = (FormulaItem) dataItems.iterator().next(); | ||
assertThat(formulaItem.getVariables()).hasSize(2); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
session.purgeDatabase(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
test/src/test/java/org/neo4j/ogm/domain/gh576/BaseEntity.java
This file contains 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,30 @@ | ||
/* | ||
* Copyright (c) 2002-2019 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product may include a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of the source | ||
* code for these subcomponents is subject to the terms and | ||
* conditions of the subcomponent's license, as noted in the LICENSE file. | ||
*/ | ||
package org.neo4j.ogm.domain.gh576; | ||
|
||
import org.neo4j.ogm.annotation.GeneratedValue; | ||
import org.neo4j.ogm.annotation.Id; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
abstract class BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
test/src/test/java/org/neo4j/ogm/domain/gh576/DataItem.java
This file contains 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,39 @@ | ||
/* | ||
* Copyright (c) 2002-2019 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product may include a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of the source | ||
* code for these subcomponents is subject to the terms and | ||
* conditions of the subcomponent's license, as noted in the LICENSE file. | ||
*/ | ||
package org.neo4j.ogm.domain.gh576; | ||
|
||
import java.util.List; | ||
|
||
import org.neo4j.ogm.annotation.NodeEntity; | ||
import org.neo4j.ogm.annotation.Relationship; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
@NodeEntity | ||
public class DataItem extends BaseEntity { | ||
|
||
private String nodeId; | ||
|
||
/* | ||
* This field is here, b/c the neo4j ogm driver optimizes queries against the class given to the query. | ||
* If we want the returned child entities to have its relations mapped as well, we need to tell OGM all | ||
* the fields by adding them here | ||
*/ | ||
@Relationship(type = "USES") | ||
protected List<Variable> variables; | ||
|
||
public String getNodeId() { | ||
return nodeId; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test/src/test/java/org/neo4j/ogm/domain/gh576/FormulaItem.java
This file contains 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,28 @@ | ||
/* | ||
* Copyright (c) 2002-2019 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product may include a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of the source | ||
* code for these subcomponents is subject to the terms and | ||
* conditions of the subcomponent's license, as noted in the LICENSE file. | ||
*/ | ||
package org.neo4j.ogm.domain.gh576; | ||
|
||
import java.util.List; | ||
|
||
import org.neo4j.ogm.annotation.NodeEntity; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
@NodeEntity | ||
public class FormulaItem extends DataItem { | ||
|
||
public List<Variable> getVariables() { | ||
return variables; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
test/src/test/java/org/neo4j/ogm/domain/gh576/Variable.java
This file contains 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,44 @@ | ||
/* | ||
* Copyright (c) 2002-2019 "Neo Technology," | ||
* Network Engine for Objects in Lund AB [http://neotechnology.com] | ||
* | ||
* This product is licensed to you under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this product except in compliance with the License. | ||
* | ||
* This product may include a number of subcomponents with | ||
* separate copyright notices and license terms. Your use of the source | ||
* code for these subcomponents is subject to the terms and | ||
* conditions of the subcomponent's license, as noted in the LICENSE file. | ||
*/ | ||
package org.neo4j.ogm.domain.gh576; | ||
|
||
import org.neo4j.ogm.annotation.EndNode; | ||
import org.neo4j.ogm.annotation.RelationshipEntity; | ||
import org.neo4j.ogm.annotation.StartNode; | ||
|
||
/** | ||
* @author Andreas Berger | ||
*/ | ||
@RelationshipEntity(type = "USES") | ||
public class Variable extends BaseEntity { | ||
|
||
@StartNode | ||
private FormulaItem formulaItem; | ||
|
||
@EndNode | ||
private DataItem dataItem; | ||
|
||
private String variable; | ||
|
||
public FormulaItem getFormulaItem() { | ||
return formulaItem; | ||
} | ||
|
||
public DataItem getDataItem() { | ||
return dataItem; | ||
} | ||
|
||
public String getVariable() { | ||
return variable; | ||
} | ||
} |
Oops, something went wrong.