Author Topic: [NewBee] How can I do ?  (Read 721 times)

Marc MENDEZ

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
[NewBee] How can I do ?
« on: June 03, 2008, 05:44:53 pm »
Hi,

I'm a biginner with EA.  ;)
Our project runs with PHP and MySql. I'm very interested in code generation. It works for MySql table quite well.
However, I would like to generate PHP code for the classes which handle the table in PHP.
Example : I create a table T with a couple of attributes. I would like to get the code of the corresponding class , with the getter and setter function.
Is it possible ? I look at the manual, but did not find any clue !

Thanks for your light !

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: [NewBee] How can I do ?
« Reply #1 on: June 03, 2008, 10:18:47 pm »
Hi Marc,

I think you can do this, but there is some work involved. First, let's make sure I understand your situation.

At this point you have some classes, from which you can generate code - meaning program code. You also have a table (or a few tables). You could generate DDL (distinct from "code" as used above). from those tables. That's fine as far as it goes, but you really want to be able to generate code (as above) to go with your other classes.

You actually have the correct picture of what needs to happen, as you describe when you say "get the code of the corresponding class."

There is a missing step here. What you need to do is to somehow obtain the 'missing' class that corresponds with your table, so that you can generate the appropriate code for the class along with all your others.

EA allows for transformations. There are several built in transformations, and you can create your own. A common scenario is transforming a class model into a database model. I believe there is a 'stock' transformation for that purpose. Another is the obverse - which is what you need here - but I do not know if there is a built-in transformation (I have not checked in a while).

There is a fairly lengthy - yet still incomplete - section in the EA help relating to transformations and code generation. There's also a few white papers on the Sparx Resources page. When you've got the idea, search this forum for more information; there's been a lot of discussion with many hints over the years.

Here's your first hint. Make a copy of a built-in script (whether for transformation or code generation) with a new name (you'll have to name the copy upon creation), then edit the copy. Failure to catch that nuance can lead to many hours of frustration while you try to figure out why your edits don't take. [One guess who fell into that trap. Twice!]

HTH, David

No, you can't have it!

sargasso

  • EA Practitioner
  • ***
  • Posts: 1406
  • Karma: +1/-2
  • 10 COMFROM 30; 20 HALT; 30 ONSUB(50,90,10)
    • View Profile
Re: [NewBee] How can I do ?
« Reply #2 on: June 03, 2008, 11:21:11 pm »
Well, so much for MDA or MDQ or MDfiik, eh?

I guess you just got to understand the problem in the first instance,  

What, "exactly" are you trying to do...  design the solution or define the problem?


yet-agin y'all "The ghost who works" (heheheheheh)
(Now innerstatic in Tacxes).
"It is not so expressed, but what of that?
'Twere good you do so much for charity."

Oh I forgot, we aren't doing him are we.

Marc MENDEZ

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: [NewBee] How can I do ?
« Reply #3 on: June 03, 2008, 11:56:53 pm »
Hi,

Your answer gave me an idea that I have tried :

- I create a class table, with a few attributes
- Then I choose Project -> Transformations -> Transform Selected Elements.
- I don't have a PHP transformation : so I choose Java.

Then I edit the new element generated : it has the same name, but it contains getter and setter.
I clear the stereotype field and press OK. I edit again the same element : now the "Language" dropdown list is available. I choose "PHP".
I can now generate (F11) PHP code. ::)

But, I'm sure there must have a shorter solution. But it works.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: [NewBee] How can I do ?
« Reply #4 on: June 04, 2008, 01:12:09 am »
Yes, there might be a shorter solution.

I suspect the best you can hope for is to eliminate the middle step that switches from Jave to PHP.

The main point is that you've got it working. As long as you are moving forwards you can call this a success.

David
No, you can't have it!

Marc MENDEZ

  • EA Novice
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: [NewBee] How can I do ?
« Reply #5 on: June 04, 2008, 05:11:22 pm »
Quote
Yes, there might be a shorter solution.

I suspect the best you can hope for is to eliminate the middle step that switches from Jave to PHP.

Right, but I must choose a language to transform into, and PHP is not in the list.

But, as you say, I'm moving forwards !  ::)

Thanks for you help