Author Topic: Linked Operations?  (Read 1188 times)

danm

  • EA User
  • **
  • Posts: 88
  • Karma: +0/-0
    • View Profile
Linked Operations?
« on: November 30, 2007, 10:54:20 am »
Hello,
  I'd like to take code gen to the next step. Kleppe has a good article on associations and the code which should be generated to correspond with them

http://www.devx.com/enterprise/Article/28528
http://www.devx.com/enterprise/Article/28576

  Using her example for a 'marriage' (and association) there is boilerplate which is generic to create and delete the associations. Really it's Linked Operations.

  I'd like to add this and more to EA, but I'm not sure what is the best way.


  • In the templates, when I'm in an association, I can't generate function code as that's a different part of the output stream.
  • I could add the operations manually as a stereotype, and override the stereotype code gen in the templates. But that's clumsy - albeit I could write an add-in to do that for me (i.e. Update all Association Operations)
  • I could just do it all via automation but that's too much work (I'd have to generate all the code myself).
  • One possibility is to use a MDG transformation. I'm not familiar with MDG transforms yet (just conquered code templates and add-ins), but maybe a transform could create operations from a link. So maybe an association gets transformed into a special property stereotype (attribute and operations), which generates the proper code.
  • The other possibility I just realized is a new code template? If I create a new template of base type operation, which is for linked operations, maybe I can call it from somewhere - but I'm not sure.


Thoughts?
« Last Edit: November 30, 2007, 11:50:33 am by danm »

danm

  • EA User
  • **
  • Posts: 88
  • Karma: +0/-0
    • View Profile
Re: Linked Operations?
« Reply #1 on: December 03, 2007, 08:26:06 am »
OK, helped by the dearth of comments on this thread I figured it out  ;D

I now do a transformation. In the transformation, when I'm generating a linked attribute, I list over all of the Connectors using a new custom Connector template. I find the one with the same GUID as the one I'm in, then look at it's origin navigability. If it's non navigable (a ---> association) then I just generate a regular attribute as a property.

If it is navigable (a <---> association) then I generate a get, set, and z_removeInternal as detailed in the article. The code is generated in the code template based on the stereotype, I use tags to pass in the proper information on how to generate the code.

Very powerful.

Some notes - when generating linked attributes, the link away from you is always the 'Target'. Even though it could be the Source or the Target in the actual link. And two, GUID's generated during transformations are not preserved to code generation.
« Last Edit: December 03, 2007, 08:28:20 am by danm »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Linked Operations?
« Reply #2 on: December 03, 2007, 10:40:54 am »
On your final point - lack of GUID preservation - I keep thinking I saw something about how to capture these. It was in the forum;it might have been an answering post by one of the Sparxians, but I'm not sure about that. If you search for this go back a long ways, since I think it was over a year ago, perhaps more than two.

David

PS: Please post the URL of the post(s) you find, if any.
No, you can't have it!

danm

  • EA User
  • **
  • Posts: 88
  • Karma: +0/-0
    • View Profile
Re: Linked Operations?
« Reply #3 on: December 03, 2007, 03:17:19 pm »
David - sorry I don't understand. What do you mean 'capture these'?

No matter - I solved it in a better way. The previous solution was to grab the GUID and pass it to the code gen via a tag. The code gen would then find the connector corresponding to that GUID, and check the source navigability.

A better way is just to do the same search up in the transformation template, and not preserve the exact value of the GUID.

I just mention as a tip to others - don't depend on GUID's being preserved!

I'd like to put these tips together in a FAQ or something.
« Last Edit: December 03, 2007, 03:17:41 pm by danm »

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Linked Operations?
« Reply #4 on: December 03, 2007, 04:13:09 pm »
Nice solution!

What I meant was that I thought I'd seen a way to capture the GUID of something newly created during code generation. Or it might have been a way to create a GUID and have the generator assign it to the new entity.

I just don't remember where I saw it, and it was quite a while ago, so I don't remember the details. So I also don't know if it would solve your current problem (or improve on the current solution you have)

Still, you might want to look for the article. It was in the (some section of) the EA forum that I saw it.

Still, it bears repeating: you've come up with a nice solution.

David

PS: I do know that in automation projects, EA normally assigns the GUID property when you call Update the first time after creating a new entity. If you first assign a GUID that you've acquired through some other method, and then call Update, EA will use the one you provided. [After that, the property is read-only.] So it is entirely possible that something roughly equivalent has been provided in the generation engine.
No, you can't have it!