Default relations?

Writing maintainable templates.

Default relations?

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

Hi,

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
^
FooEntity

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
robau
 
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
Example00.png (7.69 KiB) Viewed 6125 times


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

Example01.png
Example01.png (51.79 KiB) Viewed 6125 times


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

Example02.png
Example02.png (21.65 KiB) Viewed 6125 times


This would lead to the following result:

Example03.png
Example03.png (42.12 KiB) Viewed 6125 times


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

Example04.png
Example04.png (34.88 KiB) Viewed 6125 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
Example05.png (25.21 KiB) Viewed 6125 times


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

Example06.png
Example06.png (48.65 KiB) Viewed 6125 times


Please find the working example for actifsource V 5.3.2 here:

com.actifsource.example.zip
(33.98 KiB) Downloaded 1156 times
reto
 
Posts: 76
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
robau
 
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

cron