Book a Demo

Author Topic: Class model --> Data model  (Read 3753 times)

trasys

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Class model --> Data model
« on: December 12, 2008, 06:42:49 pm »
Is there in EA a simple, semi-automated way to create/generate a data model from an existing class model without touching the class model itself?

Thanks for any suggestion.

Philippe
www.trasys.be

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Class model --> Data model
« Reply #1 on: December 13, 2008, 04:11:31 am »
You should be able to use a transformation to generate a new data model from a class model. Depending on several factors you could use a built-in transformation, or copy one of the built-in transformations and edit it to create your own.

Check out transformations in the code engineering (I think) section of EA help. Then look at the Sparx Resources page for some tutorials, white papers, and other information.

When you have the general idea working, you might want to come back to the forum and do a search (or two or three, the forum search engine can be a bit tricky) for specific tricks and traps.

HTH, David
No, you can't have it!

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: Class model --> Data model
« Reply #2 on: December 15, 2008, 09:57:14 pm »
Hi Philippe

As David has suggested the first thing to try is the MDA (Model Driven Architecture) transformation.

Refer to the User Guide for more specific detail, but here is a summary

1) Right click the package containing the class(es) to be transformed
2) Choose "Code Engineering/Set as namespace root"
3) Create a destination view/package for your data model if not already present in your model
4) Right click the package containing the class(es) to be transformed and choose "transform current package"
5) If your package cobtains child pakcages, select the check box "Inlcude child packages"
6) From the list of classes displayed select the ones to be transformed (the default is all of them)
7) On the right had side of the dialog, check DDL and then select the destination for your data model
8) Click "Do Transform"
9) After the process is completed you will have a set of tables (one for each class) and a class (data model) diagram
10) Open the diagram and layout the classes

Issues

As a UML class has no concept of a primary key, a primary key will be added to each table.

This key is of type "int" and has the name "ClassnameID"

This key is used to define foreign key relationships

This will mean some editing of tables/realtionships

The data model is targeted as a specific DBMS (chosen from the Code Engineering Toolbar)

Ypu may have create some mapping between your data types defined in your UML classes and the specific DBMS data types, there are built transformations available.

For best results, model your UML classes using UML primitive types (set the code generation language to "none" for all classes)

The above is far easier to do than it is to describe, try it!

Cheers

Phil
Models are great!
Correct models are even greater!

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: Class model --> Data model
« Reply #3 on: December 16, 2008, 12:03:28 am »
Oh I forgot one thing, after creating the data model with MDA (or manually for that matter), double click the diagram background and select "Connctors" tab, then change the Connect Notation to "Information Engineering" and you should see the notation change to Entity Relationship "crows-foot" rather than UMl notation

Cheers
Phil
Models are great!
Correct models are even greater!

trasys

  • EA Novice
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Re: Class model --> Data model
« Reply #4 on: December 16, 2008, 06:11:36 am »
Thanks David & Phil for your assistance.

I did some tests and I could generate a data model; I even could set the target database.

Nevertheless, I see a problem for which I have to find a workaround or a best practice: if I make changes to a generated table and I regenerate the DDL afterwards, then my changes to the table are lost.
This is a bit awkward because our client requests standardised table and field names, and because we do our analysis in an iterative way.
I will have to see how to solve this with a minimum of manual activities.

« Last Edit: December 16, 2008, 06:46:10 am by phhome »

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: Class model --> Data model
« Reply #5 on: December 16, 2008, 08:15:37 pm »
Rather than change the generated DDL model, try going back to the original class model, change the attributes there add tables etc and perform the MDA transformation again, what you should experience is that the changes you made to the UMl class diagram are no synchronized with the underlying DDL model. Even the layout of the data model is preserved.

If you delete a class from the UML class model, then the corressponding table will not be removed from the DDL model, apart from this the synchronization seems to work pretty well. Give it a try!

Cheers
Phil
Models are great!
Correct models are even greater!