What is Schema2XMI?

Schema2XMI is a generator that will read a database schema and write your schema into an XMI model. This is useful for a couple of reasons:

  • Your company wants your DBA(s) to design your schema.
  • Your application already has an existing schema.
  • You want to move a legacy application to AndroMDA.

What kind of models will it produce?

The produced XMI model will possess the following attributes:

  • Associations will contain correct multiplicities based on foreign key relations.
  • Correct multiplicities on attributes that are nullable vs. non-nullable (0..1 and 1).
  • Composite aggregation will be created on relationships marked with cascade deletes.
  • Configurable stereotypes will be added to classes and identifiers.
  • Optional configurable tagged values for column names and table names can be added to attributes and tables respectively.

How do I use Schema2XMI?

Schema2XMI is a command line utility that you'll pass arguments to and then execute the main Schema2XMI class. The usage is defined below:

usage: org.andromda.schema2xmi.Schema2XMI [options] ...]]

Options:
 -C,--classStereotypes <arg>        Comma seperated list of stereotype
                                    names to add to the created class
 -I,--identifierStereotypes <arg>   Comma seperated list of stereotype
                                    names to add to any class identifiers
 -P,--package <arg>                 The package to output classifiers
 -V,--tableTaggedValue <arg>        The tagged value to use for storing
                                    the table name
 -a,--columnPattern <arg>           The column name pattern of columns to
                                    process (regular expression)
 -c,--connectionUrl <arg>           JDBC connection URL
 -d,--driver <arg>                  JDBC driver class
 -h,--help                          Display help information
 -i,--input <arg>                   Input model file (to which model
                                    elements will be added)
 -m,--mappings <arg>                The type mappings URI (i.e.
                                    file:${basedir}/DataypeMappings.xml)
 -o,--output <arg>                  Output location to which the result of
                                    the transformation will be written
 -p,--password <arg>                Schema user password
 -s,--schema <arg>                  The name of the schema where the
                                    tables can be found
 -t,--tablePattern <arg>            The table name pattern of tables to
                                    process (regular expression)
 -u,--user <arg>                    Schema user name
 -v,--columnTaggedValue <arg>       The tagged value to use for storing
                                    the column name
 -x,--xmi <arg>                     Specifies the XMI version that will be
                                    produced

Here's an example of how you could use Schema2XMI with an Oracle schema from Ant with the java task .

<
java
classname=
"org.andromda.schema2xmi.Schema2XMI"
fork=
"true"
> <
classpath
> <
path
refid=
"schema2xmi.classpath"
/
> <
/classpath
> <
arg
value=
"-i"
/
> <
arg
value=
"jar:file:${src.dir}/test/uml/SomeModel.xml.zip!/SomeModel.xml"
/
> <
arg
value=
"-u"
/
> <
arg
value=
"someuser"
/
> <
arg
value=
"-p"
/
> <
arg
value=
"somepassword"
/
> <
arg
value=
"-c"
/
> <
arg
value=
"jdbc:oracle:oci:@yoursid"
/
> <
arg
value=
"-d"
/
> <
arg
value=
"oracle.jdbc.driver.OracleDriver"
/
> <
arg
value=
"-m"
/
> <
arg
value=
"file:${conf.dir}/mappings/DatatypeMappings.xml"
/
> <
arg
value=
"-o"
/
> <
arg
value=
"${build.dir}/schema2xmi/transformed.xmi"
/
> <
arg
value=
"-t"
/
> <
arg
value=
"[\p{Lower}\p{Upper}[_]]*"
/
> <
arg
value=
"-P"
/
> <
arg
value=
"org::andromda::sample"
/
> <
arg
value=
"-C"
/
> <
arg
value=
"entity,persistent"
/
> <
ant
value=
"-I"
/
> <
arg
value=
"identifier"
/
> <
arg
value=
"-V"
/
> <
arg
value=
"@andromda.persistence.table"
/
> <
arg
value=
"-v"
/
> <
arg
value=
"@andromda.persistence.column"
/
> <
/java
>

IMPORTANT: The datatype mappings file that you specify with the -m argument, must be structured like the example directly below:

<!-- This is used to map SQL Types to model datatypes for Schema2XMI -->
<
mappings
name=
"DatatypeMappings"
> <
mapping
> <
from
>DECIMAL<
/from
> <
to
>datatype::Decimal<
/to
> <
/mapping
> <
mapping
> <
from
>VARCHAR<
/from
> <
to
>datatype::String<
/to
> <
/mapping
> <
mapping
> <
from
>TIMESTAMP<
/from
> <
to
>datatype::Timestamp<
/to
> <
/mapping
> <
mapping
> <
from
>BLOB<
/from
> <
to
>datatype::Blob<
/to
> <
/mapping
> <
/mappings
>