Commit f4b3a46b authored by Jörg Richter's avatar Jörg Richter

ChildTopics API: remove addDeletionRef() method (2x) (#341)

BREAKING CHANGE

systems.dmx.core.ChildTopics

remove the 2 addDeletionRef() methods:

ChildTopics addDeletionRef(String compDefUri, long refTopicId);
ChildTopics addDeletionRef(String compDefUri, String refTopicUri);

CODE TRANSFORMATION

Instead of

    topic.getChildTopics().addDeletionRef(compDefUri, ...);

write

    topic.update(mf.newChildTopicsModel().addDeletionRef(compDefUri, ...));
parent 1f46730b
Pipeline #9913 passed with stages
in 7 minutes and 59 seconds
......@@ -114,14 +114,4 @@ public interface ChildTopics extends Iterable<String> {
ChildTopics getChildTopics(String compDefUri);
// Note: there are no convenience accessors for a multiple-valued child.
// === Manipulators ===
// --- Multiple-valued Children ---
ChildTopics addDeletionRef(String compDefUri, long refTopicId);
ChildTopics addDeletionRef(String compDefUri, String refTopicUri);
}
......@@ -204,22 +204,6 @@ class ChildTopicsImpl implements ChildTopics {
// === Manipulators ===
// --- Multiple-valued Children ---
@Override
public ChildTopics addDeletionRef(String compDefUri, long refTopicId) {
return _updateMany(compDefUri, mf.newTopicDeletionModel(refTopicId));
}
@Override
public ChildTopics addDeletionRef(String compDefUri, String refTopicUri) {
return _updateMany(compDefUri, mf.newTopicDeletionModel(refTopicUri));
}
// === Iterable Implementation ===
@Override
......@@ -229,28 +213,6 @@ class ChildTopicsImpl implements ChildTopics {
// ------------------------------------------------------------------------------------------------- Private Methods
// Note 1: we need to explicitly declare the arg as RelatedTopicModel. When declared as TopicModel instead the
// JVM would invoke the ChildTopicsModel's set()/add() which takes a TopicModel object even if at runtime a
// RelatedTopicModel or even a TopicReferenceModel is passed. This is because Java method overloading involves
// no dynamic dispatch. See the methodOverloading tests in JavaAPITest.java (in module dmx-test). ### still true?
// Note 2: calling parent.update(..) would not work. The JVM would call the update() method of the base class
// (DMXObjectImpl), not the subclass's update() method. This is related to Java's (missing) multiple
// dispatch. Note that 2 inheritance hierarchies are involved here: the DM object hierarchy and the DM model
// hierarchy. See the missingMultipleDispatch tests in JavaAPITest.java (in module dmx-test). ### still true?
private ChildTopics _updateOne(String compDefUri, RelatedTopicModel newChildTopic) {
parent.update(mf.newChildTopicsModel().set(compDefUri, newChildTopic));
return this;
}
private ChildTopics _updateMany(String compDefUri, RelatedTopicModel newChildTopic) {
parent.update(mf.newChildTopicsModel().add(compDefUri, newChildTopic));
return this;
}
// ---
/**
* Loads the child topics for the given comp def, provided they are not loaded already.
*/
......
......@@ -285,9 +285,7 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
//
// "Comment"
Topic comment = dmx.createTopic(mf.newTopicModel("dmx.test.comment"));
comment.update(mf.newChildTopicsModel().set(
"dmx.test.person_name", mf.newTopicReferenceModel(karl.getId())
));
comment.update(mf.newChildTopicsModel().setRef("dmx.test.person_name", karl.getId()));
//
assertEquals(karl.getId(), comment.getChildTopics().getTopic("dmx.test.person_name").getId());
assertEquals("Karl Albrecht", comment.getSimpleValue().toString());
......@@ -332,9 +330,7 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
//
// "Comment"
Topic comment = dmx.createTopic(mf.newTopicModel("dmx.test.comment"));
comment.update(mf.newChildTopicsModel().set(
"dmx.test.person_name", mf.newTopicReferenceModel(karl.getId())
));
comment.update(mf.newChildTopicsModel().setRef("dmx.test.person_name", karl.getId()));
//
assertEquals(karl.getId(), comment.getChildTopics().getTopic("dmx.test.person_name").getId());
assertEquals("Karl Albrecht", comment.getSimpleValue().toString());
......@@ -509,8 +505,8 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
DMXTransaction tx = dmx.beginTx();
try {
// set Custom Assoc Type (via comp def)
dmx.getTopicType(PLUGIN).getCompDef(PLUGIN_NAME).update(mf.newChildTopicsModel().set(
"dmx.core.assoc_type#dmx.core.custom_assoc_type", mf.newTopicReferenceModel(ASSOCIATION)
dmx.getTopicType(PLUGIN).getCompDef(PLUGIN_NAME).update(mf.newChildTopicsModel().setRef(
"dmx.core.assoc_type#dmx.core.custom_assoc_type", ASSOCIATION
));
//
// get Custom Assoc Type
......@@ -533,8 +529,8 @@ public class CoreServiceTest extends CoreServiceTestEnvironment {
try {
// set Custom Assoc Type (via association)
long compDefId = dmx.getTopicType(PLUGIN).getCompDef(PLUGIN_NAME).getId();
dmx.getAssoc(compDefId).update(mf.newChildTopicsModel().set(
"dmx.core.assoc_type#dmx.core.custom_assoc_type", mf.newTopicReferenceModel(ASSOCIATION)
dmx.getAssoc(compDefId).update(mf.newChildTopicsModel().setRef(
"dmx.core.assoc_type#dmx.core.custom_assoc_type", ASSOCIATION
));
//
// get Custom Assoc Type
......
......@@ -94,7 +94,7 @@ public class DM5CoreServiceTest extends CoreServiceTestEnvironment {
assertSame(23, numbers.get(0).getSimpleValue().intValue());
assertSame(42, numbers.get(1).getSimpleValue().intValue());
//
draw.getChildTopics().addDeletionRef("lotto.number", numbers.get(0).getId());
draw.update(mf.newChildTopicsModel().addDeletionRef("lotto.number", numbers.get(0).getId()));
//
draw = dmx.getTopic(drawId);
numbers = draw.getChildTopics().getTopics("lotto.number");
......
......@@ -283,7 +283,7 @@ public class PersonTest extends CoreServiceTestEnvironment {
// add 2nd Email Address
person.update(mf.newChildTopicsModel().add("dmx.contacts.email_address", "me@example2.com"));
// remove 1st Email Address
children.addDeletionRef("dmx.contacts.email_address", ea1.getId());
person.update(mf.newChildTopicsModel().addDeletionRef("dmx.contacts.email_address", ea1.getId()));
//
// check memory
List<RelatedTopic> emailAddresses = children.getTopics("dmx.contacts.email_address");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment