public class SchemaTransformer extends Object
| Constructor and Description |
|---|
SchemaTransformer(String jdbcDriver,
String jdbcConnectionUrl,
String jdbcUser,
String jdbcPassword)
Constructs a new instance of this SchemaTransformer.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addForeignKey(String tableName,
String columnName)
Adds a foreign key column name to the
foreignKeys Map. |
protected Collection |
createAssociations(DatabaseMetaData metadata,
org.omg.uml.foundation.core.CorePackage corePackage,
String tableName)
Creates and returns a collection of associations by determining 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 Collection |
createAttributes(DatabaseMetaData metadata,
org.omg.uml.foundation.core.CorePackage corePackage,
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,
DatabaseMetaData metadata,
org.omg.uml.foundation.core.CorePackage corePackage,
String tableName)
Creates and returns a UmlClass with the given
name using
the corePackage to create it. |
protected void |
createClasses(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,
String name,
String value)
Creates a tagged value given the specified
name. |
String |
getMetaColumnColumnSize() |
String |
getMetaColumnDecPlaces() |
String |
getMetaColumnTypeName() |
protected org.omg.uml.foundation.core.DataType |
getOrCreateDataType(org.omg.uml.foundation.core.CorePackage corePackage,
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,
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 Collection |
getOrCreateStereotypes(org.omg.uml.foundation.core.CorePackage corePackage,
String names,
String baseClass)
Gets or creates a stereotypes given the specified comma separated list of
names. |
protected Collection |
getPrimaryKeyColumns(DatabaseMetaData metadata,
String tableName)
Returns a collection of all primary key column names for the given
tableName. |
protected boolean |
hasForeignKey(String tableName,
String columnName)
Returns true if the table with the given
tableName has a
foreign key with the specified columnName. |
protected boolean |
isColumnNullable(DatabaseMetaData metadata,
String tableName,
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 |
setAttributeTaggedValues(String taggedValues) |
void |
setClassStereotypes(String classStereotypes)
Sets the stereotype name for the new classes.
|
void |
setColumnNamePattern(String columnNamePattern)
Sets the regular expression pattern to match on when deciding what attributes
to create in the XMI.
|
void |
setColumnTaggedValue(String columnTaggedValue)
Sets the name of the column tagged value to use for storing the name of
the column.
|
void |
setIdentifierStereotypes(String identifierStereotypes)
Sets the stereotype name for the identifiers on the new classes.
|
void |
setMetaColumnColumnSize(String metaColumnColumnSize) |
void |
setMetaColumnDecPlaces(String metaColumnDecPlaces) |
void |
setMetaColumnTypeName(String metaColumnTypeName) |
void |
setPackageName(String packageName)
Sets the name of the package to which the model elements will be created.
|
void |
setSchema(String schema)
Sets the name of the schema (where the tables can be found).
|
void |
setTableNamePattern(String tableNamePattern)
Sets the regular expression pattern to match on when deciding what table
names to add to the transformed XMI.
|
void |
setTableTaggedValue(String tableTaggedValue)
Sets the name of the table tagged value to use for storing the name of
the table.
|
void |
setTypeMappings(String typeMappingsUri)
Sets the
mappingsUri which is the URI to the sql types to
model type mappings. |
void |
setXmiVersion(String xmiVersion)
Sets the version of XMI that will be produced.
|
void |
transform(String inputModel,
String outputLocation)
Transforms the Schema file and writes it to the location given by
outputLocation. |
public SchemaTransformer(String jdbcDriver, String jdbcConnectionUrl, String jdbcUser, String jdbcPassword)
jdbcDriver - jdbcConnectionUrl - jdbcUser - jdbcPassword - public void transform(String inputModel, String outputLocation)
outputLocation. The inputModel must be a
valid URL, otherwise an exception will be thrown.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.public void setTypeMappings(String typeMappingsUri)
mappingsUri which is the URI to the sql types to
model type mappings.typeMappingsUri - The typeMappings to set.public void setPackageName(String packageName)
packageName - The packageName to set.public void setSchema(String schema)
schema - The schema to set.public void setTableNamePattern(String tableNamePattern)
tableNamePattern - The tableNamePattern to set.public void setColumnNamePattern(String columnNamePattern)
columnNamePattern - The pattern for filtering the column name.public void setClassStereotypes(String classStereotypes)
classStereotypes - The classStereotypes to set.public void setIdentifierStereotypes(String identifierStereotypes)
identifierStereotypes - The identifierStereotypes to set.public void setColumnTaggedValue(String columnTaggedValue)
columnTaggedValue - The columnTaggedValue to set.public void setTableTaggedValue(String tableTaggedValue)
tableTaggedValue - The tableTaggedValue to set.public void setAttributeTaggedValues(String taggedValues)
taggedValues - public void setXmiVersion(String xmiVersion)
xmiVersion - The xmiVersion to set.protected org.omg.uml.modelmanagement.UmlPackage getOrCreatePackage(org.omg.uml.modelmanagement.ModelManagementPackage modelManagementPackage, org.omg.uml.modelmanagement.UmlPackage modelPackage, String packageName)
packageName
using the given modelManagementPackage, places it on the
model and returns the last leaf package.modelManagementPackage - from which we retrieve the UmlPackageClass
to create a UmlPackage.modelPackage - the root UmlPackagepackageName - protected void createClasses(Connection connection, org.omg.uml.foundation.core.CorePackage corePackage, org.omg.uml.modelmanagement.UmlPackage modelPackage) throws SQLException
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.SQLExceptionprotected org.omg.uml.foundation.core.UmlClass createClass(org.omg.uml.modelmanagement.UmlPackage modelPackage, DatabaseMetaData metadata, org.omg.uml.foundation.core.CorePackage corePackage, String tableName)
name using
the corePackage to create it.modelPackage - metadata - corePackage - used to create the class.tableName - to tableName for which we'll create the appropriate
class.protected Collection createAttributes(DatabaseMetaData metadata, org.omg.uml.foundation.core.CorePackage corePackage, String tableName) throws SQLException
tableName.metadata - the DatabaseMetaData from which to retrieve the columns.corePackage - used to create the class.tableName - the tableName for which to find columns.SQLExceptionpublic void setMetaColumnDecPlaces(String metaColumnDecPlaces)
metaColumnDecPlaces - public String getMetaColumnDecPlaces()
public void setMetaColumnColumnSize(String metaColumnColumnSize)
metaColumnColumnSize - public String getMetaColumnColumnSize()
public void setMetaColumnTypeName(String metaColumnTypeName)
metaColumnTypeName - public String getMetaColumnTypeName()
protected org.omg.uml.foundation.core.DataType getOrCreateDataType(org.omg.uml.foundation.core.CorePackage corePackage, String type)
type name.corePackage - the core packagetype - the fully qualified type name.protected boolean isColumnNullable(DatabaseMetaData metadata, String tableName, String columnName) throws SQLException
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.SQLExceptionprotected Collection getPrimaryKeyColumns(DatabaseMetaData metadata, String tableName) throws SQLException
tableName.metadata - tableName - SQLExceptionprotected Collection createAssociations(DatabaseMetaData metadata, org.omg.uml.foundation.core.CorePackage corePackage, String tableName) throws SQLException
tableName.metadata - the DatabaseMetaData from which to retrieve the columns.corePackage - used to create the class.tableName - the tableName for which to find columns.SQLExceptionprotected org.omg.uml.foundation.core.TaggedValue createTaggedValue(org.omg.uml.foundation.core.CorePackage corePackage, String name, String value)
name.corePackage - name - the name of the tagged value to create.value - the value to populate on the tagged value.protected Collection getOrCreateStereotypes(org.omg.uml.foundation.core.CorePackage corePackage, String names, String baseClass)
names. If any of the stereotypes can't be found, they
will be created.corePackage - names - comma separated list of stereotype namesbaseClass - the base class for which the stereotype applies.protected void addForeignKey(String tableName, String columnName)
foreignKeys Map. The
map stores a collection of foreign key names keyed by the given
tableNametableName - the name of the table for which to store the keys.columnName - the name of the foreign key column name.protected boolean hasForeignKey(String tableName, String columnName)
tableName has a
foreign key with the specified columnName.tableName - the name of the table to check for the foreign keycolumnName - the name of the foreign key column.columnName.protected org.omg.uml.foundation.datatypes.Multiplicity createAttributeMultiplicity(org.omg.uml.foundation.datatypes.DataTypesPackage dataTypes, boolean required)
required is true,
then multiplicity is set to 1, if required is false, then
multiplicity is set to 0..1.dataTypes - used to create the Multiplicityrequired - whether or not the attribute is required therefore
determining the multiplicity value created.protected org.omg.uml.foundation.datatypes.Multiplicity createMultiplicity(org.omg.uml.foundation.datatypes.DataTypesPackage dataTypes, int lower, int upper)
lower and upper
ranges.dataTypes - used to create the Multiplicitylower - the lower range of the multiplicityupper - the upper range of the multiplicityCopyright © 2003–2014 AndroMDA.org. All rights reserved.