protected override void saveMe()
        {
            //create the _wrapped attribute if needed
            if (_wrappedattribute == null)
            {
                if (this._ownerTable._wrappedClass == null)
                {
                    this.ownerTable.save();
                }
                //now the wrappedClass should exist. if not then we have a problem
                this._wrappedattribute = this.factory.modelFactory.createNewElement <TSF_EA.Attribute>(this._ownerTable._wrappedClass, this.name);

                if (this.isNotNullable &&
                    this.ownerTable.primaryKey != null &&
                    this.ownerTable.primaryKey.involvedColumns.Contains(this))
                {
                    //not nullable columns that are not part of a Primary key get "DEFAULT" as default value, which results in "WITH DEFAULT" in the DDL
                    this.initialValue = "DEFAULT";                     //TODO: find a better way to define "DEFAULT" instead of hardcoding.
                }
            }
            if (_wrappedattribute != null)
            {
                //set steretotype
                this._wrappedattribute.setStereotype("column");
                //set datatype;
                _wrappedattribute.type = this.factory.modelFactory.createPrimitiveType(this.type.name);
                if (this.type.type.hasPrecision)
                {
                    _wrappedattribute.precision = this.type.length;
                    _wrappedattribute.scale     = this.type.precision;
                }
                else
                {
                    _wrappedattribute.length = this.type.length;
                }
                //is not nullable
                this.isNotNullable = this.isNotNullable;
                //set position
                this.position = this.position;
                // InitialValue
                this.initialValue = this.initialValue;
                //save
                _wrappedattribute.save();
                //following properties are saved as tagged values so need to be set after saving the wrapped atttribute
                //set isOverridden
                this.isOverridden = this.isOverridden;
                //set renamed
                this.isRenamed = this.isRenamed;
                //logical attribute tag value
                if (traceTaggedValue == null)
                {
                    createTraceTaggedValue();
                }
            }
            //save the columnn name in the alias
            if (logicalAttribute != null)
            {
                logicalAttribute.save();
            }
        }
 // adds an empty column and selects it. user can now select a Data Item.
 // because of magic values in de new empty column, validation will not only
 // validate, but also immediately perform a sync
 private void addEmptyColumn()
 {
     TSF_EA.Attribute attribute =
         this.ui.Addin.Model.factory.createNewElement <TSF_EA.Attribute>(
             this.context, "<new>"
             );
     attribute.AddStereotype("column");
     attribute.save();
     this.context.save();
     this.refreshTree();
     this.selectNewColumn();
 }
예제 #3
0
 public override void save()
 {
     //create the _wrapped attribute if needed
     if (_wrappedattribute == null)
     {
         if (this._ownerTable._wrappedClass == null)
         {
             this.ownerTable.save();
         }
         //now the wrappedClass should exist. if not then we have a problem
         this._wrappedattribute = this.factory.modelFactory.createNewElement <TSF_EA.Attribute>(this._ownerTable._wrappedClass, this.name);
     }
     if (_wrappedattribute != null)
     {
         //set steretotype
         this._wrappedattribute.setStereotype("column");
         //set datatype;
         _wrappedattribute.type = this.factory.modelFactory.createPrimitiveType(this.type.name);
         if (this.type.type.hasPrecision)
         {
             _wrappedattribute.precision = this.type.length;
             _wrappedattribute.scale     = this.type.precision;
         }
         else
         {
             _wrappedattribute.length = this.type.length;
         }
         //is not nullable
         this.isNotNullable = this.isNotNullable;
         //set position
         this.position = this.position;
         // InitialValue
         this.initialValue = this.initialValue;
         //save
         _wrappedattribute.save();
         //following properties are saved as tagged values so need to be set after saving the wrapped atttribute
         //set isOverridden
         this.isOverridden = this.isOverridden;
         //set renamed
         this.isRenamed = this.isRenamed;
         //logical attribute tag value
         if (traceTaggedValue == null)
         {
             createTraceTaggedValue();
         }
     }
     //save the columnn name in the alias
     if (logicalAttribute != null)
     {
         logicalAttribute.save();
     }
 }
        private void linkColumnToDataItem()
        {
            // TODO: this allows for selecting/creating a new table anywhere
            //       currently the TreeView will only be populated with tables
            //       that are within the managed (gloaasry) package.

            // select a table (or create a new one)
            TSF_EA.Class table =
                (TSF_EA.Class) this.ui.Addin.Model.getUserSelectedElement(
                    new List <string>()
            {
                "Class"
            }
                    );
            if (!table.HasStereotype("table"))
            {
                return;
            }

            // create new column on table
            TSF_EA.Attribute attribute =
                this.ui.Addin.Model.factory.createNewElement <TSF_EA.Attribute>(
                    table, "<new>"
                    );
            attribute.AddStereotype("column");
            var context = this.context;

            attribute.save();

            // link the column to the DataItem
            attribute.addTaggedValue("EDD::dataitem", context.guid);
            attribute.save();

            // sync
            this.sync(attribute);

            this.ui.Addin.SelectedItem = context;
        }
        private void sync(TSF_EA.Attribute column)
        {
            DataItem di = this.getDataItem(column);

            column.name = di.Label;
            // TODO DataType
            column.length = di.Size;
            // TODO Format
            // TODO ValueSpecification
            column.defaultValue =
                this.ui.Addin.Model.factory.createValueSpecificationFromString(
                    di.InitialValue
                    );
            var context = this.context;

            column.save();
            this.ui.Addin.SelectedItem = context;
            this.refreshTree();
        }
 public override void save()
 {
     //create the _wrapped attribute if needed
     if (_wrappedattribute == null)
     {
         if (this._owner._wrappedClass == null)
         {
             this.ownerTable.save();
         }
         //now the wrappedClass should exist. if not then we have a problem
         this._wrappedattribute = this.factory.modelFactory.createNewElement <TSF_EA.Attribute>(this._owner._wrappedClass, this.name);
     }
     if (_wrappedattribute != null)
     {
         //set steretotype
         this._wrappedattribute.setStereotype("column");
         //set datatype;
         _wrappedattribute.type      = this.factory.modelFactory.createPrimitiveType(this.type.name);
         _wrappedattribute.length    = this.type.length;
         _wrappedattribute.precision = this.type.precision;
         //is not nullable
         this.isNotNullable = _isNotNullable;
         //save
         _wrappedattribute.save();
         //set isOverridden
         this.isOverridden = this.isOverridden;
         //logical attribute tag value
         if (traceTaggedValue == null)
         {
             createTraceTaggedValue();
         }
     }
     //save the columnn name in the alias
     if (logicalAttribute != null)
     {
         logicalAttribute.save();
     }
 }
        protected override void saveMe()
        {
            //create the _wrapped attribute if needed
            if (_wrappedattribute == null)
            {
                if (this._ownerTable.wrappedClass == null)
                {
                    this.ownerTable.save();
                }
                //now the wrappedClass should exist. if not then we have a problem
                this._wrappedattribute = this.factory.modelFactory.createNewElement <TSF_EA.Attribute>(this._ownerTable.wrappedClass, this.name);

                if (this.logicalAttribute != null)
                {
                    var attributeType = logicalAttribute.type as TSF_EA.ElementWrapper;
                    if (attributeType != null)
                    {
                        //check if attributeType as any constraints
                        var typeConstraint = attributeType.constraints.OfType <TSF_EA.Constraint>().FirstOrDefault();
                        if (typeConstraint != null)
                        {
                            //add a check constraint
                            var checkConstraint = new CheckConstraint(this.name, this, typeConstraint.convertFromEANotes("TXT").Replace("<Column>", this.name));
                            //save?
                            checkConstraint.save();
                        }
                    }
                }
            }
            if (_wrappedattribute != null)
            {
                //set steretotype
                this._wrappedattribute.setStereotype("column");
                //set datatype;
                _wrappedattribute.type = this.factory.modelFactory.createPrimitiveType(this.type.name);
                if (this.type.type != null && this.type.type.hasPrecision)
                {
                    _wrappedattribute.precision = this.type.length;
                    _wrappedattribute.scale     = this.type.precision;
                }
                else
                {
                    _wrappedattribute.length = this.type.length;
                }
                //is not nullable
                this.isNotNullable = this.isNotNullable;
                //set position
                this.position = this.position;
                // InitialValue
                this.initialValue = this.initialValue;
                //save
                _wrappedattribute.save();
                //following properties are saved as tagged values so need to be set after saving the wrapped atttribute
                //set isOverridden
                this.isOverridden = this.isOverridden;
                //set renamed
                this.isRenamed = this.isRenamed;
                //logical attribute tag value
                if (traceTaggedValue == null)
                {
                    createTraceTaggedValue();
                }
            }
            //save the columnn name in the alias
            if (logicalAttribute != null)
            {
                logicalAttribute.save();
            }
        }
        public override void correct()
        {
            //Log start
            EAOutputLogger.log(this.model, this.outputName
                               , string.Format("{0} Starting converting embedded properties to attributes'"
                                               , DateTime.Now.ToLongTimeString())
                               , 0
                               , LogTypeEnum.log);

            //Start converting
            List <TSF_EA.ElementWrapper> properties = this.model.getElementWrappersByQuery(@"select o1.[Object_ID] from [t_object] o1 where o1.[Object_Type] = 'Part'");

            foreach (TSF_EA.Property property in properties)
            {
                //Tell the user which property we are dealing  with
                EAOutputLogger.log(this.model, this.outputName
                                   , string.Format("{0} Correcting property '{1}' with GUID '{2}'"
                                                   , DateTime.Now.ToLongTimeString()
                                                   , property.name
                                                   , property.guid)
                                   , 0
                                   , LogTypeEnum.log);



                if (!string.IsNullOrEmpty(property.name))
                {
                    //Create attribute with the name of the property
                    TSF_EA.Attribute newAttribute = this.model.factory.createNewElement <TSF_EA.Attribute>(property.owner, property.name);

                    if (property.classifier != null)
                    {
                        newAttribute.type = property.classifier;
                    }
                    newAttribute.multiplicity = property.multiplicity;
                    newAttribute.save();


                    //Tell the user which attribute we created
                    EAOutputLogger.log(this.model, this.outputName
                                       , string.Format("{0} Create attribute '{1}' with type '{2}'"
                                                       , DateTime.Now.ToLongTimeString()
                                                       , newAttribute.name
                                                       , newAttribute.type)
                                       , 0
                                       , LogTypeEnum.log);
                }
                else if (property.classifier != null)
                {
                    //Create attribute with the name of the classifier
                    TSF_EA.Attribute newAttribute = this.model.factory.createNewElement <TSF_EA.Attribute>(property.owner, property.classifier.name);

                    newAttribute.type         = property.classifier;
                    newAttribute.multiplicity = property.multiplicity;
                    newAttribute.save();

                    //Tell the user which attribute we created
                    EAOutputLogger.log(this.model, this.outputName
                                       , string.Format("{0} Create attribute '{1}' with type '{2}'"
                                                       , DateTime.Now.ToLongTimeString()
                                                       , newAttribute.name
                                                       , newAttribute.type)
                                       , 0
                                       , LogTypeEnum.log);
                }
                else
                {
                    //Alert the user that we couldn't create the attribute
                    EAOutputLogger.log(this.model, this.outputName
                                       , string.Format("{0} Could not create attribute for property with id '{1}'"
                                                       , DateTime.Now.ToLongTimeString()
                                                       , property.guid
                                                       )
                                       , property.id
                                       , LogTypeEnum.error);
                    //stop processing
                    break;
                }
                //Delete property
                property.delete();
            }



            //Log Finished
            EAOutputLogger.log(this.model, this.outputName
                               , string.Format("{0} Finished converting embedded properties to attributes'"
                                               , DateTime.Now.ToLongTimeString())
                               , 0
                               , LogTypeEnum.log);
        }