Book a Demo

Author Topic: How to change attribute type in code generation?  (Read 8783 times)

shimon

  • EA User
  • **
  • Posts: 172
  • Karma: +6/-0
    • View Profile
How to change attribute type in code generation?
« on: July 10, 2012, 12:49:32 am »
I would like to manipulate the (JAVA) code generation process to change the attribute type and to add some annotations that I have placed as taggged values, i.e. JPA annotations for table and column name.
Is this possible?
Is there any (basic, step by step) tutorial how to change the code templates to add additional elements?

saradina

  • EA Novice
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: How to change attribute type in code generatio
« Reply #1 on: July 10, 2012, 04:37:45 pm »
Why would you mainpulate the code generation for attribute type?
Why not change it directly using an SQL update?

shimon

  • EA User
  • **
  • Posts: 172
  • Karma: +6/-0
    • View Profile
Re: How to change attribute type in code generatio
« Reply #2 on: July 12, 2012, 01:03:18 am »
I am not so familiar with the syntax necessary for such a change.
I tried

UPDATE t_attribute.Type
set t_attribute.Type='Stringg'
where t_attribute.Type=string

This did't work, any suggestions.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to change attribute type in code generatio
« Reply #3 on: July 12, 2012, 04:29:25 am »
UPDATE t_attribute
set Type='Stringg'
where Type=string

q.

P.S. see my Inside book for links to SQL references

shimon

  • EA User
  • **
  • Posts: 172
  • Karma: +6/-0
    • View Profile
Re: How to change attribute type in code generatio
« Reply #4 on: July 12, 2012, 08:14:01 pm »
I bought and read your book.
I tried what you wrote, but it didn't  work. There is no error.txt in the EA directory.
Is this syntax supposed to work from the SQL builder in EA, or do I have to do this via MS Access?
My EA db is on a SQL server, but I'm doing my experiments on a copy in a EAP file.

shimon

  • EA User
  • **
  • Posts: 172
  • Karma: +6/-0
    • View Profile
Re: How to change attribute type in code generatio
« Reply #5 on: July 12, 2012, 09:05:47 pm »
Now I tried the same from access and it works fine.
Any idea why the update wouldn"t work from within EA?

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: How to change attribute type in code generatio
« Reply #6 on: July 12, 2012, 09:49:38 pm »
Hi,

the file to see the last SQL error is:
DBError.txt and is located in:

%appdata%\Sparx System\EA  

and on my computer:

c:\Dokumente und Einstellungen\deexortm\Anwendungsdaten\Sparx Systems\EA\

Kind regards,

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to change attribute type in code generatio
« Reply #7 on: July 12, 2012, 11:40:16 pm »
Hi shimon,
you can not execute UPDATE or the like in EA's SQL window. It's only for SELECT statements (I guess out of good reasons). So if you wan't to perform an UPDATE you either need to write a script (with the also undocumented Execute function) or to go to some external client.

I will add a clarification in my book.

q.

shimon

  • EA User
  • **
  • Posts: 172
  • Karma: +6/-0
    • View Profile
Re: How to change attribute type in code generatio
« Reply #8 on: July 15, 2012, 11:57:10 pm »
Ok, so now that I know that, let's get back to my first question.
How can I change or add elements to the JAVA code, based on annotations?
What language in used in the code templates?
What is the syntax for adding the tagged values for attributes?

shimon

  • EA User
  • **
  • Posts: 172
  • Karma: +6/-0
    • View Profile
Re: How to change attribute type in code generatio
« Reply #9 on: July 16, 2012, 09:58:57 pm »
OK.
Today I started playing with the code generation templates and realized that adding the annotations is pretty simple.

%attTag: "nullable"% will enter the Value of the tagged value named "nullable".

I tried the following and the resultant code wasn't what I expected:

%if attTag: "nullabel" == "Null=TRUE"
%do something%
%endIf%

The code ended having the first two lines in every attribute. Is there any way that I can test for the existence of a specific Tagged Value?



Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: How to change attribute type in code generatio
« Reply #10 on: July 17, 2012, 09:27:01 am »
Basically you screwed the syntax, it didn't match valid terms so they were generated verbatim.

%if attTag:"nullable" == ""%
stuff generated when no nullable tag (or it's empty)
%else%
stuff generated when nullable tag has a value
%endIf%

shimon

  • EA User
  • **
  • Posts: 172
  • Karma: +6/-0
    • View Profile
Re: How to change attribute type in code generatio
« Reply #11 on: July 17, 2012, 05:44:02 pm »
Thanks.
Worked like a charm. I thought from your answer that I cannot check for a specific value in the tagged value, but that was not so. I was able to check for a specific value and add code dependent on that value.
All the best,
Shimon (m.  :))