org.andromda.schema2xmi
Class SchemaTransformer

java.lang.Object
  extended by org.andromda.schema2xmi.SchemaTransformer

public class SchemaTransformer
extends java.lang.Object

Performs the transformation of database schema to XMI.

Author:
Chad Brandon

Constructor Summary
SchemaTransformer(java.lang.String jdbcDriver, java.lang.String jdbcConnectionUrl, java.lang.String jdbcUser, java.lang.String jdbcPassword)
          Constructs a new instance of this SchemaTransformer.
 
Method Summary
protected  void addForeignKey(java.lang.String tableName, java.lang.String columnName)
          Adds a foreign key column name to the foreignKeys Map.
protected  java.util.Collection createAssociations(java.sql.DatabaseMetaData metadata, org.omg.uml.foundation.core.CorePackage corePackage, java.lang.String tableName)
          Creates and returns a collection of associations by determing foreign tables to the table having the given tableName.
protected  org.omg.uml.foundation.datatypes.Multiplicity createAttributeMultiplicity(org.omg.uml.foundation.datatypes.DataTypesPackage dataTypes, boolean required)
          Creates an attributes multiplicity, if required is true, then multiplicity is set to 1, if required is false, then multiplicity is set to 0..1.
protected  java.util.Collection createAttributes(java.sql.DatabaseMetaData metadata, org.omg.uml.foundation.core.CorePackage corePackage, java.lang.String tableName)
          Creates and returns a collection of attributes from creating an attribute from every column on the table having the give tableName.
protected  org.omg.uml.foundation.core.UmlClass createClass(org.omg.uml.modelmanagement.UmlPackage modelPackage, java.sql.DatabaseMetaData metadata, org.omg.uml.foundation.core.CorePackage corePackage, java.lang.String tableName)
          Creates and returns a UmlClass with the given name using the corePackage to create it.
protected  void createClasses(java.sql.Connection connection, org.omg.uml.foundation.core.CorePackage corePackage, org.omg.uml.modelmanagement.UmlPackage modelPackage)
          Creates all classes from the tables found in the schema.
protected  org.omg.uml.foundation.datatypes.Multiplicity createMultiplicity(org.omg.uml.foundation.datatypes.DataTypesPackage dataTypes, int lower, int upper)
          Creates a multiplicity, from lower and upper ranges.
protected  org.omg.uml.foundation.core.TaggedValue createTaggedValue(org.omg.uml.foundation.core.CorePackage corePackage, java.lang.String name, java.lang.String value)
          Creates a tagged value given the specfied name.
protected  org.omg.uml.foundation.core.DataType getOrCreateDataType(org.omg.uml.foundation.core.CorePackage corePackage, java.lang.String type)
          Gets or creates a new data type instance having the given fully qualified type name.
protected  org.omg.uml.modelmanagement.UmlPackage getOrCreatePackage(org.omg.uml.modelmanagement.ModelManagementPackage modelManagementPackage, org.omg.uml.modelmanagement.UmlPackage modelPackage, java.lang.String packageName)
          Gets or creates a package having the specified packageName using the given modelManagementPackage, places it on the model and returns the last leaf package.
protected  java.util.Collection getOrCreateStereotypes(org.omg.uml.foundation.core.CorePackage corePackage, java.lang.String names, java.lang.String baseClass)
          Gets or creates a stereotypes given the specfied comma seperated list of names.
protected  java.util.Collection getPrimaryKeyColumns(java.sql.DatabaseMetaData metadata, java.lang.String tableName)
          Returns a collection of all primary key column names for the given tableName.
protected  boolean hasForeignKey(java.lang.String tableName, java.lang.String columnName)
          Returns true if the table with the given tableName has a foreign key with the specified columnName.
protected  boolean isColumnNullable(java.sql.DatabaseMetaData metadata, java.lang.String tableName, java.lang.String columnName)
          This method just checks to see if a column is null able or not, if so, returns true, if not returns false.
 void setClassStereotypes(java.lang.String classStereotypes)
          Sets the stereotype name for the new classes.
 void setColumnNamePattern(java.lang.String columnNamePattern)
          Sets the regular expression pattern to match on when deciding what attributes ti create in the XMI.
 void setColumnTaggedValue(java.lang.String columnTaggedValue)
          Sets the name of the column tagged value to use for storing the name of the column.
 void setIdentifierStereotypes(java.lang.String identifierStereotypes)
          Sets the stereotype name for the identifiers on the new classes.
 void setPackageName(java.lang.String packageName)
          Sets the name of the package to which the model elements will be created.
 void setSchema(java.lang.String schema)
          Sets the name of the schema (where the tables can be found).
 void setTableNamePattern(java.lang.String tableNamePattern)
          Sets the regular expression pattern to match on when deciding what table names to add to the transformed XMI.
 void setTableTaggedValue(java.lang.String tableTaggedValue)
          Sets the name of the table tagged value to use for storing the name of the table.
 void setTypeMappings(java.lang.String typeMappingsUri)
          Sets the mappingsUri which is the URI to the sql types to model type mappings.
 void setXmiVersion(java.lang.String xmiVersion)
          Sets the version of XMI that will be produced.
 void transform(java.lang.String inputModel, java.lang.String outputLocation)
          Transforms the Schema file and writes it to the location given by outputLocation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SchemaTransformer

public SchemaTransformer(java.lang.String jdbcDriver,
                         java.lang.String jdbcConnectionUrl,
                         java.lang.String jdbcUser,
                         java.lang.String jdbcPassword)
Constructs a new instance of this SchemaTransformer.

Method Detail

transform

public void transform(java.lang.String inputModel,
                      java.lang.String outputLocation)
Transforms the Schema file and writes it to the location given by outputLocation. The inputModel must be a valid URL, otherwise an exception will be thrown.

Parameters:
inputModel - the location of the input model to start with (if there is one)
outputLocation - The location to where the transformed output will be written.

setTypeMappings

public void setTypeMappings(java.lang.String typeMappingsUri)
Sets the mappingsUri which is the URI to the sql types to model type mappings.

Parameters:
typeMappingsUri - The typeMappings to set.

setPackageName

public void setPackageName(java.lang.String packageName)
Sets the name of the package to which the model elements will be created.

Parameters:
packageName - The packageName to set.

setSchema

public void setSchema(java.lang.String schema)
Sets the name of the schema (where the tables can be found).

Parameters:
schema - The schema to set.

setTableNamePattern

public void setTableNamePattern(java.lang.String tableNamePattern)
Sets the regular expression pattern to match on when deciding what table names to add to the transformed XMI.

Parameters:
tableNamePattern - The tableNamePattern to set.

setColumnNamePattern

public void setColumnNamePattern(java.lang.String columnNamePattern)
Sets the regular expression pattern to match on when deciding what attributes ti create in the XMI.

Parameters:
columnNamePattern - The pattern for filtering the column name.

setClassStereotypes

public void setClassStereotypes(java.lang.String classStereotypes)
Sets the stereotype name for the new classes.

Parameters:
classStereotypes - The classStereotypes to set.

setIdentifierStereotypes

public void setIdentifierStereotypes(java.lang.String identifierStereotypes)
Sets the stereotype name for the identifiers on the new classes.

Parameters:
identifierStereotypes - The identifierStereotypes to set.

setColumnTaggedValue

public void setColumnTaggedValue(java.lang.String columnTaggedValue)
Sets the name of the column tagged value to use for storing the name of the column.

Parameters:
columnTaggedValue - The columnTaggedValue to set.

setTableTaggedValue

public void setTableTaggedValue(java.lang.String tableTaggedValue)
Sets the name of the table tagged value to use for storing the name of the table.

Parameters:
tableTaggedValue - The tableTaggedValue to set.

setXmiVersion

public void setXmiVersion(java.lang.String xmiVersion)
Sets the version of XMI that will be produced.

Parameters:
xmiVersion - The xmiVersion to set.

getOrCreatePackage

protected org.omg.uml.modelmanagement.UmlPackage getOrCreatePackage(org.omg.uml.modelmanagement.ModelManagementPackage modelManagementPackage,
                                                                    org.omg.uml.modelmanagement.UmlPackage modelPackage,
                                                                    java.lang.String packageName)
Gets or creates a package having the specified packageName using the given modelManagementPackage, places it on the model and returns the last leaf package.

Parameters:
modelManagementPackage - from which we retrieve the UmlPackageClass to create a UmlPackage.
modelPackage - the root UmlPackage

createClasses

protected void createClasses(java.sql.Connection connection,
                             org.omg.uml.foundation.core.CorePackage corePackage,
                             org.omg.uml.modelmanagement.UmlPackage modelPackage)
                      throws java.sql.SQLException
Creates all classes from the tables found in the schema.

Parameters:
connection - the Connection used to retrieve the schema metadata.
corePackage - the CorePackage instance we use to create the classes.
modelPackage - the package which the classes are added.
Throws:
java.sql.SQLException

createClass

protected org.omg.uml.foundation.core.UmlClass createClass(org.omg.uml.modelmanagement.UmlPackage modelPackage,
                                                           java.sql.DatabaseMetaData metadata,
                                                           org.omg.uml.foundation.core.CorePackage corePackage,
                                                           java.lang.String tableName)
Creates and returns a UmlClass with the given name using the corePackage to create it.

Parameters:
corePackage - used to create the class.
tableName - to tableName for which we'll create the appropriate class.
Returns:
the UmlClass

createAttributes

protected java.util.Collection createAttributes(java.sql.DatabaseMetaData metadata,
                                                org.omg.uml.foundation.core.CorePackage corePackage,
                                                java.lang.String tableName)
                                         throws java.sql.SQLException
Creates and returns a collection of attributes from creating an attribute from every column on the table having the give tableName.

Parameters:
metadata - the DatabaseMetaData from which to retrieve the columns.
corePackage - used to create the class.
tableName - the tableName for which to find columns.
Returns:
the collection of new attributes.
Throws:
java.sql.SQLException

getOrCreateDataType

protected org.omg.uml.foundation.core.DataType getOrCreateDataType(org.omg.uml.foundation.core.CorePackage corePackage,
                                                                   java.lang.String type)
Gets or creates a new data type instance having the given fully qualified type name.

Parameters:
corePackage - the core package
type - the fully qualified type name.
Returns:
the DataType

isColumnNullable

protected boolean isColumnNullable(java.sql.DatabaseMetaData metadata,
                                   java.lang.String tableName,
                                   java.lang.String columnName)
                            throws java.sql.SQLException
This method just checks to see if a column is null able or not, if so, returns true, if not returns false.

Parameters:
metadata - the DatabaseMetaData instance used to retrieve the column information.
tableName - the name of the table on which the column exists.
columnName - the name of the column.
true/false - on whether or not column is nullable.
Throws:
java.sql.SQLException

getPrimaryKeyColumns

protected java.util.Collection getPrimaryKeyColumns(java.sql.DatabaseMetaData metadata,
                                                    java.lang.String tableName)
                                             throws java.sql.SQLException
Returns a collection of all primary key column names for the given tableName.

Parameters:
metadata -
tableName -
Returns:
collection of primary key names.
Throws:
java.sql.SQLException

createAssociations

protected java.util.Collection createAssociations(java.sql.DatabaseMetaData metadata,
                                                  org.omg.uml.foundation.core.CorePackage corePackage,
                                                  java.lang.String tableName)
                                           throws java.sql.SQLException
Creates and returns a collection of associations by determing foreign tables to the table having the given tableName.

Parameters:
metadata - the DatabaseMetaData from which to retrieve the columns.
corePackage - used to create the class.
tableName - the tableName for which to find columns.
Returns:
the collection of new attributes.
Throws:
java.sql.SQLException

createTaggedValue

protected org.omg.uml.foundation.core.TaggedValue createTaggedValue(org.omg.uml.foundation.core.CorePackage corePackage,
                                                                    java.lang.String name,
                                                                    java.lang.String value)
Creates a tagged value given the specfied name.

Parameters:
name - the name of the tagged value to create.
value - the value to populate on the tagged value.
Returns:
returns the new TaggedValue

getOrCreateStereotypes

protected java.util.Collection getOrCreateStereotypes(org.omg.uml.foundation.core.CorePackage corePackage,
                                                      java.lang.String names,
                                                      java.lang.String baseClass)
Gets or creates a stereotypes given the specfied comma seperated list of names. If any of the stereotypes can't be found, they will be created.

Parameters:
names - comma seperated list of stereotype names
baseClass - the base class for which the stereotype applies.
Returns:
Collection of Stereotypes

addForeignKey

protected void addForeignKey(java.lang.String tableName,
                             java.lang.String columnName)
Adds a foreign key column name to the foreignKeys Map. The map stores a collection of foreign key names keyed by the given tableName

Parameters:
tableName - the name of the table for which to store the keys.
columnName - the name of the foreign key column name.

hasForeignKey

protected boolean hasForeignKey(java.lang.String tableName,
                                java.lang.String columnName)
Returns true if the table with the given tableName has a foreign key with the specified columnName.

Parameters:
tableName - the name of the table to check for the foreign key
columnName - the naem of the foreign key column.
Returns:
true/false dependeing on whether or not the table has the foreign key with the given columnName.

createAttributeMultiplicity

protected org.omg.uml.foundation.datatypes.Multiplicity createAttributeMultiplicity(org.omg.uml.foundation.datatypes.DataTypesPackage dataTypes,
                                                                                    boolean required)
Creates an attributes multiplicity, if required is true, then multiplicity is set to 1, if required is false, then multiplicity is set to 0..1.

Parameters:
dataTypes - used to create the Multiplicity
required - whether or not the attribute is required therefore determining the multiplicity value created.
Returns:
the new Multiplicity

createMultiplicity

protected org.omg.uml.foundation.datatypes.Multiplicity createMultiplicity(org.omg.uml.foundation.datatypes.DataTypesPackage dataTypes,
                                                                           int lower,
                                                                           int upper)
Creates a multiplicity, from lower and upper ranges.

Parameters:
dataTypes - used to create the Multiplicity
lower - the lower range of the multiplicity
upper - the upper range of the multiplicity
Returns:
the new Multiplicity


Copyright © 2003-2008 AndroMDA.org. All Rights Reserved.