Skip to content
This repository has been archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
Change Tracker: instance reloading failed on delete of 'Hard Delete' …
Browse files Browse the repository at this point in the history
…entity #76
  • Loading branch information
Gavrilov-Ivan committed Aug 27, 2021
1 parent 924e3b4 commit 10c6817
Show file tree
Hide file tree
Showing 13 changed files with 791 additions and 102 deletions.
352 changes: 260 additions & 92 deletions search/src/main/java/io/jmix/search/listener/EntityTrackingListener.java

Large diffs are not rendered by default.

324 changes: 324 additions & 0 deletions search/src/test/java/change_tracking/EntityChangeTrackingTest.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ public DataSource dataSource() {
dataSource.setUrl("jdbc:hsqldb:mem:testdb");
dataSource.setUsername("sa");
dataSource.setPassword("");
dataSource.addConnectionProperty("hsqldb.tx", "mvcc");
return dataSource;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ public TestRootEntityWrapper setOneToManyAssociation(List<TestReferenceEntity> r
affectedInstances.addAll(references);
return this;
}

public TestRootEntityWrapper setManyToManyAssociation(TestReferenceEntity... references) {
return setManyToManyAssociation(Arrays.asList(references));
}

public TestRootEntityWrapper setManyToManyAssociation(List<TestReferenceEntity> references) {
this.instance.setManyToManyAssociation(references);
this.affectedInstances.addAll(references);
return this;
}
}

public class TestReferenceEntityWrapper extends AbstractEntityWrapper<TestReferenceEntity> {
Expand Down Expand Up @@ -239,6 +249,16 @@ public TestReferenceEntityWrapper setOneToManyAssociation(List<TestSubReferenceE
affectedInstances.addAll(references);
return this;
}

public TestReferenceEntityWrapper setManyToManyAssociation(TestSubReferenceEntity... references) {
return setManyToManyAssociation(Arrays.asList(references));
}

public TestReferenceEntityWrapper setManyToManyAssociation(List<TestSubReferenceEntity> references) {
this.instance.setManyToManyAssociation(references);
this.affectedInstances.addAll(references);
return this;
}
}

public class TestSubReferenceEntityWrapper extends AbstractEntityWrapper<TestSubReferenceEntity> {
Expand Down Expand Up @@ -334,6 +354,16 @@ public TestRootEntityHDWrapper setOneToManyAssociation(List<TestReferenceEntityH
affectedInstances.addAll(references);
return this;
}

public TestRootEntityHDWrapper setManyToManyAssociation(TestReferenceEntityHD... references) {
return setManyToManyAssociation(Arrays.asList(references));
}

public TestRootEntityHDWrapper setManyToManyAssociation(List<TestReferenceEntityHD> references) {
this.instance.setManyToManyAssociation(references);
this.affectedInstances.addAll(references);
return this;
}
}

public class TestReferenceEntityHDWrapper extends AbstractEntityWrapper<TestReferenceEntityHD> {
Expand Down Expand Up @@ -392,6 +422,16 @@ public TestReferenceEntityHDWrapper setOneToManyAssociation(List<TestSubReferenc
affectedInstances.addAll(references);
return this;
}

public TestReferenceEntityHDWrapper setManyToManyAssociation(TestSubReferenceEntityHD... references) {
return setManyToManyAssociation(Arrays.asList(references));
}

public TestReferenceEntityHDWrapper setManyToManyAssociation(List<TestSubReferenceEntityHD> references) {
this.instance.setManyToManyAssociation(references);
this.affectedInstances.addAll(references);
return this;
}
}

public class TestSubReferenceEntityHDWrapper extends AbstractEntityWrapper<TestSubReferenceEntityHD> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public interface TestRootEntityHDIndexDefinition {
"oneToOneAssociation.textValue",
"oneToOneAssociation.oneToOneAssociation.textValue",
"oneToManyAssociation.textValue",
"oneToManyAssociation.oneToManyAssociation.textValue"})
"oneToManyAssociation.oneToManyAssociation.textValue",
"manyToManyAssociation.textValue",
"manyToManyAssociation.manyToManyAssociation.textValue"
})
void mapping();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public interface TestRootEntityIndexDefinition {
"oneToOneAssociation.textValue",
"oneToOneAssociation.oneToOneAssociation.textValue",
"oneToManyAssociation.textValue",
"oneToManyAssociation.oneToManyAssociation.textValue"})
"oneToManyAssociation.oneToManyAssociation.textValue",
"manyToManyAssociation.textValue",
"manyToManyAssociation.manyToManyAssociation.textValue"
})
void mapping();
}
16 changes: 16 additions & 0 deletions search/src/test/java/test_support/entity/TestReferenceEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ public class TestReferenceEntity extends BaseEntity {
@OneToMany(mappedBy = "testReferenceEntityManyToOne")
private List<TestSubReferenceEntity> oneToManyAssociation;

@OnDeleteInverse(DeletePolicy.UNLINK)
@OnDelete(DeletePolicy.UNLINK)
@JoinTable(name = "TEST_REF_E_SREF_E_LINK",
joinColumns = @JoinColumn(name = "TEST_REFERENCE_ENTITY_ID"),
inverseJoinColumns = @JoinColumn(name = "TEST_SUB_REFERENCE_ENTITY_ID"))
@ManyToMany
private List<TestSubReferenceEntity> manyToManyAssociation;

public List<TestSubReferenceEntity> getManyToManyAssociation() {
return manyToManyAssociation;
}

public void setManyToManyAssociation(List<TestSubReferenceEntity> manyToManyAssociation) {
this.manyToManyAssociation = manyToManyAssociation;
}

public List<TestSubReferenceEntity> getOneToManyAssociation() {
return oneToManyAssociation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ public class TestReferenceEntityHD extends BaseEntityHD {
@OneToMany(mappedBy = "testReferenceEntityManyToOne")
private List<TestSubReferenceEntityHD> oneToManyAssociation;

@JoinTable(name = "TEST_REF_E_SREF_E_HD_LINK",
joinColumns = @JoinColumn(name = "TEST_REF_ENTITY_HD_ID"),
inverseJoinColumns = @JoinColumn(name = "TEST_SUB_REF_ENTITY_HD_ID"))
@ManyToMany
private List<TestSubReferenceEntityHD> manyToManyAssociation;

public List<TestSubReferenceEntityHD> getManyToManyAssociation() {
return manyToManyAssociation;
}

public void setManyToManyAssociation(List<TestSubReferenceEntityHD> manyToManyAssociation) {
this.manyToManyAssociation = manyToManyAssociation;
}

public List<TestSubReferenceEntityHD> getOneToManyAssociation() {
return oneToManyAssociation;
}
Expand Down
16 changes: 16 additions & 0 deletions search/src/test/java/test_support/entity/TestRootEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ public class TestRootEntity extends BaseEntity {
@OneToMany(mappedBy = "testRootEntityManyToOne")
private List<TestReferenceEntity> oneToManyAssociation;

@OnDeleteInverse(DeletePolicy.UNLINK)
@OnDelete(DeletePolicy.UNLINK)
@JoinTable(name = "TEST_ROOT_ENT_REF_ENT_LINK",
joinColumns = @JoinColumn(name = "TEST_ROOT_ENTITY_ID"),
inverseJoinColumns = @JoinColumn(name = "TEST_REFERENCE_ENTITY_ID"))
@ManyToMany
private List<TestReferenceEntity> manyToManyAssociation;

public List<TestReferenceEntity> getManyToManyAssociation() {
return manyToManyAssociation;
}

public void setManyToManyAssociation(List<TestReferenceEntity> manyToManyAssociation) {
this.manyToManyAssociation = manyToManyAssociation;
}

public List<TestReferenceEntity> getOneToManyAssociation() {
return oneToManyAssociation;
}
Expand Down
14 changes: 14 additions & 0 deletions search/src/test/java/test_support/entity/TestRootEntityHD.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ public class TestRootEntityHD extends BaseEntityHD {
@OneToMany(mappedBy = "testRootEntityManyToOne")
private List<TestReferenceEntityHD> oneToManyAssociation;

@JoinTable(name = "TEST_ROOT_ENT_REF_ENT_HD_LINK",
joinColumns = @JoinColumn(name = "TEST_ROOT_ENTITY_HD_ID"),
inverseJoinColumns = @JoinColumn(name = "TEST_REFERENCE_ENTITY_HD_ID"))
@ManyToMany
private List<TestReferenceEntityHD> manyToManyAssociation;

public List<TestReferenceEntityHD> getManyToManyAssociation() {
return manyToManyAssociation;
}

public void setManyToManyAssociation(List<TestReferenceEntityHD> manyToManyAssociation) {
this.manyToManyAssociation = manyToManyAssociation;
}

public List<TestReferenceEntityHD> getOneToManyAssociation() {
return oneToManyAssociation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@
"type": "text"
}
}
}
},
"manyToManyAssociation": {
"properties": {
"_instance_name": {
"type": "text"
}
}
}
}
},
"name": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,68 @@
</createTable>
</changeSet>
<changeSet id="4" author="test">
<createTable tableName="TEST_ROOT_ENT_REF_ENT_HD_LINK">
<column name="TEST_REFERENCE_ENTITY_HD_ID" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_TEST_ROOT_REF_ENT_HD_LINK"/>
</column>
<column name="TEST_ROOT_ENTITY_HD_ID" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_TEST_ROOT_REF_ENT_HD_LINK"/>
</column>
</createTable>
</changeSet>
<changeSet id="5" author="test">
<createTable tableName="TEST_REF_E_SREF_E_HD_LINK">
<column name="TEST_REF_ENTITY_HD_ID" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_TEST_REF_E_SREF_E_HD_LINK"/>
</column>
<column name="TEST_SUB_REF_ENTITY_HD_ID" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_TEST_REF_E_SREF_E_HD_LINK"/>
</column>
</createTable>
</changeSet>
<changeSet id="6" author="test">
<addForeignKeyConstraint baseColumnNames="ONE_TO_ONE_ASSOCIATION_ID" baseTableName="TEST_REFERENCE_ENTITY_HD"
constraintName="FK_TESTREFENHD_ON_ONETOONEASS" onDelete="SET NULL"
referencedColumnNames="ID" referencedTableName="TEST_SUB_REFERENCE_ENTITY_HD"/>
</changeSet>
<changeSet id="5" author="test">
<changeSet id="7" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_ROOT_ENTITY_M_TO_O_ID" baseTableName="TEST_REFERENCE_ENTITY_HD"
constraintName="FK_TESTREFENHD_ON_TESTROOTENHD" referencedColumnNames="ID"
referencedTableName="TEST_ROOT_ENTITY_HD"/>
</changeSet>
<changeSet id="6" author="test">
<changeSet id="8" author="test">
<addForeignKeyConstraint baseColumnNames="ONE_TO_ONE_ASSOCIATION_ID" baseTableName="TEST_ROOT_ENTITY_HD"
constraintName="FK_TESTROOTENHD_ON_ONETOONEASS" onDelete="SET NULL"
referencedColumnNames="ID" referencedTableName="TEST_REFERENCE_ENTITY_HD"/>
</changeSet>
<changeSet id="7" author="test">
<changeSet id="9" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_REF_ENTITY_M_TO_O_ID" baseTableName="TEST_SUB_REFERENCE_ENTITY_HD"
constraintName="FK_TESTSREFENHD_ON_TESTREFENHD" referencedColumnNames="ID"
referencedTableName="TEST_REFERENCE_ENTITY_HD"/>
</changeSet>
<changeSet id="10" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_REFERENCE_ENTITY_HD_ID"
baseTableName="TEST_ROOT_ENT_REF_ENT_HD_LINK"
constraintName="FK_ROOT_REF_LINK_ON_REFENTHD" referencedColumnNames="ID"
onDelete="CASCADE"
referencedTableName="TEST_REFERENCE_ENTITY_HD"/>
</changeSet>
<changeSet id="11" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_ROOT_ENTITY_HD_ID" baseTableName="TEST_ROOT_ENT_REF_ENT_HD_LINK"
constraintName="FK_ROOT_REF_LINK_ON_ROOTENTHD" referencedColumnNames="ID"
onDelete="CASCADE"
referencedTableName="TEST_ROOT_ENTITY_HD"/>
</changeSet>
<changeSet id="12" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_REF_ENTITY_HD_ID" baseTableName="TEST_REF_E_SREF_E_HD_LINK"
constraintName="FK_REF_SREF_LINK_ON_REFENTHD" referencedColumnNames="ID"
onDelete="CASCADE"
referencedTableName="TEST_REFERENCE_ENTITY_HD"/>
</changeSet>
<changeSet id="13" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_SUB_REF_ENTITY_HD_ID" baseTableName="TEST_REF_E_SREF_E_HD_LINK"
constraintName="FK_REF_SREF_LINK_ON_SREFENTHD" referencedColumnNames="ID"
onDelete="CASCADE"
referencedTableName="TEST_SUB_REFERENCE_ENTITY_HD"/>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,63 @@
</createTable>
</changeSet>
<changeSet id="4" author="test">
<createTable tableName="TEST_ROOT_ENT_REF_ENT_LINK">
<column name="TEST_REFERENCE_ENTITY_ID" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_TEST_ROOT_REF_ENT_LINK"/>
</column>
<column name="TEST_ROOT_ENTITY_ID" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_TEST_ROOT_REF_ENT_LINK"/>
</column>
</createTable>
</changeSet>
<changeSet id="5" author="test">
<createTable tableName="TEST_REF_E_SREF_E_LINK">
<column name="TEST_REFERENCE_ENTITY_ID" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_TEST_REF_E_SREF_E_LINK"/>
</column>
<column name="TEST_SUB_REFERENCE_ENTITY_ID" type="UUID">
<constraints nullable="false" primaryKey="true" primaryKeyName="PK_TEST_REF_E_SREF_E_LINK"/>
</column>
</createTable>
</changeSet>
<changeSet id="6" author="test">
<addForeignKeyConstraint baseColumnNames="ONE_TO_ONE_ASSOCIATION_ID" baseTableName="TEST_REFERENCE_ENTITY"
constraintName="FK_TESTREFEREN_ON_ONETOONEASS" referencedColumnNames="ID"
referencedTableName="TEST_SUB_REFERENCE_ENTITY"/>
</changeSet>
<changeSet id="5" author="test">
<changeSet id="7" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_ROOT_ENTITY_M_TO_O_ID" baseTableName="TEST_REFERENCE_ENTITY"
constraintName="FK_TESTREFEREN_ON_TESTROOTENT" referencedColumnNames="ID"
referencedTableName="TEST_ROOT_ENTITY"/>
</changeSet>
<changeSet id="6" author="test">
<changeSet id="8" author="test">
<addForeignKeyConstraint baseColumnNames="ONE_TO_ONE_ASSOCIATION_ID" baseTableName="TEST_ROOT_ENTITY"
constraintName="FK_TESTROOTENT_ON_ONETOONEASS" referencedColumnNames="ID"
referencedTableName="TEST_REFERENCE_ENTITY"/>
</changeSet>
<changeSet id="7" author="test">
<changeSet id="9" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_REF_ENTITY_M_TO_O_ID" baseTableName="TEST_SUB_REFERENCE_ENTITY"
constraintName="FK_TESTSUBREFE_ON_TESTREFENTI" referencedColumnNames="ID"
referencedTableName="TEST_REFERENCE_ENTITY"/>
</changeSet>
<changeSet id="10" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_REFERENCE_ENTITY_ID" baseTableName="TEST_ROOT_ENT_REF_ENT_LINK"
constraintName="FK_ROOT_REF_LINK_ON_REFENT" referencedColumnNames="ID"
referencedTableName="TEST_REFERENCE_ENTITY"/>
</changeSet>
<changeSet id="11" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_ROOT_ENTITY_ID" baseTableName="TEST_ROOT_ENT_REF_ENT_LINK"
constraintName="FK_ROOT_REF_LINK_ON_ROOTENT" referencedColumnNames="ID"
referencedTableName="TEST_ROOT_ENTITY"/>
</changeSet>
<changeSet id="12" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_REFERENCE_ENTITY_ID" baseTableName="TEST_REF_E_SREF_E_LINK"
constraintName="FK_REF_SREF_LINK_ON_REFENT" referencedColumnNames="ID"
referencedTableName="TEST_REFERENCE_ENTITY"/>
</changeSet>
<changeSet id="13" author="test">
<addForeignKeyConstraint baseColumnNames="TEST_SUB_REFERENCE_ENTITY_ID" baseTableName="TEST_REF_E_SREF_E_LINK"
constraintName="FK_REF_SREF_LINK_ON_SREFENT" referencedColumnNames="ID"
referencedTableName="TEST_SUB_REFERENCE_ENTITY"/>
</changeSet>
</databaseChangeLog>

0 comments on commit 10c6817

Please sign in to comment.