Skip navigation.
Home

Reverse engineer DataBase to XMI.

In this article I will try to reverse engineer a postgres data base and I think any other database will be the same with small modifications in the config and properties files.

ok lets start.

I will use andromda:schema2xmi plugin to achieve this task.

Prerequisites:

  1. Maven version 1.
  2. In brief a working andromda environment.


Requiered steps to generate the xmi file from our postgres data base are 5:

  1. Generate an AndroMDA project using Maven.
  2. Add the PostgreSQL Mappings file.
  3. Modify the project properties.
  4. Add dependency to Postgres jdbc drivers.
  5. Run schema2xmi.


1. Generate a standard J2EE project. as down million of times:

 by issuing the following at command line:
   maven andromdapp:generate

aabdelaziz@aliminium:~/NetBeansProjects/Private/ANDROMDA>  maven andromdapp:generate

__  __
|  \/  |__ _Apache__ ___
| |\/| / _` \ V / -_) ' \  ~ intelligent projects ~
|_|  |_\__,_|\_/\___|_||_|  v. 1.0.2

Please enter your first and last name (i.e. Chad Brandon):

Ali Abdel-Aziz

Please enter the name of your J2EE project (i.e. Animal Quiz):

reverse database

Please enter the id for your J2EE project (i.e. animalquiz):

reversedatabase

Please enter a version for your project (i.e. 1.0-SNAPSHOT):

1.0-SNAPSHOT

Please enter the base package name for your J2EE project (i.e. org.andromda.samples):

org.egjug.reversedatabase

Would you like an EAR or standalone WAR (enter 'ear' or 'war')?

war

Would you like to be able to expose your services as web services? (enter 'yes' or 'no'):

yes

build:start:

andromdapp:init:

andromdapp:generate:
    [echo] +---------------------------------------------------------------------+
    [echo] |   G E N E R A T I N G   A n d r o M D A   J 2 E E   P R O J E C T   |
    [echo] +---------------------------------------------------------------------+
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp
    [copy] Copying 1 file to /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp
andromdapp:init:

andromdapp:generate-spring-subproject:
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/core
andromdapp:init:

andromdapp:generate-core-subproject:
andromdapp:generate-module:

    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/core/src/java
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/core/target/src

andromdapp:init:

andromdapp:generate-common-subproject:
andromdapp:generate-module:
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/common

    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/common/src/java
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/common/target/src

andromdapp:init:

andromdapp:generate-mda-subproject:
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/mda/src/uml
    [copy] Copying 1 file to /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/mda/src/uml
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/mda/conf
    [copy] Copying 1 file to /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/mda
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/mda/conf/mappings

andromdapp:init:

andromdapp:generate-web-subproject:
andromdapp:generate-module:
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/web

    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/web/src/java
    [mkdir] Created dir: /home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp/web/target/src

    [echo] New J2EE project generated to: '/home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/testapp'
BUILD SUCCESSFUL
Total time: 7 minutes 53 seconds
Finished at: Mon Sep 18 12:12:05 EEST 2006
 
aabdelaziz@aliminium:~/NetBeansProjects/Private/ANDROMDA>

 


2. Place the attached PostgreSQLMappings.xml file to
${project.home}/mda/mappings/:

you will find the PostgreSQLMappings.xml attached but with different name because of attachment modules didn't allow to attach xml files.

rename it form PostgreSQLMappings.jpg to PostgreSQLMappings.xml.

 
3. Add the following properties to the
${project.home}/mda/project.properties file:

#Items related to schema2xmi

maven.andromda.schema2xmi.user=databaseUser

maven.andromda.schema2xmi.password=databasePassword

maven.andromda.schema2xmi.driverClass=org.postgresql.Driver

maven.andromda.schema2xmi.connectionUrl=jdbc:postgresql://localhost/databaseName

maven.andromda.schema2xmi.mappingsUri=file:///home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/ reverseDataBase/mda/conf/mappings/PostgreSQLMappings.xml 
maven.andromda.schema2xmi.classStereotype=Entity

maven.andromda.schema2xmi.identifierStereotypes=Identifier

maven.andromda.schema2xmi.package=org.egjug.reversedatabase
 


4. Add the following dependencies to the ${project.home}/mda/project.xml

        <dependency>

            <groupId>postgresql</groupId>

            <artifactId>postgresql</artifactId>

            <version>8.1-407.jdbc3</version>

            <type>jar</type>

        </dependency>
 

5. Now, its schema2xmi time:

go to ${project.home}/mda 

aabdelaziz@aliminium:~/NetBeansProjects/Private/ANDROMDA/reverseDataBase/mda>

then run the following

aabdelaziz@aliminium:~/NetBeansProjects/Private/ANDROMDA/reverseDataBase/mda>  maven andromda:schema2xmi

                   .
                   .
                   .

    [java] INFO  [SchemaTransformer] Completed adding 42 classes, writing model to --> '/home/aabdelaziz/NetBeansProjects/Private/ANDROMDA/reverseDataBase/mda/target/schema2xmi/transformed.xmi', TIME --> 9.739[s]
BUILD SUCCESSFUL
Total time: 19 seconds
Finished at: Mon Sep 18 12:27:54 EEST 2006

aabdelaziz@aliminium:~/NetBeansProjects/Private/ANDROMDA/reverseDataBase/mda>

The transformed model will be found under

mda/target/schema2xmi/transformed.xmi
 

Reference

 

 Ali Abdel-Aziz

AttachmentSize
PostgreSQLMappings.jpg2.95 KB