Dresden OCL Toolkit

tudresden.ocl.sql
Class ORMappingImp

java.lang.Object
  extended bytudresden.ocl.sql.ORMappingImp
All Implemented Interfaces:
ORMapping

public class ORMappingImp
extends Object
implements ORMapping

An implementation of the ORMapping interface. It generates a number of tables for classes and associations according some rules that are parameterized. The source of the object oriented information is a Model object that must be of rough quality. The rules are as follows:

  1. Classes map to one ore more tables according to the parameter classToTableMode.
  2. The class tables are going to get a primary key consisting of a certain number of columns (numOfPKCols) of a specified datatype (pKColTypeName). All primary key columns have the same datatype. The keys follow the existence based approach and are going to be inherited throughout an inheritance hierarchy.
  3. Associations map to tables and foreign key references. It can be an association table for each association regardless the multiplicity or as follows:
  4. Attributes map to columns according to the class to table strategy. Complex attributes are going to be mapped to a table. The table's primary key then is referenced if the attribute is member of a class. That is, complex attributes are treated as if they were objects with an directed one-to-one association to them.

Author:
Sten Loecher
See Also:
Model

Field Summary
private  HashMap addAssEnds
          Maps class names to a Map (key-type String, element-type String) of association ends that result from the treatment of complex attributes.
static String ASSTABNAME
           
private  HashMap classesToTables
          Maps class names to a List of table names (the element type of the List is String).
private  int classToTableMode
          Mapping mode for classes to tables.
static String JAVATYPES
           
private  HashMap navGuides
          Maps class names to a Map of navigation guides.
private  int numOfPKCols
          The number of desired primary key columns (default is 1).
private  boolean oneTablePerAssociation
          The flag to determine whether each association is mapped to a separate table or not (default is no or rather false).
static String PACKID
           
private  String pKColTypeName
          The type name of the primary key columns (default is int).
static String PRIMKEYNAME
           
static String SEPARATOR
           
private  ArrayList tables
          An array that contains all the tables from the object relational mapping.
private  Model theModel
          The model containing the object oriented information.
 
Constructor Summary
ORMappingImp(Model theModel)
          A constructor to create the object relational mapping informations.
ORMappingImp(Model theModel, int classToTableMode, int numOfPKCols, String pKColTypeName, boolean oneTablePerAssociation)
          A constructor to create the object relational mapping informations.
 
Method Summary
 Map associationEnds(String classifier)
           
 Set attributes(String classifier)
           
private  Set buryForeignKeys(List pkTables, List fkTables, String assEndName, Set fkSet)
          Buries the primary keys of the pkTables to all fkTables as foreign keys.
 Set classifiers()
           
private  void createClassTables()
          Creates all the class tables with respect to the mapping mode.
private  List createGuideList(ModelClass startClass, ModelClass endClass, Table assTab, boolean nTo1, Set fkSet)
           
 Set directSupertypeNames(String classifier)
           
private  void generatePrimaryKeys()
          Generates the primary keys for all classes.
private  Map getAssEndMap(ModelClass mc)
          Helper methode.
private  String getAssociationName(ModelAssociation ma)
          Helper methode.
private  String getClassName(ModelClass mc)
          Important: does not care about package names yet !
 List getClassTables(String classifier)
           
private  String getColumnName(String attName, Table table)
          Mapping of attribute names to column names.
private  String getForeignKeyString(Table fkTable, Table pkTable, Set fkSet)
          Helper methode.
private  String getPrimaryKeyString(Table t)
          Helper methode.
 Table getTable(String tabName)
           
private  List getTableList(List tableNames)
           
private  String getTableName(ModelClass mc)
          Mapping of class names to table names.
private  String getTableName(String className)
          Mapping of class names to table names.
 List getTables(List tabNames)
           
 Map guidesToAssociationEnds(String classifier)
           
 List guidesToAssociationEnds(String classifier, String assEnd)
           
private  boolean isJavaType(String typeName)
           
private  boolean isPackageMember(String typeName)
           
private  void mapAssociations()
          Mapping of Associations to foreign key relations and association tables.
private  void mapAttributes()
          Mapping of the attributes for all classes.
private  void mapClassAttributes(ModelClass mc)
          Does the attribute mapping for one class.
private  void mapClassToTable(ModelClass mc)
          Maps one class to one table.
 Set operations(String classifier)
           
 List tables()
           
 void testBuryForeignKeys(boolean verbose)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

theModel

private Model theModel
The model containing the object oriented information.


tables

private ArrayList tables
An array that contains all the tables from the object relational mapping.


classesToTables

private HashMap classesToTables
Maps class names to a List of table names (the element type of the List is String).


navGuides

private HashMap navGuides
Maps class names to a Map of navigation guides. The map of navigation guides maps role names to the actual guides (key-type String, element-type Guide).


addAssEnds

private HashMap addAssEnds
Maps class names to a Map (key-type String, element-type String) of association ends that result from the treatment of complex attributes.


classToTableMode

private int classToTableMode
Mapping mode for classes to tables. Possible values are:
0 - use one table for an entire class hierarchy
1 - use one table per leaf class
2 - use one table per class (which is the default)


numOfPKCols

private int numOfPKCols
The number of desired primary key columns (default is 1).


pKColTypeName

private String pKColTypeName
The type name of the primary key columns (default is int).


oneTablePerAssociation

private boolean oneTablePerAssociation
The flag to determine whether each association is mapped to a separate table or not (default is no or rather false).


JAVATYPES

public static String JAVATYPES

PRIMKEYNAME

public static String PRIMKEYNAME

ASSTABNAME

public static String ASSTABNAME

PACKID

public static String PACKID

SEPARATOR

public static String SEPARATOR
Constructor Detail

ORMappingImp

public ORMappingImp(Model theModel)
             throws IllegalArgumentException
A constructor to create the object relational mapping informations. This constructor uses default parameters for the mapping.

Parameters:
theModel - a model for which isRough() must hold
Throws:
IllegalArgumentException - if the theModel.isRough() evaluates to false

ORMappingImp

public ORMappingImp(Model theModel,
                    int classToTableMode,
                    int numOfPKCols,
                    String pKColTypeName,
                    boolean oneTablePerAssociation)
             throws IllegalArgumentException
A constructor to create the object relational mapping informations. This constructor uses the given parameters for the mapping.

Parameters:
theModel - a model for which isRough() must hold
classToTableMode - see field description of classToTableMode
numOfPKCols - see field description of numOfPKCols
pKColTypeName - see field description of pKColTypeName
oneTablePerAssociation - see field description of oneTablePerAssociation
Throws:
IllegalArgumentException - if the theModel.isRough() evaluates to false or the parameters are not valid
Method Detail

tables

public List tables()
Specified by:
tables in interface ORMapping
Returns:
a List with all table objects created during the object relational mapping
See Also:
Table

getClassTables

public List getClassTables(String classifier)
                    throws IllegalArgumentException
Specified by:
getClassTables in interface ORMapping
Parameters:
classifier - a classifier
Returns:
a List with all table objects the classifier was mapped to
Throws:
IllegalArgumentException
See Also:
Table

classifiers

public Set classifiers()
Specified by:
classifiers in interface ORMapping
Returns:
a Set containing the names of all classifiers

directSupertypeNames

public Set directSupertypeNames(String classifier)
Specified by:
directSupertypeNames in interface ORMapping
Parameters:
classifier - a classifier
Returns:
a Set containing all the names of direct supertypes of the classifier

associationEnds

public Map associationEnds(String classifier)
Specified by:
associationEnds in interface ORMapping
Parameters:
classifier - a classifier
Returns:
a Map that maps the names of all association ends to the according class name

guidesToAssociationEnds

public Map guidesToAssociationEnds(String classifier)

operations

public Set operations(String classifier)
Specified by:
operations in interface ORMapping
Parameters:
classifier - a classifier
Returns:
a Set containing all names of operations that are properties of the classifier

attributes

public Set attributes(String classifier)
Specified by:
attributes in interface ORMapping
Parameters:
classifier - a classifier
Returns:
a Set containing all names of attributes that are properties of the classifier

guidesToAssociationEnds

public List guidesToAssociationEnds(String classifier,
                                    String assEnd)
Specified by:
guidesToAssociationEnds in interface ORMapping
Parameters:
classifier - a classifier
assEnd - the name of the association end
Returns:
a List that contains guides to to the specified association end from the classifier
See Also:
Guide

createClassTables

private void createClassTables()
Creates all the class tables with respect to the mapping mode.


generatePrimaryKeys

private void generatePrimaryKeys()
Generates the primary keys for all classes.


mapClassAttributes

private void mapClassAttributes(ModelClass mc)
Does the attribute mapping for one class.

Parameters:
mc - the model class

mapAttributes

private void mapAttributes()
Mapping of the attributes for all classes.


mapAssociations

private void mapAssociations()
Mapping of Associations to foreign key relations and association tables.


isJavaType

private boolean isJavaType(String typeName)
Parameters:
typeName - a type name
Returns:
true if typeName is a Java predefined type

isPackageMember

private boolean isPackageMember(String typeName)
Parameters:
typeName - a type name
Returns:
true if typeName is a Package member, false otherwise

mapClassToTable

private void mapClassToTable(ModelClass mc)
Maps one class to one table.

Parameters:
mc - the class

getTableName

private String getTableName(String className)
Mapping of class names to table names.


getTableName

private String getTableName(ModelClass mc)
Mapping of class names to table names.


getClassName

private String getClassName(ModelClass mc)
Important: does not care about package names yet !

Returns:
the Name of the class to work with

getColumnName

private String getColumnName(String attName,
                             Table table)
Mapping of attribute names to column names.


getTable

public Table getTable(String tabName)
               throws NoSuchElementException
Returns:
the related table object
Throws:
NoSuchElementException

getTableList

private List getTableList(List tableNames)
                   throws NoSuchElementException
Parameters:
tableNames - a List with table names
Returns:
a List that contains the actual tables related to the table names
Throws:
NoSuchElementException - if a table to a given name does not exist

getTables

public List getTables(List tabNames)
Returns:
a List with all related table object
Throws:
NoSuchElementException - if one of the tables does not exist

createGuideList

private List createGuideList(ModelClass startClass,
                             ModelClass endClass,
                             Table assTab,
                             boolean nTo1,
                             Set fkSet)
Parameters:
startClass - the class to start from
endClass - the class to lead to
assTab - a possible association Table or null, if such a table does not exist
nTo1 - a flag that indicates whether the association is a many-to-one association or not
fkSet - a Set of foreign key names that belong to the association

getPrimaryKeyString

private String getPrimaryKeyString(Table t)
Helper methode.


getForeignKeyString

private String getForeignKeyString(Table fkTable,
                                   Table pkTable,
                                   Set fkSet)
Helper methode.


getAssEndMap

private Map getAssEndMap(ModelClass mc)
Helper methode.


getAssociationName

private String getAssociationName(ModelAssociation ma)
Helper methode.


buryForeignKeys

private Set buryForeignKeys(List pkTables,
                            List fkTables,
                            String assEndName,
                            Set fkSet)
Buries the primary keys of the pkTables to all fkTables as foreign keys. If pkTables size is greater than one, the number of the according buried foreign keys is related to the actual number of pkTables. That is, for each pkTable a foreign key will be added to the foreign key Tables.

Parameters:
pkTables - a List of tables which contain the primary keys
fkTables - a List of tables to which the foreign keys are going to be buried
assEndName - the name of the association end which belongs to the pkTables
fkSet - a Set as initialization for the result Set
Returns:
a List of Strings that contains the names of all buried keys

testBuryForeignKeys

public void testBuryForeignKeys(boolean verbose)
                         throws RuntimeException
Throws:
RuntimeException

Dresden OCL Toolkit

Submit a bug
Developed at the Dresden University of Technology.
This software is published under the GNU Lesser General Public License.