|
|
|
@ -17,6 +17,9 @@ package org.springframework.data.relational.core.conversion; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import lombok.Data; |
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.HashSet; |
|
|
|
import java.util.HashSet; |
|
|
|
@ -43,9 +46,6 @@ import org.springframework.data.relational.core.mapping.RelationalMappingContext |
|
|
|
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; |
|
|
|
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
|
|
|
|
|
|
|
|
import lombok.Data; |
|
|
|
|
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Unit tests for the {@link RelationalEntityWriter} |
|
|
|
* Unit tests for the {@link RelationalEntityWriter} |
|
|
|
* |
|
|
|
* |
|
|
|
@ -97,7 +97,8 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(InsertRoot.class, SingleReferenceEntity.class, "", SingleReferenceEntity.class, false, IdValueSource.GENERATED) //
|
|
|
|
tuple(InsertRoot.class, SingleReferenceEntity.class, "", SingleReferenceEntity.class, false, |
|
|
|
|
|
|
|
IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -118,7 +119,8 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(InsertRoot.class, PrimitiveLongIdEntity.class, "", PrimitiveLongIdEntity.class, false, IdValueSource.GENERATED) //
|
|
|
|
tuple(InsertRoot.class, PrimitiveLongIdEntity.class, "", PrimitiveLongIdEntity.class, false, |
|
|
|
|
|
|
|
IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -139,7 +141,8 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(InsertRoot.class, PrimitiveIntIdEntity.class, "", PrimitiveIntIdEntity.class, false, IdValueSource.GENERATED) //
|
|
|
|
tuple(InsertRoot.class, PrimitiveIntIdEntity.class, "", PrimitiveIntIdEntity.class, false, |
|
|
|
|
|
|
|
IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -162,7 +165,8 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(InsertRoot.class, EmbeddedReferenceEntity.class, "", EmbeddedReferenceEntity.class, false, IdValueSource.GENERATED) //
|
|
|
|
tuple(InsertRoot.class, EmbeddedReferenceEntity.class, "", EmbeddedReferenceEntity.class, false, |
|
|
|
|
|
|
|
IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -185,7 +189,8 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(InsertRoot.class, SingleReferenceEntity.class, "", SingleReferenceEntity.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertRoot.class, SingleReferenceEntity.class, "", SingleReferenceEntity.class, false, |
|
|
|
|
|
|
|
IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "other", Element.class, true, IdValueSource.GENERATED) //
|
|
|
|
tuple(Insert.class, Element.class, "other", Element.class, true, IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -210,9 +215,12 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactlyInAnyOrder( //
|
|
|
|
.containsExactlyInAnyOrder( //
|
|
|
|
tuple(InsertRoot.class, EntityWithReferencesToPrimitiveIdEntity.class, "", EntityWithReferencesToPrimitiveIdEntity.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertRoot.class, EntityWithReferencesToPrimitiveIdEntity.class, "", |
|
|
|
tuple(Insert.class, PrimitiveLongIdEntity.class, "primitiveLongIdEntity", PrimitiveLongIdEntity.class, true, IdValueSource.GENERATED), //
|
|
|
|
EntityWithReferencesToPrimitiveIdEntity.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, PrimitiveIntIdEntity.class, "primitiveIntIdEntity", PrimitiveIntIdEntity.class, true, IdValueSource.GENERATED) //
|
|
|
|
tuple(Insert.class, PrimitiveLongIdEntity.class, "primitiveLongIdEntity", PrimitiveLongIdEntity.class, true, |
|
|
|
|
|
|
|
IdValueSource.GENERATED), //
|
|
|
|
|
|
|
|
tuple(Insert.class, PrimitiveIntIdEntity.class, "primitiveIntIdEntity", PrimitiveIntIdEntity.class, true, |
|
|
|
|
|
|
|
IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -307,11 +315,11 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
); |
|
|
|
); |
|
|
|
List<Insert<Element>> batchedInsertActions = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
List<Insert<Element>> batchedInsertActions = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
assertThat(batchedInsertActions).extracting(DbAction::getClass, //
|
|
|
|
assertThat(batchedInsertActions).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(Insert.class, Element.class, "elements", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "elements", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "elements", Element.class, true, IdValueSource.GENERATED) //
|
|
|
|
tuple(Insert.class, Element.class, "elements", Element.class, true, IdValueSource.GENERATED) //
|
|
|
|
@ -346,17 +354,19 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(InsertRoot.class, CascadingReferenceEntity.class, "", CascadingReferenceEntity.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertRoot.class, CascadingReferenceEntity.class, "", CascadingReferenceEntity.class, false, |
|
|
|
|
|
|
|
IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertBatch.class, CascadingReferenceMiddleElement.class, "", null, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertBatch.class, CascadingReferenceMiddleElement.class, "", null, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertBatch.class, Element.class, "", null, false, IdValueSource.GENERATED) //
|
|
|
|
tuple(InsertBatch.class, Element.class, "", null, false, IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
List<Insert<CascadingReferenceMiddleElement>> middleElementInserts = getInsertBatchAction(actions, CascadingReferenceMiddleElement.class).getInserts(); |
|
|
|
List<Insert<CascadingReferenceMiddleElement>> middleElementInserts = getInsertBatchAction(actions, |
|
|
|
|
|
|
|
CascadingReferenceMiddleElement.class).getInserts(); |
|
|
|
assertThat(middleElementInserts).extracting(DbAction::getClass, //
|
|
|
|
assertThat(middleElementInserts).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(Insert.class, CascadingReferenceMiddleElement.class, "other", CascadingReferenceMiddleElement.class, |
|
|
|
tuple(Insert.class, CascadingReferenceMiddleElement.class, "other", CascadingReferenceMiddleElement.class, |
|
|
|
true, IdValueSource.GENERATED), //
|
|
|
|
true, IdValueSource.GENERATED), //
|
|
|
|
@ -365,11 +375,11 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
); |
|
|
|
); |
|
|
|
List<Insert<Element>> leafElementInserts = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
List<Insert<Element>> leafElementInserts = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
assertThat(leafElementInserts).extracting(DbAction::getClass, //
|
|
|
|
assertThat(leafElementInserts).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(Insert.class, Element.class, "other.element", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "other.element", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "other.element", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "other.element", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
@ -415,11 +425,11 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
List<Insert<CascadingReferenceMiddleElement>> middleElementInserts = getInsertBatchAction(actions, |
|
|
|
List<Insert<CascadingReferenceMiddleElement>> middleElementInserts = getInsertBatchAction(actions, |
|
|
|
CascadingReferenceMiddleElement.class).getInserts(); |
|
|
|
CascadingReferenceMiddleElement.class).getInserts(); |
|
|
|
assertThat(middleElementInserts).extracting(DbAction::getClass, //
|
|
|
|
assertThat(middleElementInserts).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(Insert.class, CascadingReferenceMiddleElement.class, "other", CascadingReferenceMiddleElement.class, |
|
|
|
tuple(Insert.class, CascadingReferenceMiddleElement.class, "other", CascadingReferenceMiddleElement.class, |
|
|
|
true, IdValueSource.GENERATED), //
|
|
|
|
true, IdValueSource.GENERATED), //
|
|
|
|
@ -428,11 +438,11 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
); |
|
|
|
); |
|
|
|
List<Insert<Element>> elementInserts = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
List<Insert<Element>> elementInserts = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
assertThat(elementInserts).extracting(DbAction::getClass, //
|
|
|
|
assertThat(elementInserts).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(Insert.class, Element.class, "other.element", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "other.element", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "other.element", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "other.element", Element.class, true, IdValueSource.GENERATED), //
|
|
|
|
@ -481,10 +491,10 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
); |
|
|
|
); |
|
|
|
List<Insert<Element>> inserts = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
List<Insert<Element>> inserts = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
assertThat(inserts).extracting(DbAction::getClass, //
|
|
|
|
assertThat(inserts).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
this::getMapKey, //
|
|
|
|
this::getMapKey, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactlyInAnyOrder( //
|
|
|
|
.containsExactlyInAnyOrder( //
|
|
|
|
tuple(Insert.class, Element.class, "one", "elements", IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "one", "elements", IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "two", "elements", IdValueSource.GENERATED) //
|
|
|
|
tuple(Insert.class, Element.class, "two", "elements", IdValueSource.GENERATED) //
|
|
|
|
@ -525,10 +535,10 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
); |
|
|
|
); |
|
|
|
List<Insert<Element>> inserts = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
List<Insert<Element>> inserts = getInsertBatchAction(actions, Element.class).getInserts(); |
|
|
|
assertThat(inserts).extracting(DbAction::getClass, //
|
|
|
|
assertThat(inserts).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
this::getMapKey, //
|
|
|
|
this::getMapKey, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactlyInAnyOrder( //
|
|
|
|
.containsExactlyInAnyOrder( //
|
|
|
|
tuple(Insert.class, Element.class, "1", "elements", IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "1", "elements", IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "2", "elements", IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, "2", "elements", IdValueSource.GENERATED), //
|
|
|
|
@ -718,7 +728,8 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(InsertRoot.class, EmbeddedReferenceChainEntity.class, "", EmbeddedReferenceChainEntity.class, false, IdValueSource.GENERATED) //
|
|
|
|
tuple(InsertRoot.class, EmbeddedReferenceChainEntity.class, "", EmbeddedReferenceChainEntity.class, false, |
|
|
|
|
|
|
|
IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -764,35 +775,34 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
List<DbAction<?>> actions = extractActions(aggregateChange); |
|
|
|
List<DbAction<?>> actions = extractActions(aggregateChange); |
|
|
|
assertThat(actions).extracting(DbAction::getClass, //
|
|
|
|
assertThat(actions).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsSubsequence( |
|
|
|
.containsSubsequence( |
|
|
|
tuple(InsertRoot.class, ListContainer.class, "", ListContainer.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertRoot.class, ListContainer.class, "", ListContainer.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertBatch.class, Element.class, "", null, false, IdValueSource.PROVIDED) //
|
|
|
|
tuple(InsertBatch.class, Element.class, "", null, false, IdValueSource.PROVIDED) //
|
|
|
|
) |
|
|
|
).containsSubsequence( //
|
|
|
|
.containsSubsequence( //
|
|
|
|
|
|
|
|
tuple(InsertRoot.class, ListContainer.class, "", ListContainer.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertRoot.class, ListContainer.class, "", ListContainer.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertBatch.class, Element.class, "", null, false, IdValueSource.GENERATED) //
|
|
|
|
tuple(InsertBatch.class, Element.class, "", null, false, IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
InsertBatch<Element> insertBatchWithoutId = getInsertBatchAction(actions, Element.class, IdValueSource.GENERATED); |
|
|
|
InsertBatch<Element> insertBatchWithoutId = getInsertBatchAction(actions, Element.class, IdValueSource.GENERATED); |
|
|
|
assertThat(insertBatchWithoutId.getInserts()).extracting(DbAction::getClass, //
|
|
|
|
assertThat(insertBatchWithoutId.getInserts()).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
this::getListKey, //
|
|
|
|
this::getListKey, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(Insert.class, Element.class, 0, "elements", IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, 0, "elements", IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, Element.class, 2, "elements", IdValueSource.GENERATED) //
|
|
|
|
tuple(Insert.class, Element.class, 2, "elements", IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
InsertBatch<Element> insertBatchWithId = getInsertBatchAction(actions, Element.class, IdValueSource.PROVIDED); |
|
|
|
InsertBatch<Element> insertBatchWithId = getInsertBatchAction(actions, Element.class, IdValueSource.PROVIDED); |
|
|
|
assertThat(insertBatchWithId.getInserts()).extracting(DbAction::getClass, //
|
|
|
|
assertThat(insertBatchWithId.getInserts()).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
this::getListKey, //
|
|
|
|
this::getListKey, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactly( //
|
|
|
|
.containsExactly( //
|
|
|
|
tuple(Insert.class, Element.class, 1, "elements", IdValueSource.PROVIDED), //
|
|
|
|
tuple(Insert.class, Element.class, 1, "elements", IdValueSource.PROVIDED), //
|
|
|
|
tuple(Insert.class, Element.class, 3, "elements", IdValueSource.PROVIDED) //
|
|
|
|
tuple(Insert.class, Element.class, 3, "elements", IdValueSource.PROVIDED) //
|
|
|
|
@ -813,15 +823,18 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
List<DbAction<?>> actions = extractActions(aggregateChange); |
|
|
|
List<DbAction<?>> actions = extractActions(aggregateChange); |
|
|
|
assertThat(actions).extracting(DbAction::getClass, //
|
|
|
|
assertThat(actions).extracting(DbAction::getClass, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbAction::getEntityType, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::extractPath, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::actualEntityType, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::isWithDependsOn, //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
DbActionTestSupport::insertIdValueSource) //
|
|
|
|
.containsExactlyInAnyOrder( //
|
|
|
|
.containsExactlyInAnyOrder( //
|
|
|
|
tuple(InsertRoot.class, EntityWithReferencesToPrimitiveIdEntity.class, "", EntityWithReferencesToPrimitiveIdEntity.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(InsertRoot.class, EntityWithReferencesToPrimitiveIdEntity.class, "", |
|
|
|
tuple(Insert.class, PrimitiveLongIdEntity.class, "primitiveLongIdEntities", PrimitiveLongIdEntity.class, true, IdValueSource.GENERATED), //
|
|
|
|
EntityWithReferencesToPrimitiveIdEntity.class, false, IdValueSource.GENERATED), //
|
|
|
|
tuple(Insert.class, PrimitiveIntIdEntity.class, "primitiveIntIdEntities", PrimitiveIntIdEntity.class, true, IdValueSource.GENERATED) //
|
|
|
|
tuple(Insert.class, PrimitiveLongIdEntity.class, "primitiveLongIdEntities", PrimitiveLongIdEntity.class, |
|
|
|
|
|
|
|
true, IdValueSource.GENERATED), //
|
|
|
|
|
|
|
|
tuple(Insert.class, PrimitiveIntIdEntity.class, "primitiveIntIdEntities", PrimitiveIntIdEntity.class, true, |
|
|
|
|
|
|
|
IdValueSource.GENERATED) //
|
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -834,28 +847,25 @@ public class RelationalEntityWriterUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
@NotNull |
|
|
|
@NotNull |
|
|
|
private <T> InsertBatch<T> getInsertBatchAction(List<DbAction<?>> actions, Class<T> entityType) { |
|
|
|
private <T> InsertBatch<T> getInsertBatchAction(List<DbAction<?>> actions, Class<T> entityType) { |
|
|
|
return getInsertBatchActions(actions, entityType).stream() |
|
|
|
return getInsertBatchActions(actions, entityType).stream().findFirst() |
|
|
|
.findFirst() |
|
|
|
|
|
|
|
.orElseThrow(() -> new RuntimeException("No InsertBatch action found!")); |
|
|
|
.orElseThrow(() -> new RuntimeException("No InsertBatch action found!")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NotNull |
|
|
|
@NotNull |
|
|
|
private <T> InsertBatch<T> getInsertBatchAction(List<DbAction<?>> actions, Class<T> entityType, |
|
|
|
private <T> InsertBatch<T> getInsertBatchAction(List<DbAction<?>> actions, Class<T> entityType, |
|
|
|
IdValueSource idValueSource) { |
|
|
|
IdValueSource idValueSource) { |
|
|
|
return getInsertBatchActions(actions, entityType).stream() |
|
|
|
return getInsertBatchActions(actions, entityType).stream() |
|
|
|
.filter(insertBatch -> insertBatch.getIdValueSource() == idValueSource) |
|
|
|
.filter(insertBatch -> insertBatch.getIdValueSource() == idValueSource).findFirst().orElseThrow( |
|
|
|
.findFirst() |
|
|
|
() -> new RuntimeException(String.format("No InsertBatch with includeId '%s' found!", idValueSource))); |
|
|
|
.orElseThrow(() -> new RuntimeException(String.format("No InsertBatch with includeId '%s' found!", idValueSource))); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@NotNull |
|
|
|
@NotNull |
|
|
|
private <T> List<InsertBatch<T>> getInsertBatchActions(List<DbAction<?>> actions, Class<T> entityType) { |
|
|
|
private <T> List<InsertBatch<T>> getInsertBatchActions(List<DbAction<?>> actions, Class<T> entityType) { |
|
|
|
//noinspection unchecked
|
|
|
|
// noinspection unchecked
|
|
|
|
return actions.stream() //
|
|
|
|
return actions.stream() //
|
|
|
|
.filter(dbAction -> dbAction instanceof InsertBatch) //
|
|
|
|
.filter(dbAction -> dbAction instanceof InsertBatch) //
|
|
|
|
.filter(dbAction -> dbAction.getEntityType().equals(entityType)) //
|
|
|
|
.filter(dbAction -> dbAction.getEntityType().equals(entityType)) //
|
|
|
|
.map(dbAction -> (InsertBatch<T>) dbAction) |
|
|
|
.map(dbAction -> (InsertBatch<T>) dbAction).collect(Collectors.toList()); |
|
|
|
.collect(Collectors.toList()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private CascadingReferenceMiddleElement createMiddleElement(Element first, Element second) { |
|
|
|
private CascadingReferenceMiddleElement createMiddleElement(Element first, Element second) { |
|
|
|
|