[deepamehta-devel] Setting a simple association programmatically

Jörg Richter jri at deepamehta.de
Mon Oct 24 21:33:26 CEST 2016


Hi Robert,

short answer:
=> Use ChildTopics to perform **model-driven** operations.
=> Use dm4.createAssociation() to create an arbitrary (= not model-driven = "free-form") association (as explained by Malte).

About ChildTopics:

The ChildTopics interface provides a high-level abstraction for manipulating parent-child instance hierarchies in a model-driven fashion. All the ChildTopics methods rely on your application's data model (= type definitions + association definitions).

In case your operation IS model-driven (I don't know your application's data model at the moment) you could use addRef() like this:

	ChildTopics childs = comment.getChildTopics();
	childs.addRef("myapp.topic", topicCommentOn.getId());

This assumes your data model contains an association definition (in short: "assoc def") between your topic type "Comment" (parent type) and your topic type "myapp.topic" (child type). The method addRef() would create an association between the parent instance and the specified child instance then.

What would be the type of that association? DM will take the association type from your data model: in case the association is defined (at type-level!) via "Composition Def" it will be an "Composition". In case the association is defined via "Aggregation Def" it will be an "Aggregation". In case an Custom Association Type is set for the assoc def that type will be used.

Lets look at some ChildTopics method signatures:

	ChildTopics set(String assocDefUri, TopicModel value);
	ChildTopics add(String assocDefUri, TopicModel value);
	ChildTopics setRef(String assocDefUri, long refTopicId);
	ChildTopics addRef(String assocDefUri, long refTopicId);

So, what's an "assocDefUri"? DM uses an assocDefUri to pickup a specific assoc def from your parent type definition. In most cases an assocDefUri is just the URI of a child topic type. In case the assoc def makes use of a Custom Association Type its URI MUST be appended via # character. (Malte's explanation was not correct at this point. He confused "assocDefUri" with "assocDefTypeUri").

Examples for assocDefUris:

	"dm4.notes.title"
	"dm4.datetime.date#dm4.contacts.date_of_birth"

Use the set()/setRef() methods in case your child type is defined as cardinality ONE. In contrast, use the add()/addRef() methods in case your child type is defined as cardinality MANY.

Why there is the difference between cardinality-one and cardinality-many operations? This frees you from managing the associations manually. E.g. if you set a single value (via set()) and then another single value (via calling set() again) DM manages to delete the former parent-child-association automatically.

Use the set()/add() methods if you want CREATE a new child and associate that to the parent. In contrast, use the setRef()/addRef() methods if you want associate an EXISTING child to the parent.

Note: if you pass an assocDefUri to a ChildTopics method which is NOT part of your (parent) model that call will be ignored. It is not an error. That's why your call shows no result.


In case your operation is NOT model-driven you can manually create/delete arbitrary associations using dm4.createAssociation()/dm4.deleteAssociation().


Just a hint: it is NOT recommended to manipulate instance hierarchies at the low-level (that is create/delete associations manually) when you could use the ChildTopic's model-driven manipulators.


Cheers,
Jörg


> On 23 Oct 2016, at 22:10, Robert Schuster <robert.schuster.rs01 at gmail.com> wrote:
> 
> Hi all,
> I want to create a simple association between between two topics
> programmatically.
> 
> So the result should be as if I would draw a line between two topics in
> the webclient. I was under the impression that this would be a simple:
> 
>        ChildTopics childs = comment.getChildTopics();
>        childs.addRef("dm4.core.association", topicCommentOn.getId());
> 
> However that did not work as intended. Any idea what I am missing here?
> 
> What wonders me also is that this code seemingly works without error but
> I cannot 'see' any associations in the webclient later on.
> 
> Best regards,
> Robert
> 
> --
> Robert Schuster
> freiberuflicher Softwareingenieur
> 
> RS01 - IT-Systemanalyse und -entwicklung Robert Schuster
> Brückenstraße 4 • 12439 Berlin
> +49 157 798 00 310
> robert.schuster.rs01 at gmail.com
> 
> 
> --
> devel mailing list
> devel at lists.deepamehta.de
> http://lists.deepamehta.de/mailman/listinfo/devel-lists.deepamehta.de

-------------- n�chster Teil --------------
Ein Dateianhang mit Bin�rdaten wurde abgetrennt...
Dateiname   : signature.asc
Dateityp    : application/pgp-signature
Dateigr��e  : 496 bytes
Beschreibung: Message signed with OpenPGP using GPGMail
URL         : <http://lists.deepamehta.de/pipermail/devel-lists.deepamehta.de/attachments/20161024/9f2593af/attachment.sig>


More information about the devel mailing list