Book a Demo

Author Topic: GENERATE DDL code -  (Read 6024 times)

Carmenza

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
GENERATE DDL code -
« on: March 20, 2009, 11:38:30 am »
Hi there:

I need to generate a DDL code from my proyect, must be base on the version of the tables.
EA assign the next configuration
Element Type = Class
Stereotype = Table
Element Field = version
Element field = 1.0

Any suggestions ? Do I need to use an Add-In or there is something to set up during the DDL code generation ?

 :'(

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: GENERATE DDL code -
« Reply #1 on: March 22, 2009, 08:44:07 am »
Make sure that you set up a Data Modeling diagram - it is under the Extended set on the New Diagram dialog.

Also, make sure you set the DBMS for new table elements. You can do this with the properties dialog. You can also use the Settings | Database Datatypes dialog to set a default DBMS.

Now you should be able to build a data model diagram, select the package it belongs to (in the Project Browser) and generate DDL. From the EA main menu choose Project | Database Engineering | Generate Package DDL.

Once you've tried this you should reread the EA help sections on DDL generation and play around a bit.

I don't know if you can (yet) do this via automation.
No, you can't have it!

Carmenza

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: GENERATE DDL code -
« Reply #2 on: March 24, 2009, 02:59:36 pm »
Dear Midnight,

Thanks for your kind reply, I have been using the options to generate DDL code extensible already.

Currently, I have many tables in the same package and I need to be able to generate the DDL code in selected way according with the version.

All the tables are at the moment in the same package, to consolidate a unique data model of my Database with old and new tables.

If you have any idea or suggestion please let me know.  :-?

Cheers,


«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: GENERATE DDL code -
« Reply #3 on: March 24, 2009, 11:11:41 pm »
I think I see what you are trying to do.

This might be difficult - not necessarily impossible - due to some limitations of EA's data modeling approach.

First, EA does not provide any gateway into the data modeling process. It is a black box as far as code generation is concerned. There are a few options, those on the DDL dialog, that are essentially global. These are stored in the Windows registry, and therefore affect all DDL generation, across all DBMS products and EA projects. A few additional options are provided for (very) specific attributes of some DBMS products; (I think) these are stored as tagged values, and affect individual elements when DDL is generated for specific DBMS engines.
===
NOTE: One particularly annoying - and dangerous, particularly in your situation - global setting is the database (or schema) name. I don't mean the output file, but the database that will be named in a USE statement in the SQL. Changing this setting affects all data models in all EA projects, including those that have already been created. Running DDL generation on any past or subsequent model will use the most recent setting (from any DDL generation effort). I've mentioned this to Sparx, but don't know if they will change this behavior; I've not had feedback either way.
===

EA also allows you to generate DDL associated with a single table if you want. This will use a subset of the available options (those with relevance to table-oriented SQL). You'll get the necessary DROP and CREATE statements, as well as any triggers associated with the table. You do this by selecting the table on a data modeling diagram, then generating DDL as you would for the entire diagram. Note that EA generates table-specific DDL for only one table. If you select multiple tables on a diagram, EA will generate the DDL for the last one selected.

Beyond these few options, EA controls everything about DDL generation. You cannot modify the algorithm or template that EA uses. Nor can you have EA test any attributes (tagged values, etc.) you set, and generate optional DDL in response to the test results.

This could make it difficult for you to generate depending on your version attribute (or any other value you use).

But there might be hope...

What you can do is break up your model into 'chunks' that will be generated together. Remember that (with the exception of generating a single table) this is all or nothing. Everything on a diagram, perhaps in a package, that is part of a data model will have DDL generated. So you must have use some kind of package hierarchy to segregate data model components into coherent groups.

You can also use transformation scripts - look at MDA transforms in the EA help - to generate these models. This is not DDL generation, but the construction of one model based on another. A common use of this is to create a 'pure' model that is independent of any DBMS. This could be used as the pattern to generate equivalent implementations in several different DBMS models. You could even generate the 'pure' model (or the DBMS-specific ones) directly from a class model.

In your case you might create such a basic model for your first version, then define transformations for each new version. The new models would be placed in their own package (or package trees) to separate them from other versions. You could also do this by hand; there's no requirement to use transformation scripts. Once you do this you can generate DDL for each version by selecting the appropriate starting point in your package hierarchy.

That might not be exactly what you imagine now, and it is certainly not fully automatic, but it just might do what you need.

David
No, you can't have it!

Carmenza

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: GENERATE DDL code -
« Reply #4 on: March 25, 2009, 10:48:38 am »
David:

I like your idea, simple and should work well, tough, it is not as automatic as I would like it. I can break my model and still use one big data model diagram.

Just a quick note - EA can generated DDL code from a selected tables from a long list. Of course, one by one using  <Ctrl> key and a single file as an option.

 ;)

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: GENERATE DDL code -
« Reply #5 on: March 25, 2009, 10:29:12 pm »
Sorry, I stand corrected, sort of. I just meant that you could not (or at least it did not work for me) generate several selected tables all at once. It only generates for the most recently selected of the group.

Note that generating for selected tables does not generate stored procedures. There is a «proc» stereotype available for operations, which looks like it should allow stored procedures to be associated with a table. Unfortunately this stereotype seems to have no effect on DDL generation.

NOTE: I have not done extensive testing on this though. I just gave up after confirming that it would not help me in what I was working on. I also tried this on a different project some time ago (I think back in EA 6.x days) with the same results. I had hoped at the time that this was a placeholder for (then) future implementation. This seems not to have come about.
No, you can't have it!