Saturday, August 14, 2010

Reverse engineering a MySQL schema into JPA classes using AndroMDA

We are looking to use a third party product in our system, and want to integrate our domain with theirs.  I have set up the db schema for the third party in MySQL.  What I am trying to do is create a separate EJB service class to access this third party database.  To do that I want to reverse the database into EJB3 entity classes using AndroMDA.

AndroMDA has an ANT pluging called Schema2XMI which is supposed to automatically generate the domain objects from a schema.  In this post I will attempt to do that.

So far, I have generated a new Andromda project (see previous posts on how to do this).

I have downloaded the AndroMDA binary and exploded it into the folder C:\programs\andromda_bin_exploded
In the root of the new andromda project (same folder as the root pom.xml) I have created the file build.xml and put the following contents inside of it:

           <property name="andromda.lib.dir" value="C:\programs\andromda_bin_exploded\andromda\org\andromda"/>             <property name="andromda.dependency.dir" value="C:\programs\andromda_bin_exploded\lib"/>             <path id="andromda.classpath">         <fileset dir="${andromda.lib.dir}">           <include name="andromda-core/*/andromda-core-*.jar"/>           <include name="andromda-utils/*/andromda-utils-*.jar"/>           <include name="andromda-schema2xmi/*/andromda-schema2xmi-*.jar"/>           <include name="ant/andromda-ant-task/*/andromda-ant-task-*.jar"/>           <include name="metafacades/andromda-metafacades-emf-uml2/*/andromda-metafacades-emf-uml2-*.jar"/>           <include name="metafacades/andromda-metafacades-uml/*/andromda-metafacades-uml-*.jar"/>           <include name="metafacades/andromda-metafacades-uml14/*/andromda-metafacades-uml14-*.jar"/>           <include name="repositories/andromda-repository-emf/*/andromda-repository-emf-*.jar"/>           <include name="repositories/andromda-repository-mdr/*/andromda-repository-mdr*.jar"/>           <include name="repositories/andromda-repository-mdr-uml14/*/andromda-repository-mdr-uml14*.jar"/>           <include name="repositories/andromda-repository-emf-uml2/*/andromda-repository-emf-uml2-*.jar"/>           <include name="translationlibraries/andromda-ocl-query-library/*/andromda-ocl-query-library-*.jar"/>           <include name="translationlibraries/andromda-ocl-translation-core/*/andromda-ocl-translation-core-*.jar"/>           <include name="translationlibraries/andromda-ocl-translation-testsuite/*/andromda-ocl-translation-testsuite-*.jar"/>           <include name="translationlibraries/andromda-ocl-validation-library/*/andromda-ocl-validation-library-*.jar"/>           <include name="templateengines/andromda-templateengine-velocity/*/andromda-templateengine-velocity-*.jar"/>           <include name="cartridges/andromda-java-cartridge/*/andromda-java-cartridge-*.jar"/>         </fileset>         <fileset dir="${andromda.dependency.dir}">           <include name="commons-beanutils/commons-beanutils/*/commons-beanutils-*.jar"/>           <include name="commons-collections/commons-collections/*/commons-collections-*.jar"/>           <include name="commons-digester/commons-digester/*/commons-digester-*.jar"/>           <include name="commons-dbutils/commons-dbutils/*/commons-dbutils-*.jar"/>           <include name="commons-cli/commons-cli/*/commons-cli-*.jar"/>           <include name="commons-lang/commons-lang/*/commons-lang-*.jar"/>           <include name="commons-logging/commons-logging/*/commons-logging-*.jar"/>           <include name="log4j/log4j/*/log4j-*.jar"/>           <include name="velocity/velocity/*/velocity-*.jar"/>           <include name="xerces/xercesImpl/*/xercesImpl-*.jar"/>           <include name="xml-apis/xml-apis/*/xml-apis-*.jar"/>           <include name="jmi/jmi/*/jmi-*.jar"/>           <include name="jmi/jmiuml/*/jmiuml-*.jar"/>           <include name="jmi/mof/*/mof-*.jar"/>           <include name="org/netbeans/mdr/jmiutils/*/jmiutils-*.jar"/>           <include name="org/netbeans/mdr/mdrapi/*/mdrapi-*.jar"/>           <include name="org/netbeans/mdr/nbmdr/*/nbmdr-*.jar"/>           <include name="org/netbeans/mdr/openide-util/*/openide-util-*.jar"/>           <include name="org/eclipse/**/*.jar"/>           <include name="*.jar"/>         </fileset>       </path>       <target name="schema2xmi">         <java classname="org.andromda.schema2xmi.Schema2XMI" fork="true">           <classpath>             <path refid="andromda.classpath"/>           </classpath>           <arg value="-i"/>           <arg value="file:${basedir}/mda/src/uml/schema2xmi/input.xml"/>           <arg value="-u"/>           <arg value="${dbuser}"/>           <arg value="-p"/>           <arg value="${dbpass}"/>           <arg value="-c"/>           <arg value="jdbc:mysql://l127.0.0.1:3306/app"/>           <arg value="-d"/>           <arg value="com.mysql.jdbc.Driver"/>           <arg value="-m"/>           <arg value="file:${basedir}/mda/src/mappings/MySQLMappings.xml"/>           <arg value="-o"/>           <arg value="${basedir}/mda/src/uml/output.xmi"/>           <arg value="-P"/>           <arg value="com::example::app"/>           <arg value="-I"/>           <arg value="Identifier"/>           <arg value="-C"/>           <arg value="Entity"/>           <arg value="-V"/>           <arg value="@andromda.persistence.table"/>           <arg value="-v"/>           <arg value="@andromda.persistence.column"/>         </java>       </target> 

No comments:

Post a Comment