Esempio n. 1
0
 public void compare()
 {
     this.comparedItems = new List <DatabaseItemComparison>();
     //compare each new table
     foreach (var newTable in _newDatabase.tables)
     {
         Table existingTable = null;
         if (_existingDatabase != null)
         {
             existingTable = (Table)_existingDatabase.getCorrespondingTable(newTable);
         }
         var comparedItem = new EADatabaseItemComparison(newTable, existingTable);
         addToComparison(comparedItem);
         this.addComparisonDetails(comparedItem);
     }
     if (_existingDatabase != null)
     {
         //get existing tables that don't exist in the new database
         foreach (var existingTable in _existingDatabase.tables)
         {
             //if the existingTable does not exist in the comparedItems then add it.
             if (!comparedItems.Any(x => x.existingDatabaseItem == existingTable))
             {
                 var comparedItem = new EADatabaseItemComparison(null, existingTable);
                 addToComparison(comparedItem);
                 this.addComparisonDetails(comparedItem);
             }
         }
     }
 }
Esempio n. 2
0
        public DatabaseItemComparison addOwnedComparison(DB.DatabaseItem existingItem, DB.DatabaseItem newItem)
        {
            var newComparison = new EADatabaseItemComparison(existingItem, newItem);

            this.ownedComparisons.Add(newComparison);
            newComparison.ownerComparison = this;
            return(newComparison);
        }
Esempio n. 3
0
        private void addTableComparison(EADatabaseItemComparison tableComparison)
        {
            addToComparison(tableComparison);
            var tableComparisons = this.addComparisonDetails(tableComparison);

            //add them to the comparison
            addToComparison(tableComparisons);
        }
Esempio n. 4
0
        public override bool Equals(object obj)
        {
            EADatabaseItemComparison other = obj as EADatabaseItemComparison;

            if (other == null)
            {
                return(false);
            }
            bool existingEqual = false;
            bool newEqual      = false;

            existingEqual = (this.existingDatabaseItem != null && this.existingDatabaseItem.Equals(other.existingDatabaseItem)) ||
                            this.existingDatabaseItem == null && other.existingDatabaseItem == null;
            newEqual = (this.newDatabaseItem != null && this.newDatabaseItem.Equals(other.newDatabaseItem)) ||
                       this.newDatabaseItem == null && other.newDatabaseItem == null;
            return(existingEqual && newEqual);
        }
Esempio n. 5
0
        private void addTableComparison(EADatabaseItemComparison tableComparison)
        {
            string tableName = null;

            if (tableComparison.existingDatabaseItem != null)
            {
                tableName = tableComparison.existingDatabaseItem.name;
            }
            else if (tableComparison.newDatabaseItem != null)
            {
                tableName = tableComparison.newDatabaseItem.name;
            }
            if (!string.IsNullOrEmpty(tableName))
            {
                EAOutputLogger.log(string.Format("Comparing table {0}", tableName));
            }
            addToComparison(tableComparison);
            var tableComparisons = this.addComparisonDetails(tableComparison);

            //add them to the comparison
            addToComparison(tableComparisons);
        }
Esempio n. 6
0
        public List <DatabaseItemComparison> addComparisonDetails(EADatabaseItemComparison comparedItem)
        {
            List <DatabaseItemComparison> addedComparedItems = new List <DatabaseItemComparison>();
            var existingTable = comparedItem.existingDatabaseItem as Table;
            var newTable      = comparedItem.newDatabaseItem as Table;

            if (existingTable != null)
            {
                List <Column> alreadMappedcolumns = new List <Column>();
                //add all existing columns
                foreach (Column existingColumn in existingTable.columns.OrderBy(x => x.position))
                {
                    Column newColumn = null;
                    if (newTable != null)
                    {
                        newColumn = newTable.getCorrespondingColumn(existingColumn, alreadMappedcolumns);
                        //in case the existing column is derived from another table then we add the column the new table
                        if (newColumn == null)
                        {
                            newColumn = getRemoteColumn(existingColumn, newTable, alreadMappedcolumns);
                        }
                    }
                    if (newColumn != null)
                    {
                        alreadMappedcolumns.Add(newColumn);
                    }
                    addedComparedItems.Add(comparedItem.addOwnedComparison(newColumn, existingColumn));
                }
                //now the new columns that don't have a corresponding existing column
                if (newTable != null)
                {
                    Dictionary <Column, Column> columnsToDelete = new Dictionary <Column, Column>();
                    foreach (Column newColumn in newTable.columns)
                    {
                        //if not already mapped
                        if (addedComparedItems.All(x => x.newDatabaseItem != newColumn))
                        {
                            //and there is no other column with the same name that maps to the same physical column and has exactly the same properties and name
                            var duplicateColumns = addedComparedItems.Where(y =>
                                                                            y.existingDatabaseItem is DB_EA.Column &&
                                                                            y.existingDatabaseItem.logicalElements.Contains(newColumn.logicalElement) &&
                                                                            y.newDatabaseItem is DB_EA.Column &&
                                                                            (y.newDatabaseItem.name == newColumn.name || y.existingDatabaseItem.isRenamed) &&         // fix 4. GBTOA25.SEQ_NO
                                                                            ((Column)y.newDatabaseItem).type?.name == newColumn.type?.name)
                                                   .Select(z => z.newDatabaseItem as Column);
                            if (duplicateColumns.Any())
                            {
                                //a duplicate is already compared. remove this one from the table
                                columnsToDelete.Add(newColumn, duplicateColumns.First());
                            }
                            else
                            {
                                //no duplicates so add to the comparison
                                addedComparedItems.Add(comparedItem.addOwnedComparison(newColumn, null));
                            }
                        }
                    }
                    //actually remove the duplicate columns
                    foreach (var columnToDelete in columnsToDelete.Keys)
                    {
                        columnToDelete.ownerTable.removeColumn(columnToDelete, columnsToDelete[columnToDelete]);
                    }
                }
                //add all foreignkeys
                foreach (ForeignKey existingForeignkey in existingTable.foreignKeys)
                {
                    ForeignKey newForeignkey = null;
                    if (newTable != null)
                    {
                        newForeignkey = newTable.getCorrespondingForeignKey(existingForeignkey);
                    }
                    addedComparedItems.Add(comparedItem.addOwnedComparison(newForeignkey, existingForeignkey));
                }
                //then add the new foreign keys that don't have an existing foreign key
                if (newTable != null)
                {
                    foreach (var newForeignkey in newTable.foreignKeys)
                    {
                        if (addedComparedItems.All(x => x.newDatabaseItem != newForeignkey))
                        {
                            addedComparedItems.Add(comparedItem.addOwnedComparison(newForeignkey, null));
                        }
                    }
                }
                //add the primary key comparison

                var           existingPrimaryKey = existingTable.primaryKey;
                DB.PrimaryKey newPrimaryKey      = newTable != null ? newTable.primaryKey : null;
                addedComparedItems.Add(comparedItem.addOwnedComparison(newPrimaryKey, existingPrimaryKey));
            }
            else
            {
                //no existing table, everything is new
                foreach (var newColumn in newTable.columns)
                {
                    addedComparedItems.Add(comparedItem.addOwnedComparison(newColumn, null));
                }
                foreach (var newForeignkey in newTable.foreignKeys)
                {
                    addedComparedItems.Add(comparedItem.addOwnedComparison(newForeignkey, null));
                }
                //add the primary key
                if (newTable.primaryKey != null)
                {
                    addedComparedItems.Add(comparedItem.addOwnedComparison(newTable.primaryKey, null));
                }
            }
            return(addedComparedItems);
        }
Esempio n. 7
0
        public void addComparisonDetails(EADatabaseItemComparison comparedItem)
        {
            List <DatabaseItemComparison> addedComparedItems = new List <DatabaseItemComparison>();
            var existingTable = comparedItem.existingDatabaseItem as Table;
            var newTable      = comparedItem.newDatabaseItem as Table;

            if (existingTable != null)
            {
                //add all existing columns
                foreach (Column existingColumn in existingTable.columns)
                {
                    Column newColumn = null;
                    if (newTable != null)
                    {
                        newColumn = newTable.getCorrespondingColumn(existingColumn);
                    }
                    addedComparedItems.Add(new EADatabaseItemComparison(newColumn, existingColumn));
                }
                //now the new columns that don't have a corresponding existing column
                if (newTable != null)
                {
                    foreach (Column newColumn in newTable.columns)
                    {
                        if (!addedComparedItems.Any(x => x.newDatabaseItem == newColumn))
                        {
                            addedComparedItems.Add(new EADatabaseItemComparison(newColumn, null));
                        }
                    }
                }
                //add all existing constraints
                foreach (var existingConstraint in existingTable.constraints)
                {
                    Constraint newConstraint = null;
                    if (newTable != null)
                    {
                        if (existingConstraint is ForeignKey)
                        {
                            newConstraint = newTable.getCorrespondingForeignKey((ForeignKey)existingConstraint);
                        }
                        else
                        {
                            newConstraint = (Constraint)newTable.primaryKey;
                        }
                        addedComparedItems.Add(new EADatabaseItemComparison(newConstraint, existingConstraint));
                    }
                }
                //then add the new constraints don't have a corresponding existing constraint
                if (newTable != null)
                {
                    foreach (var newConstraint in newTable.constraints)
                    {
                        if (!addedComparedItems.Any(x => x.newDatabaseItem == newConstraint))
                        {
                            addedComparedItems.Add(new EADatabaseItemComparison(newConstraint, null));
                        }
                    }
                }
            }
            else
            {
                //no existing table, everything is new
                foreach (var newColumn in newTable.columns)
                {
                    addedComparedItems.Add(new EADatabaseItemComparison(newColumn, null));
                }
                foreach (var newConstraint in newTable.constraints)
                {
                    addedComparedItems.Add(new EADatabaseItemComparison(newConstraint, null));
                }
            }

            //add the new compared items
            addToComparison(addedComparedItems);
        }