Class UMLToDDLTransformation

    • Field Detail

      • skipProperties

        private static final java.util.Collection<java.lang.String> skipProperties
      • ORACLE

        public static final com.nomagic.magicdraw.dmn.ce.ddl.DialectManager ORACLE
      • GENERIC

        public static final com.nomagic.magicdraw.dmn.ce.ddl.DialectManager GENERIC
      • ORACLE_HELPER

        public static final com.nomagic.magicdraw.dmn.ce.ddl.DDLModelHelper ORACLE_HELPER
      • GENERIC_HELPER

        public static final com.nomagic.magicdraw.dmn.ce.ddl.DDLModelHelper GENERIC_HELPER
      • mElementsToRemove

        protected java.util.Set<Element> mElementsToRemove
      • mProcessedAssociations

        protected java.util.Set<Element> mProcessedAssociations
      • mTransformationType

        protected int mTransformationType
      • mIsTransformationInPlace

        protected boolean mIsTransformationInPlace
      • mIsUpdate

        protected boolean mIsUpdate
      • mSyncDestination

        protected boolean mSyncDestination
      • mDestination

        protected Package mDestination
      • elementIdentifier

        private com.nomagic.magicdraw.dmn.transformation.ElementIdentifier elementIdentifier
      • processingContext

        private com.nomagic.magicdraw.dmn.transformation.ProcessingContext processingContext
      • rootsMap

        private final com.nomagic.magicdraw.dmn.transformation.uml2ddl.TreeRootsMap rootsMap
      • copyStrategyFactory

        private com.nomagic.magicdraw.dmn.transformation.uml2ddl.copystrategies.ElementsCopyStrategiesFactory copyStrategyFactory
      • originalTransformationMap

        protected java.util.Map<Element,​java.util.Collection<Element>> originalTransformationMap
      • postTransformationElementsToRemove

        protected java.util.Set<Element> postTransformationElementsToRemove
      • selectorDataType

        private DataType selectorDataType
      • charDataType

        private DataType charDataType
      • integerDataType

        private DataType integerDataType
      • exclusionRules

        private java.util.List<OpaqueBehavior> exclusionRules
    • Constructor Detail

      • UMLToDDLTransformation

        public UMLToDDLTransformation()
    • Method Detail

      • getProject

        public Project getProject()
      • removeEntriesFromTransformationMap

        private java.util.Map<Element,​java.util.Collection<Element>> removeEntriesFromTransformationMap​(java.util.Collection<Element> elementsToRemove)
        Clears transformation mapping for specified list of elements
        Parameters:
        elementsToRemove - list of elements which transformation mapping will be cleared
        Returns:
        map of removed elements
      • addRemovedEntities

        private void addRemovedEntities​(java.util.Collection<Element> originalElements,
                                        java.util.Map<Element,​java.util.Collection<Element>> removedElements)
        Adds back removed transformation mapping for specified elements
        Parameters:
        originalElements - list of elements which transformation mapping will be updated
        removedElements - transformation mapping
      • customTransformationForElement

        protected void customTransformationForElement​(Element original,
                                                      java.util.Collection<Element> mapped)
                                               throws ReadOnlyElementException
        Invokes custom transformation for specified original element.
        Overrides:
        customTransformationForElement in class AnyToAnyModelTransformation
        Parameters:
        original - original element.
        mapped - collection of current mapped elements. Custom transformation can modify this collection. In case custom transformation needs to remove current mapping, it should remove element from this collection. In case it needs to map more elements it should add new elements to this collection.
        Throws:
        ReadOnlyElementException - is thrown if processed element is in read-only state
      • translateCommentsToText

        private void translateCommentsToText​(java.util.Collection<Element> mapped)
      • getTransformedComment

        @CheckForNull
        public java.lang.String getTransformedComment​(Element original)
      • translateToText

        private boolean translateToText()
      • autoGeneratePK

        public boolean autoGeneratePK()
      • isMappableElement

        protected boolean isMappableElement​(Element element)
        Checks what source elements can be mapped and processed in destination model
        Overrides:
        isMappableElement in class AnyToAnyModelTransformation
        Parameters:
        element - element to check.
        Returns:
        true if source model element can mapped to destination model
      • transformPackage

        protected void transformPackage​(Package original,
                                        Package target,
                                        java.util.Collection mapped)
                                 throws ReadOnlyElementException
        Transforms package. Flattens or strips from model tree. Does nothing on update.
        Parameters:
        original - original element
        target - mapped element
        mapped - list of mapped elements
        Throws:
        ReadOnlyElementException - this exception is thrown if processed element has read-only status
      • transformLiteralName

        private void transformLiteralName​(EnumerationLiteral targetLiteral)
      • createEnumNameProperty

        private Property createEnumNameProperty​(Enumeration enumeration)
      • setEnumerationPropertySlotValue

        @CheckForNull
        public Slot setEnumerationPropertySlotValue​(Property feature,
                                                    InstanceSpecification instanceSpecification,
                                                    java.lang.Object value,
                                                    boolean addValue)
      • setExpandedEnumerationPropertySlotValue

        @CheckForNull
        public Slot setExpandedEnumerationPropertySlotValue​(Property feature,
                                                            @CheckForNull
                                                            Property expandedType,
                                                            InstanceSpecification instanceSpecification,
                                                            java.lang.Object value,
                                                            boolean addValue)
      • setGeneratedPKSlotValue

        public void setGeneratedPKSlotValue​(EnumerationLiteral literal,
                                            java.util.Collection<Property> pkProperties)
      • makePKColumnsFirst

        private static void makePKColumnsFirst​(EnumerationLiteral literal,
                                               java.util.List<Slot> pkSlots)
      • transformToCheckConstraint

        public boolean transformToCheckConstraint​(Element enumeration)
      • transformTypeToUserDefinedType

        private void transformTypeToUserDefinedType​(DataType original,
                                                    Element target)
      • transformClass

        protected void transformClass​(Class original,
                                      Element target,
                                      java.util.Collection<Element> mapped)
                               throws ReadOnlyElementException
        Transforms classes. Adds PK if such does not exist.
        Parameters:
        original - original element
        target - mapped element
        mapped - contains original element's transformation result
        Throws:
        ReadOnlyElementException - this exception is thrown if processed element has read-only status
      • transformClassifier

        private void transformClassifier​(Classifier original,
                                         Element target,
                                         java.util.Collection<Element> mapped)
      • addTableStereotype

        private void addTableStereotype​(Classifier original,
                                        Element target)
      • markAsRemoved

        public void markAsRemoved​(java.util.Collection<? extends Element> originalElements)
        Adds elements to removed elements list.
        Parameters:
        originalElements - list of elements to be added
      • getTransformedTableStereotype

        protected java.util.List<Stereotype> getTransformedTableStereotype​(Element original)
      • transformAttribute

        protected void transformAttribute​(Property original,
                                          Element target,
                                          java.util.Collection<Element> mapped)
                                   throws ReadOnlyElementException
        Transforms attributes. Adds PK, unique, index constrains if required.
        Parameters:
        original - original attribute
        target - element (attribute or operation)
        mapped - list of all mapped elements
        Throws:
        ReadOnlyElementException - this exception is thrown if processed element has read-only status
      • expandPropertyWithEnum

        public void expandPropertyWithEnum​(java.util.Collection<Element> transformed)
      • getOriginalType

        @CheckForNull
        private Type getOriginalType​(Property transformedProperty)
      • setEnumerationPropertyType

        private void setEnumerationPropertyType​(Property targetProperty)
      • createCheckConstraintForEnum

        public java.util.Collection<Element> createCheckConstraintForEnum​(Property targetProperty)
      • createEnumCheckConstraintBody

        @CheckForNull
        private java.lang.String createEnumCheckConstraintBody​(Property targetProperty)
      • expandPropertyNameWithType

        public java.util.Collection<Property> expandPropertyNameWithType​(Property original,
                                                                         Property target,
                                                                         java.util.Set<Type> processedTypes,
                                                                         com.nomagic.magicdraw.dmn.transformation.uml2ddl.traversal.PropertyExpansion propertyExpansion)
      • generatePropertyName

        public java.lang.String generatePropertyName​(java.lang.String originalPropertyName,
                                                     java.lang.String typePropertyName,
                                                     java.lang.String targetOwnerName)
      • replace

        private static java.lang.String replace​(java.lang.String originalString,
                                                java.lang.String placeholder,
                                                java.lang.String replaceString)
      • getTypeAttributes

        private java.util.List<Property> getTypeAttributes​(Property original,
                                                           java.util.Set<Type> processedTypes,
                                                           com.nomagic.magicdraw.dmn.transformation.uml2ddl.traversal.PropertyExpansion propertyExpansion)
      • expandWithTypeProperties

        public boolean expandWithTypeProperties​(Type type)
      • transformMultiplicity

        private void transformMultiplicity​(Property original,
                                           Property target)
        If property multiplicity is in range of [0..1] (0, 1, 0..1) appropriate null/not null stereotype is added.
        Parameters:
        original - original property used to retrieve multiplicity
        target - transformed property, where null/not null stereotype will be applied
      • hasSameParent

        private boolean hasSameParent​(Property originalProperty,
                                      Property targetProperty)
      • copyMultipleValuesProperty

        private java.util.Collection<Element> copyMultipleValuesProperty​(Property originalProperty,
                                                                         Property transformedProperty,
                                                                         java.util.Collection<Element> transformed)
      • setEnumSlotsForCopiedProperties

        private void setEnumSlotsForCopiedProperties​(Property targetProperty,
                                                     java.util.Collection<? extends Property> properties)
      • copyTransformedProperty

        private java.util.Collection<Element> copyTransformedProperty​(Property originalProperty,
                                                                      Property targetProperty,
                                                                      java.util.Collection<Element> transformed,
                                                                      com.nomagic.magicdraw.dmn.transformation.uml2ddl.UML2DDLCopyPasteManager copyManager,
                                                                      boolean isNull)
        Copies end returns transformed property
        Parameters:
        originalProperty - property which transformed elements will be copied
        targetProperty - target property
        transformed - list of elements to be copied
        copyManager - copy manager
        isNull - indicates if column value can be null
        Returns:
        list of copied elements
      • processKeyProperty

        protected void processKeyProperty​(Element original,
                                          Element target,
                                          Classifier originalOwner,
                                          java.util.Collection<Element> transformed)
        Helper method used to transform key property
        Parameters:
        original - element to be processed
        target - element in transformed model, corresponding to original element
        transformed - list of transformed elements
      • processKey

        protected void processKey​(Element original,
                                  Element target,
                                  java.util.Collection<Element> transformed,
                                  com.nomagic.magicdraw.dmn.transformation.uml2ddl.keys.KeyGenerator generator)
      • findSameElement

        @CheckForNull
        private Element findSameElement​(Element elementToFind)
        Locates 'nearest' transformed element to elementToFind
        Parameters:
        elementToFind - original element, which transformed element must be found
        Returns:
        found 'nearest' transformed element. If element not found, null is returned.
      • transformDiagram

        protected void transformDiagram​(Diagram target)
                                 throws ReadOnlyElementException
        Transform the class diagrams into the DDL diagrams.
        Parameters:
        target - target diagram
        Throws:
        ReadOnlyElementException - this exception is thrown if processed element has read-only status
      • transformGeneralization

        protected void transformGeneralization​(Generalization originalGeneralization,
                                               Element target,
                                               java.util.Collection<Element> mapped)
                                        throws ReadOnlyElementException
        Transforms generalization.
        Parameters:
        originalGeneralization - original generalization
        target - mapped element (generalization or model class)
        mapped - list of all mapped elements
        Throws:
        ReadOnlyElementException - this exception is thrown if processed element has read-only status
      • canHaveConstraint

        public static boolean canHaveConstraint​(Element element)
      • transformAbstraction

        protected void transformAbstraction​(Abstraction original,
                                            Element target,
                                            java.util.Collection<Element> mapped)
                                     throws ReadOnlyElementException
        Transforms abstraction.
        Parameters:
        original - original abstraction
        target - mapped element (abstraction or model class)
        mapped - list of all mapped elements
        Throws:
        ReadOnlyElementException - this exception is thrown if processed element has read-only status
      • transformAssociation

        protected void transformAssociation​(Association original,
                                            Element target,
                                            java.util.Collection<Element> mapped)
                                     throws ReadOnlyElementException
        Transforms association. Adds association table for many-to-many relationships.
        Parameters:
        original - original association
        target - mapped element (association or model class)
        mapped - list of all mapped elements
        Throws:
        ReadOnlyElementException - this exception is thrown if processed element has read-only status
      • getRoot

        public Classifier getRoot​(Classifier element)
        Returns element's root from which it is derived. If element is not part of generalization tree, then root is element itself.
        Parameters:
        element - root of this element will be returned.
        Returns:
        root element. If no root exists, same element as root is returned.
      • setRoot

        public void setRoot​(Classifier element,
                            Classifier root)
        Remembers element's root from which it is derived.
        Parameters:
        element - derived element
        root - element's root
      • hasRootChildren

        public boolean hasRootChildren​(Classifier element)
        Checks if root element has descendant(s).
        Parameters:
        element - to be checked
        Returns:
        true if root element has descendant(s), otherwise false is returned
      • getMappedClassifier

        public Classifier getMappedClassifier​(Element original)
        Returns transformed original element as Classifier.
        Parameters:
        original - element from source model
        Returns:
        element Classifier target. If it does not exists, null is returned
      • getDDLModelHelper

        public com.nomagic.magicdraw.dmn.ce.ddl.DDLModelHelper getDDLModelHelper()
        Returns DDL ModelHelper
        Returns:
        DDL ModelHelper
      • getDiagramType

        private java.lang.String getDiagramType()
        Returns diagram type id
        Returns:
        diagram type id
      • setTransformationType

        public void setTransformationType​(int type)
        Sets transformation type.
        Parameters:
        type - transformation type id
      • getTransformationType

        public int getTransformationType()
        Returns transformation type id
        Returns:
        transformation type id
      • getPackageHierarchyAction

        @CheckForNull
        private java.lang.String getPackageHierarchyAction()
        Returns PackageHierarchy action property
        Returns:
        PackageHierarchy action property
      • getStringProperty

        @CheckForNull
        public java.lang.String getStringProperty​(java.lang.String property)
        Returns string property
        Parameters:
        property - property name
        Returns:
        value
      • getOriginalRoot

        @CheckForNull
        private Package getOriginalRoot​(@CheckForNull
                                        Package element)
        Returns root package of the list
        Parameters:
        element - child package
        Returns:
        root package
      • flattenPackages

        private void flattenPackages​(Package target,
                                     @CheckForNull
                                     Package mappedRoot,
                                     boolean stripPackage)
                              throws ReadOnlyElementException
        Flattens or strips packages.
        Parameters:
        target - model package to flatten or strip
        mappedRoot - root package to move child elements of target
        stripPackage - true for "strip packages"
        Throws:
        ReadOnlyElementException - this exception is thrown if processed element has read-only status
      • hasPackage

        private static boolean hasPackage​(Package mp)
        Checks if model package has child model packages
        Parameters:
        mp - model package to check
        Returns:
        true if has child model package
      • isChildOf

        private static boolean isChildOf​(Element child,
                                         Element parent)
        Checks if model element is child of parent model element
        Parameters:
        child - child element
        parent - parent element
        Returns:
        true if is
      • hasElementWithTheSameName

        private static boolean hasElementWithTheSameName​(Element child,
                                                         Element parent)
        Checks for elements in parent with the same name like element name
        Parameters:
        child - element to check for
        parent - parent element
        Returns:
        true if parent has elements with the same name like child element name
      • renameElement

        private void renameElement​(NamedElement element,
                                   NamedElement parent)
        Renames element
        Parameters:
        element - element name
        parent - parent of element
      • findWithSameName

        @CheckForNull
        private static Element findWithSameName​(Element newElement,
                                                Element newParent)
        Find elements with the same name
        Parameters:
        newElement - element to check
        newParent - parent element to check in
        Returns:
        found element
      • stripAllStereotypes

        protected void stripAllStereotypes​(Element element)
        Strips all stereotypes from model element
        Parameters:
        element - element to strip from
      • stripAllStereotypesByProfile

        protected void stripAllStereotypesByProfile​(@CheckForNull
                                                    Element element,
                                                    @CheckForNull
                                                    Package profile)
        Strips all stereotypes from model element by profile
        Parameters:
        element - element to strip from
        profile - profile model package
      • setEntityPropertiesCopyStrategy

        private void setEntityPropertiesCopyStrategy​(com.nomagic.magicdraw.dmn.transformation.ProcessingContext context,
                                                     PropertyManager manager)
        Retrieves Generalization transformation type, converts it to property copy strategy and set it into processing context
        Parameters:
        context - processing context
        manager - property manager
      • removeNonRootTable

        private boolean removeNonRootTable​(Classifier original)
        Helper method used to check if original table is non root table and must be removed
        Parameters:
        original - table to be checked
        Returns:
        return true if original table must be removed, otherwise false is returned
      • hasSameRoot

        public boolean hasSameRoot​(Classifier element1,
                                   Classifier element2)
        Checks if both elements from generalization tree have same root element.
        Parameters:
        element1 - to be checked
        element2 - to be checked
        Returns:
        true if both have same root element, false - otherwise
      • removeAbstractEntity

        public boolean removeAbstractEntity​(Element entity)
        This method checks if abstract entity must be removed.
        Parameters:
        entity - to be checked
        Returns:
        true if entity is abstract and must be removed, false - otherwise
      • removeMappedElements

        public void removeMappedElements​(java.util.Collection<Element> targetElements)
        Clear transformation elements maps from elements in targetElements
        Parameters:
        targetElements - list of elements to be removed
      • removeMappedElements

        public void removeMappedElements​(Element original,
                                         java.util.Collection<Element> targetElements)
      • getTargetPackage

        public Package getTargetPackage​(Element originalElement)
      • findInCollection

        @CheckForNull
        public <T extends Element> T findInCollection​(java.util.Collection<? extends Element> elements,
                                                      java.lang.String name,
                                                      java.lang.Class<T> classType)
        Helper method that locates element with specified name and type in list of elements
        Parameters:
        elements - list of elements to be searched.
        name - of element to be found
        classType - type of element to be found
        Returns:
        found element, null - if not found
      • getSelectorDataType

        private DataType getSelectorDataType​(PropertyManager pm,
                                             java.lang.String propertyName)
        Retrieves DataType object by it's name
        Parameters:
        pm - property manager
        propertyName - property containing DataType name
        Returns:
        found DataType object. If no DataType with specified name exists, null is returned
      • getDataType

        private DataType getDataType​(java.lang.String typeName)
      • getElementOwner

        @CheckForNull
        public <T extends Element> T getElementOwner​(Element element,
                                                     java.lang.Class<T> type)
        Finds element's owner that is of specified type
        Parameters:
        element - this element's owner will be returned.
        type - owner type
        Returns:
        element's owner, if owner of specified type is not found, null is returned.
      • getOriginalMappedElements

        public java.util.Collection<Element> getOriginalMappedElements​(Element original)
        Returns transformed elements for given original element.
        Parameters:
        original - original element.
        Returns:
        mapped elements if original was mapped; empty collection if original was mapped to nothing;
      • setOriginalElementsMapping

        public void setOriginalElementsMapping​(Element original,
                                               java.util.Collection<Element> elements)
        Sets transformed elements original mapping for given original element.
        Parameters:
        original - original element.
        elements - list of transformed elements to add
      • getElementIdentifier

        public com.nomagic.magicdraw.dmn.transformation.ElementIdentifier getElementIdentifier()
        Returns stereotype mapper that is used to map stereotypes between DDL flavors or DDL and ER. It is useful when different stereotypes refers to same feature.
        Returns:
        stereotype mapper
      • setElementIdentifier

        public void setElementIdentifier​(com.nomagic.magicdraw.dmn.transformation.ElementIdentifier elementIdentifier)
        Sets stereotype mapper that is used to map stereotypes between DDL flavors or DDL and ER. It is useful when different stereotypes refers to same feature.
        Parameters:
        elementIdentifier - new stereotype mapper
      • getProcessingContext

        public com.nomagic.magicdraw.dmn.transformation.ProcessingContext getProcessingContext()
        Returns processing context that is used to contain specific current transformation related data. Also it contains different transformation specific key generators that can be changed dynamically to alter transformation behavior.
        Returns:
        processing context
      • setProcessingContext

        public void setProcessingContext​(com.nomagic.magicdraw.dmn.transformation.ProcessingContext processingContext)
        Sets processing context that is used to contain specific current transformation related data. Also it contains different transformation specific key generators that can be changed dynamically to alter transformation behavior.
        Parameters:
        processingContext - new processing context
      • getSelectorDataType

        public DataType getSelectorDataType()
        Returns selector data type that name is specified in transformation properties and type itself is retrieved from ddl profile.
        Returns:
        selector data type
      • getCopyStrategyFactory

        public com.nomagic.magicdraw.dmn.transformation.uml2ddl.copystrategies.ElementsCopyStrategiesFactory getCopyStrategyFactory()
        Returns transaction specific factory that returns elements copy strategy used to copy elements in generalization tree.
        Returns:
        transaction specific elements copy factory
      • setCopyStrategyFactory

        public void setCopyStrategyFactory​(com.nomagic.magicdraw.dmn.transformation.uml2ddl.copystrategies.ElementsCopyStrategiesFactory copyStrategyFactory)
        Sets transaction specific factory that returns elements copy strategy used to copy elements in generalization tree.
        Parameters:
        copyStrategyFactory - new transaction specific elements copy factory
      • transformElementName

        public java.lang.String transformElementName​(java.lang.String originalName,
                                                     @CheckForNull
                                                     Element namedElement,
                                                     Element target)
      • excludeFromTransformation

        public boolean excludeFromTransformation​(java.lang.Object sourceElement,
                                                 java.util.List<OpaqueBehavior> exclusionRules)
      • getExcludeElementsCallExpression

        private com.nomagic.magicdraw.expressions.specification.CallExpressionSpecification getExcludeElementsCallExpression​(@CheckForNull
                                                                                                                             Element sourceElement,
                                                                                                                             OpaqueBehavior namingRule)
      • getNamingRuleCallExpression

        private com.nomagic.magicdraw.expressions.specification.CallExpressionSpecification getNamingRuleCallExpression​(java.lang.String originalName,
                                                                                                                        Element namedElement,
                                                                                                                        @CheckForNull
                                                                                                                        Element target,
                                                                                                                        OpaqueBehavior namingRule)
      • makeCall

        private java.lang.Object makeCall​(com.nomagic.magicdraw.expressions.specification.CallExpressionSpecification callExpressionSpecification,
                                          ExpressionContext context)
      • getNamingRules

        private java.util.List<OpaqueBehavior> getNamingRules()