Default relations?

Writing maintainable templates.

Default relations?

Postby robau » Tue May 29, 2012 12:05 pm


I want to create several types of java objects, so I wrote a simple Entity-Attribute-Relation model. Now I wanted to specialize a bit, i.e. creating a subclass of Entity that already has 4 relations to 4 Attributes. Can such be achieved? Or are there better ways to do the same? The reason I like to make the relations is that the code is then generated similarly to the other specialized objects.

My case (simplified)

Entity -> Attributes

I want the FooEntity to contain 4 relations to attributes, i.e. dateCreated, dateMofified. These should be relations to Attributes. I know I can code them in a template, but then I can't use the nice code-generation capalibities
Posts: 4
Joined: Tue May 29, 2012 9:40 am

Re: Default relations?

Postby reto » Tue May 29, 2012 7:49 pm

Hi Rob

Thank you for your interesting question. I would suggest that you model an extends relationship between the entities:

Example00.png (7.69 KiB) Viewed 8107 times

Doing so allows you to model the base entities with the desired attributes:

Example01.png (51.79 KiB) Viewed 8107 times

Writing standard template code you would ask for all attributes in the entity as follows:

Example02.png (21.65 KiB) Viewed 8107 times

This would lead to the following result:

Example03.png (42.12 KiB) Viewed 8107 times

But it is also possible to write much more complex selector expressions which are able to recursively call themselves.

Example04.png (34.88 KiB) Viewed 8107 times

  • Create a new resource of type FunctionSpace
  • Inside, create a new ResourceInfo with typeRef Entity
  • Inside create a new SelectorFunction named allEntity
  • returnType shall be of type ListType with innerTypeRef Entity

This means that we create a function which can be called in the template on type Entity and returns a list of Entity. The idea is now to collect all base entities which can be recursively reached via the extends relation.

For that reason please enter the following selector statement:

  • Entity.extends.allEntity@Common union Entity:Entity

This means that

  • On the current entity we follow the extends relation an call ourself recursively
  • Then we create a union (set theory) with the current entity itself

As a result, you are now able to use allEntity in your template code and ask for the attributes on this result:

Example05.png (25.21 KiB) Viewed 8107 times

As a result the generated files contains all the entity from the modeled base classes:

Example06.png (48.65 KiB) Viewed 8107 times

Please find the working example for actifsource V 5.3.2 here:
(33.98 KiB) Downloaded 1256 times
Posts: 87
Joined: Thu Aug 05, 2010 2:45 pm
Location: Switzerland

Re: Default relations?

Postby robau » Thu May 31, 2012 3:45 pm

Thanks, very nice read!

I will definately try it
Posts: 4
Joined: Tue May 29, 2012 9:40 am

Return to Generic Code

Who is online

Users browsing this forum: No registered users and 1 guest