示例#1
0
        private static SqlPreCommandSimple UpdateByFkChange(string tn, DiffColumn difCol, IColumn tabCol, Func <ObjectName, ObjectName> changeName, Dictionary <ObjectName, ObjectName> copyDataFrom)
        {
            if (difCol.ForeignKey == null || tabCol.ReferenceTable == null || tabCol.AvoidForeignKey)
            {
                return(null);
            }

            ObjectName oldFk = changeName(difCol.ForeignKey.TargetTable);

            if (oldFk.Equals(tabCol.ReferenceTable.Name))
            {
                return(null);
            }

            var newComesFrom = copyDataFrom.TryGetC(tabCol.ReferenceTable.Name);

            if (newComesFrom != null && oldFk.Equals(newComesFrom))
            {
                return(null);
            }

            AliasGenerator ag = new AliasGenerator();

            return(new SqlPreCommandSimple(
                       @"UPDATE {2}
SET {0} =  -- get {5} id from {4}.Id
FROM {1} {2}
JOIN {3} {4} ON {2}.{0} = {4}.Id".FormatWith(tabCol.Name,
                                             tn, ag.NextTableAlias(tn),
                                             oldFk, ag.NextTableAlias(oldFk.Name),
                                             tabCol.ReferenceTable.Name.Name)));
        }
示例#2
0
        private bool RemoveNativeTableSequence(ObjectName tableName)
        {
            // If the Sequence or SequenceInfo tables don't exist then
            // We can't add or remove native tables
            if (tableName.Equals(SystemSchema.SequenceTableName) ||
                tableName.Equals(SystemSchema.SequenceInfoTableName) ||
                !Transaction.ObjectExists(SystemSchema.SequenceTableName) ||
                !Transaction.ObjectExists(SystemSchema.SequenceInfoTableName))
            {
                return(false);
            }

            // The SEQUENCE and SEQUENCE_INFO table
            var seq  = Transaction.GetMutableTable(SystemSchema.SequenceTableName);
            var seqi = Transaction.GetMutableTable(SystemSchema.SequenceInfoTableName);

            var list = seqi.SelectRowsEqual(2, DataObject.VarChar(tableName.Name), 1, DataObject.VarChar(tableName.Parent.FullName));

            // Remove the corresponding entry in the SEQUENCE table
            foreach (var rowIndex in list)
            {
                var sid   = seqi.GetValue(rowIndex, 0);
                var list2 = seq.SelectRowsEqual(0, sid);
                foreach (int rowIndex2 in list2)
                {
                    // Remove entry from the sequence table.
                    seq.RemoveRow(rowIndex2);
                }

                // Remove entry from the sequence info table
                seqi.RemoveRow(rowIndex);
            }

            return(true);
        }
示例#3
0
 public int FindByName(ObjectName name)
 {
     if (HasOldTable &&
         name.Equals(SystemSchema.OldTriggerTableName, transaction.IgnoreIdentifiersCase()))
     {
         return(0);
     }
     if (HasNewTable &&
         name.Equals(SystemSchema.NewTriggerTableName, transaction.IgnoreIdentifiersCase()))
     {
         return(HasOldTable ? 1 : 0);
     }
     return(-1);
 }
 private void Update()
 {
     if (this.enabled)
     {
         if (selectedGameobject != null)
         {
             currentGameObjectScript = selectedGameobject.GetComponent <ResourceBase>();
         }
         if (currentGameObjectScript != selectedGameobject.GetComponent <ResourceBase>())
         {
             currentGameObjectScript = selectedGameobject.GetComponent <ResourceBase>();
         }
         else
         {
             if (!ObjectName.Equals(GetObjectName(selectedGameobject.name)))
             {
                 ObjectName = currentGameObjectScript.ResourceName;
                 this.transform.Find("ObjectName").GetComponent <TextMeshProUGUI>().SetText(ObjectName);
             }
             if (!PatchSize.Equals(currentGameObjectScript.SizeOfTheResource))
             {
                 PatchSize = currentGameObjectScript.SizeOfTheResource;
                 this.transform.Find("PatchSize").GetComponent <TextMeshProUGUI>().SetText(PatchSize.ToString());
             }
             if (!PatchQuantity.Equals(currentGameObjectScript.QuantityOfTheResource))
             {
                 PatchQuantity = currentGameObjectScript.QuantityOfTheResource;
                 this.transform.Find("PatchQuantity").GetComponent <TextMeshProUGUI>().SetText(PatchQuantity.ToString());
             }
         }
     }
 }
示例#5
0
        protected override MergeResult DoMerge(Operation operation)
        {
            if (base.DoMerge(operation) == MergeResult.Stop)
            {
                return(MergeResult.Stop);
            }

            // Ignore object operations that don't operate on this object.
            if (operation is ObjectOperation otherAsObjectOp &&
                !ObjectName.Equals(otherAsObjectOp.ObjectName, StringComparison.InvariantCultureIgnoreCase))
            {
                return(MergeResult.Stop);
            }

            if (operation is RenameObjectOperation otherAsRenameOp)
            {
                // If the object is being renamed.
                if (ObjectName.Equals(otherAsRenameOp.ObjectName, StringComparison.InvariantCultureIgnoreCase))
                {
                    Name = otherAsRenameOp.NewName;
                    otherAsRenameOp.Disabled = true;
                    return(MergeResult.Stop);
                }
            }

            return(MergeResult.Continue);
        }
示例#6
0
        public override bool Equals(SqlType other)
        {
            if (!(other is UserType))
            {
                return(false);
            }

            var otherType = (UserType)other;

            if (!FullName.Equals(otherType.FullName))
            {
                return(false);
            }

            if (MemberCount != otherType.MemberCount)
            {
                return(false);
            }

            for (int i = 0; i < MemberCount; i++)
            {
                var thisMember  = TypeInfo.MemberAt(i);
                var otherMember = otherType.TypeInfo.MemberAt(i);

                if (!thisMember.MemberName.Equals(otherMember.MemberName) ||
                    !thisMember.MemberType.Equals(otherMember.MemberType))
                {
                    return(false);
                }
            }

            return(true);
        }
        public int FindByName(ObjectName name)
        {
            if (HasOldTable &&
                name.Equals(SystemSchema.OldTriggerTableName))
            {
                return(0);
            }

            if (HasNewTable &&
                name.Equals(SystemSchema.NewTriggerTableName))
            {
                return(HasOldTable ? 1 : 0);
            }

            return(-1);
        }
示例#8
0
        /// <inheritdoc/>
        public override int FindFieldName(ObjectName v)
        {
            ObjectName tableName = v.Parent;

            if (tableName != null && tableName.Equals(TableName))
            {
                return(TableInfo.FastFindColumnName(v.Name));
            }
            return(-1);
        }
示例#9
0
        public bool ContainsTable(ObjectName name)
        {
            // This set can not contain the table that is backing it, so we always
            // return false for that.  This check stops an annoying recursive
            // situation for table name resolution.
            if (name.Equals(TableName))
                return false;

            return FindByName(name) != -1;
        }
        /// <summary>
        /// Tries to get an object with the given name formed as table.
        /// </summary>
        /// <param name="transaction">The transaction object.</param>
        /// <param name="tableName">The name of the table to try to get.</param>
        /// <returns>
        /// Returns an instance of <see cref="ITable"/> if an object with the given name was
        /// found in the underlying transaction and it is of <see cref="DbObjectType.Table"/> and
        /// it is <c>not null</c>.
        /// </returns>
        public static ITable GetTable(this ITransaction transaction, ObjectName tableName)
        {
            tableName = ResolveReservedTableName(tableName);

            var tableStateHandler = transaction as ITableStateHandler;

            if (tableStateHandler != null)
            {
                if (tableName.Equals(SystemSchema.OldTriggerTableName, transaction.IgnoreIdentifiersCase()))
                {
                    return(tableStateHandler.TableState.OldDataTable);
                }
                if (tableName.Equals(SystemSchema.NewTriggerTableName, transaction.IgnoreIdentifiersCase()))
                {
                    return(tableStateHandler.TableState.NewDataTable);
                }
            }

            return((ITable)transaction.GetObject(DbObjectType.Table, tableName));
        }
示例#11
0
 /// <inheritdoc/>
 public override int FindFieldName(ObjectName v)
 {
     for (int i = 0; i < aliases.Length; ++i)
     {
         if (v.Equals(aliases[i]))
         {
             return(i);
         }
     }
     return(-1);
 }
示例#12
0
 protected override int IndexOfColumn(ObjectName columnName)
 {
     for (int i = 0; i < aliases.Length; ++i)
     {
         if (columnName.Equals(aliases[i]))
         {
             return(i);
         }
     }
     return(-1);
 }
示例#13
0
        public void EqualsTest()
        {
            ObjectName target = new ObjectName("domain:a=4,b=5,c=6");

            ObjectName other = new ObjectName("domain:a=4,b=5,c=6");

            Assert.IsTrue(target.Equals(other));

            other = new ObjectName("domain:b=5,a=4,c=6");
            Assert.IsTrue(target.Equals(other));

            other = new ObjectName("domain:c=6,b=5,a=4");
            Assert.IsTrue(target.Equals(other));

            Dictionary <string, string> properties = new Dictionary <string, string>();

            properties["a"] = "4";
            properties["b"] = "5";
            properties["c"] = "6";
            other           = new ObjectName("domain", properties);
            Assert.IsTrue(target.Equals(other));
        }
        public override bool Equals(object obj)
        {
            if (!(obj is NotificationSubscriptionKey))
            {
                return(false);
            }
            NotificationSubscriptionKey other = (NotificationSubscriptionKey)obj;

            return(Callback.Equals(other.Callback) &&
                   AreBothNullOrEqual(_filterCallback, other._filterCallback) &&
                   AreBothNullOrEqual(_handback, other._handback) &&
                   ObjectName.Equals(other.ObjectName));
        }
示例#15
0
        public bool ContainsTable(ObjectName name)
        {
            var seqInfo = SequenceManager.SequenceInfoTableName;

            // This set can not contain the table that is backing it, so we always
            // return false for that.  This check stops an annoying recursive
            // situation for table name resolution.
            if (name.Equals(seqInfo))
            {
                return(false);
            }

            return(FindByName(name) != -1);
        }
 private void Update()
 {
     if (this.enabled)
     {
         if (selectedGameobject == null)
         {
             currentGameObjectScript = selectedGameobject.GetComponentInParent <ResourceBuildingsManagment>();
         }
         if (currentGameObjectScript != selectedGameobject.GetComponentInParent <ResourceBuildingsManagment>())
         {
             currentGameObjectScript = selectedGameobject.GetComponentInParent <ResourceBuildingsManagment>();
         }
         else
         {
             if (!ObjectName.Equals(currentGameObjectScript.ChildBuildingTyp.BuildingTyp))
             {
                 ObjectName = currentGameObjectScript.ChildBuildingTyp.BuildingTyp;
                 this.transform.Find("BuildingName").GetComponent <TextMeshProUGUI>().SetText(ObjectName);
             }
             if (!StortedResources.Equals(currentGameObjectScript.StoredResources))
             {
                 StortedResources = currentGameObjectScript.StoredResources[currentGameObjectScript.ChildBuildingTyp.ResourceToGather[GrabTheResourceWithTheLargesValue()]];
                 this.transform.Find("StortedResources").GetComponent <TextMeshProUGUI>().SetText(ResourceWithTheHighestAmount + ": " + StortedResources.ToString());
             }
             if (!ProduktionSpeed.Equals(currentGameObjectScript.ProduktionSpeed))
             {
                 ProduktionSpeed = currentGameObjectScript.ProduktionSpeed;
                 this.transform.Find("ProduktionSpeed").GetComponent <TextMeshProUGUI>().SetText(ProduktionSpeed.ToString());
             }
             if (!WorkingPeopleCapacity.Equals(currentGameObjectScript.WorkingPeopleCapacity))
             {
                 WorkingPeopleCapacity = currentGameObjectScript.WorkingPeopleCapacity;
             }
             if (!WorkingPeople.Equals(currentGameObjectScript.WorkingPeople))
             {
                 WorkingPeople = currentGameObjectScript.WorkingPeople;
                 this.transform.Find("WorkingPeople").GetComponent <TextMeshProUGUI>().SetText(WorkingPeople.ToString() + "/" + WorkingPeopleCapacity.ToString());
             }
             if (!GatheredResourcesOverall.Equals(currentGameObjectScript.GatheredResourcesOverall))
             {
                 GatheredResourcesOverall = currentGameObjectScript.GatheredResourcesOverall;
                 this.transform.Find("GatheredResourcesOverall").GetComponent <TextMeshProUGUI>().SetText(GatheredResourcesOverall.ToString());
             }
         }
     }
 }
示例#17
0
 /// <summary>
 /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
 /// </summary>
 /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
 /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.</returns>
 public override bool Equals(object obj)
 {
     if (obj is CriteriaGet)
     {
         var c = (CriteriaGet)obj;
         if (!ObjectName.Equals(c.ObjectName))
         {
             return(false);
         }
         if (!UICulture.Equals(c.UICulture))
         {
             return(false);
         }
         return(true);
     }
     return(false);
 }
        protected override MergeResult DoMerge(Operation operation)
        {
            if (base.DoMerge(operation) == MergeResult.Stop)
            {
                return(MergeResult.Stop);
            }

            if (operation is RenameOperation otherAsRenameOp &&
                ObjectName.Equals(otherAsRenameOp.ObjectName, StringComparison.InvariantCultureIgnoreCase))
            {
                Name = otherAsRenameOp.NewName;
                otherAsRenameOp.Disabled = true;
                return(MergeResult.Continue);
            }

            return(MergeResult.Continue);
        }
示例#19
0
        private static ObjectName SubstituteAliasedVariable(ObjectName v, IEnumerable <SelectColumn> columns)
        {
            var name = v;

            if (columns != null)
            {
                foreach (SelectColumn scol in columns)
                {
                    if (v.Equals(scol.Alias))
                    {
                        name = scol.InternalName.Clone();
                        break;
                    }
                }
            }

            return(name);
        }
示例#20
0
        protected override MergeResult DoMerge(Operation operation)
        {
            if (base.DoMerge(operation) == MergeResult.Stop)
            {
                return(MergeResult.Stop);
            }

            if (operation is TableObjectOperation otherAsTableObjectOp &&
                !TableObjectName.Equals(otherAsTableObjectOp.TableObjectName,
                                        StringComparison.InvariantCultureIgnoreCase))
            {
                return(MergeResult.Stop);
            }

            // The table this operation is a part of is getting removed so remove the operation.
            if (operation is RemoveTableOperation otherAsRemoveTableOp &&
                TableObjectName.Equals(otherAsRemoveTableOp.ObjectName, StringComparison.InvariantCultureIgnoreCase))
            {
                Disabled = true;
                return(MergeResult.Stop);
            }

            if (operation is RenameObjectOperation otherAsRenameOp)
            {
                // If renaming a table, update objects that use that table.
                if (TableObjectName.Equals(otherAsRenameOp.ObjectName, StringComparison.InvariantCultureIgnoreCase))
                {
                    TableName          = otherAsRenameOp.NewName;
                    operation.Disabled = true;
                    return(MergeResult.Stop);
                }

                if (ObjectName.Equals(otherAsRenameOp.ObjectName, StringComparison.InvariantCultureIgnoreCase))
                {
                    Name = otherAsRenameOp.NewName;
                    operation.Disabled = true;
                    return(MergeResult.Stop);
                }
            }


            return(MergeResult.Continue);
        }
示例#21
0
        private void SetOriginalPathAddExtNameAndObjectName(string originalPath, string objectName)
        {
            if (string.IsNullOrWhiteSpace(originalPath))
            {
                throw new ArgumentException("message", nameof(originalPath));
            }

            if (OriginalPath.Equals(originalPath))
            {
                return;
            }

            OriginalPath = originalPath;
            ExtName      = Path.GetExtension(originalPath);

            objectName = objectName ?? originalPath.ToObjectName();

            if (!ObjectName.Equals(objectName))
            {
                ObjectName = objectName;
            }
        }
示例#22
0
        /// <inheritdoc/>
        public override int FindFieldName(ObjectName v)
        {
            // Check this is the correct table first...
            ObjectName    tableName = v.Parent;
            DataTableInfo tableInfo = TableInfo;

            if (tableName != null && tableName.Equals(TableName))
            {
                // Look for the column name
                string colName = v.Name;
                int    size    = ColumnCount;
                for (int i = 0; i < size; ++i)
                {
                    DataColumnInfo col = tableInfo[i];
                    if (col.Name.Equals(colName))
                    {
                        return(i);
                    }
                }
            }
            return(-1);
        }
 private void Update()
 {
     if (this.enabled)
     {
         if (selectedGameobject == null)
         {
             currentGameObjectScript = selectedGameobject.GetComponent <SocialBuildingManagment>();
         }
         if (currentGameObjectScript != selectedGameobject.GetComponent <SocialBuildingManagment>())
         {
             currentGameObjectScript = selectedGameobject.GetComponent <SocialBuildingManagment>();
         }
         else
         {
             if (!ObjectName.Equals(currentGameObjectScript.SocialBuildingType))
             {
                 ObjectName = currentGameObjectScript.SocialBuildingType;
                 this.transform.Find("ObjectName").GetComponent <TextMeshProUGUI>().SetText(ObjectName);
             }
             if (!BirthRate.Equals(currentGameObjectScript.BirthRate))
             {
                 BirthRate = currentGameObjectScript.BirthRate;
                 this.transform.Find("BirthRate").GetComponent <TextMeshProUGUI>().SetText(BirthRate.ToString());
             }
             if (!PeopleCapacity.Equals(currentGameObjectScript.PeopleCapacity))
             {
                 PeopleCapacity = currentGameObjectScript.PeopleCapacity;
                 this.transform.Find("People").GetComponent <TextMeshProUGUI>().SetText(People.ToString() + "/" + PeopleCapacity.ToString());
             }
             if (!People.Equals(currentGameObjectScript.People))
             {
                 People = currentGameObjectScript.People;
                 this.transform.Find("People").GetComponent <TextMeshProUGUI>().SetText(People.ToString() + "/" + PeopleCapacity.ToString());
             }
         }
     }
 }
示例#24
0
        public override bool Equals(object otherObject)
        {
            if (otherObject == this) {
                return true;
            }

            if (otherObject == null) {
                return false;
            }

            if (GetType() != otherObject.GetType()) {
                return false;
            }

            var other = (ObjectSpec) otherObject;
            if (!ObjectName.Equals(other.ObjectName)) {
                return false;
            }

            if (ObjectParameters.Count != other.ObjectParameters.Count) {
                return false;
            }

            // Compare object parameter by object parameter
            var index = 0;
            foreach (var thisParam in ObjectParameters) {
                var otherParam = other.ObjectParameters[index];
                index++;

                if (!ExprNodeUtilityCompare.DeepEquals(thisParam, otherParam, false)) {
                    return false;
                }
            }

            return true;
        }
示例#25
0
 protected override int IndexOfColumn(ObjectName columnName)
 {
     for (int i = 0; i < aliases.Length; ++i) {
         if (columnName.Equals(aliases[i])) {
             return i;
         }
     }
     return -1;
 }
示例#26
0
 /// <inheritdoc/>
 public override int FindFieldName(ObjectName v)
 {
     for (int i = 0; i < aliases.Length; ++i) {
         if (v.Equals(aliases[i])) {
             return i;
         }
     }
     return -1;
 }
示例#27
0
 public int FindByName(ObjectName name)
 {
     if (HasOldTable &&
         name.Equals(SystemSchema.OldTriggerTableName, transaction.IgnoreIdentifiersCase()))
         return 0;
     if (HasNewTable &&
         name.Equals(SystemSchema.NewTriggerTableName, transaction.IgnoreIdentifiersCase()))
         return HasOldTable ? 1 : 0;
     return -1;
 }
示例#28
0
 public bool Equals(Key other)
 {
     return(objectType == other.objectType &&
            objectName.Equals(other.objectName) &&
            String.Equals(grantee, other.grantee, StringComparison.Ordinal));
 }
        protected override MergeResult DoMerge(Operation operation)
        {
            if (base.DoMerge(operation) == MergeResult.Stop)
            {
                return(MergeResult.Stop);
            }

            // only table object operations that operate on this table are allowed.
            if (operation is TableObjectOperation otherAsTableObjectOp &&
                !ObjectName.Equals(otherAsTableObjectOp.TableObjectName, StringComparison.InvariantCultureIgnoreCase))
            {
                return(MergeResult.Stop);
            }

            switch (operation)
            {
            case AddDefaultConstraintOperation otherAsAddDefaultConstraintOp when !otherAsAddDefaultConstraintOp.WithValues:
            {
                var column = FindColumn(otherAsAddDefaultConstraintOp.ColumnName);
                if (column != null)
                {
                    column.DefaultExpression               = otherAsAddDefaultConstraintOp.Expression;
                    column.DefaultConstraintName           = otherAsAddDefaultConstraintOp.Name;
                    otherAsAddDefaultConstraintOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case AddRowGuidColOperation otherAsAddRowGuidColOp:
            {
                var column = FindColumn(otherAsAddRowGuidColOp.ColumnName);
                if (column != null && column.DataType == DataType.UniqueIdentifier)
                {
                    column.RowGuidCol = true;
                    otherAsAddRowGuidColOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RemoveDefaultConstraintOperation otherAsRemoveDefaultConstraintOp:
            {
                var column = FindColumn(otherAsRemoveDefaultConstraintOp.ColumnName);
                if (column != null)
                {
                    column.DefaultExpression = null;
                    otherAsRemoveDefaultConstraintOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RemoveRowGuidColOperation otherAsRemoveRowGuidColOp:
            {
                var column = FindColumn(otherAsRemoveRowGuidColOp.ColumnName);
                if (column != null && column.DataType == DataType.UniqueIdentifier)
                {
                    column.RowGuidCol = false;
                    otherAsRemoveRowGuidColOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RenameColumnOperation otherAsRenameColumnOp:
            {
                var column = FindColumn(otherAsRenameColumnOp.Name);
                if (column != null)
                {
                    column.Name = otherAsRenameColumnOp.NewName;
                    otherAsRenameColumnOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RenameObjectOperation otherAsRenameObjectOp:
            {
                var column = AddColumns
                             .Concat(UpdateColumns)
                             .FirstOrDefault(c => null != c.DefaultConstraintName &&
                                             c.DefaultConstraintName.Equals(otherAsRenameObjectOp.Name, StringComparison.InvariantCultureIgnoreCase));

                if (null != column)
                {
                    column.DefaultConstraintName   = otherAsRenameObjectOp.NewName;
                    otherAsRenameObjectOp.Disabled = true;
                    return(MergeResult.Stop);
                }

                break;
            }

            case UpdateTableOperation otherAsUpdateTableOp:
            {
                if (otherAsUpdateTableOp.Disabled)
                {
                    return(MergeResult.Stop);
                }

                AddColumns.AddRange(otherAsUpdateTableOp.AddColumns);

                foreach (var addColumn in otherAsUpdateTableOp.AddColumns)
                {
                    for (var thisIdx = RemoveColumns.Count - 1; thisIdx >= 0; --thisIdx)
                    {
                        if (addColumn.Name.Equals(RemoveColumns[thisIdx],
                                                  StringComparison.InvariantCultureIgnoreCase))
                        {
                            RemoveColumns.RemoveAt(thisIdx);
                            break;
                        }
                    }
                }

                foreach (var otherColumn in otherAsUpdateTableOp.UpdateColumns)
                {
                    var found = false;
                    for (var thisIdx = 0; thisIdx < AddColumns.Count; ++thisIdx)
                    {
                        var thisColumn = AddColumns[thisIdx];
                        if (thisColumn.Name.Equals(otherColumn.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found = true;
                            AddColumns[thisIdx] = otherColumn;
                            break;
                        }
                    }

                    for (var thisIdx = 0; thisIdx < UpdateColumns.Count; ++thisIdx)
                    {
                        var thisColumn = UpdateColumns[thisIdx];
                        if (thisColumn.Name.Equals(otherColumn.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found = true;
                            UpdateColumns[thisIdx] = otherColumn;
                            break;
                        }
                    }

                    if (!found)
                    {
                        UpdateColumns.Add(otherColumn);
                    }
                }

                foreach (var columnToRemove in otherAsUpdateTableOp.RemoveColumns)
                {
                    var found = false;
                    for (var thisIdx = AddColumns.Count - 1; thisIdx >= 0; --thisIdx)
                    {
                        var thisColumn = AddColumns[thisIdx];
                        if (thisColumn.Name.Equals(columnToRemove, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found = true;
                            AddColumns.RemoveAt(thisIdx);
                            break;
                        }
                    }

                    for (var thisIdx = UpdateColumns.Count - 1; thisIdx >= 0; --thisIdx)
                    {
                        var thisColumn = UpdateColumns[thisIdx];
                        if (thisColumn.Name.Equals(columnToRemove, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found = true;
                            UpdateColumns.RemoveAt(thisIdx);
                            break;
                        }
                    }

                    if (!found)
                    {
                        RemoveColumns.Add(columnToRemove);
                    }
                }

                otherAsUpdateTableOp.Disabled = true;

                if (AddColumns.Count == 0 && UpdateColumns.Count == 0 && RemoveColumns.Count == 0)
                {
                    Disabled = true;
                    return(MergeResult.Stop);
                }

                return(MergeResult.Continue);
            }
            }

            return(MergeResult.Continue);
        }
 public void RemoveNotificationListener(ObjectName name, NotificationCallback callback)
 {
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     if (callback == null)
     {
         throw new ArgumentNullException("callback");
     }
     var toRemove = _subscriptions.Keys.Where(x => callback.Equals(x.Callback) && name.Equals(x.ObjectName)).ToList();
     foreach (var key in toRemove)
     {
         var listener = _subscriptions[key];
         listener.Dispose();
         _subscriptions.Remove(key);
     }
 }
示例#31
0
 public void SimpleName_Equals()
 {
     var objName1 = new ObjectName("id1");
     var objName2 = new ObjectName("id1");
     Assert.IsTrue(objName1.Equals(objName2));
 }
        protected override MergeResult DoMerge(Operation operation)
        {
            if (base.DoMerge(operation) == MergeResult.Stop)
            {
                return(MergeResult.Stop);
            }

            // only table object operations that operate on this table are allowed.
            if (operation is TableObjectOperation otherAsTableObjectOp &&
                !ObjectName.Equals(otherAsTableObjectOp.TableObjectName, StringComparison.InvariantCultureIgnoreCase))
            {
                return(MergeResult.Stop);
            }

            switch (operation)
            {
            case UpdateTableOperation updateTableOp:
            {
                if (operation.Disabled)
                {
                    return(MergeResult.Stop);
                }

                foreach (var column in updateTableOp.AddColumns)
                {
                    var found = false;
                    for (var idx = 0; idx < Columns.Count; ++idx)
                    {
                        if (Columns[idx].Name.Equals(column.Name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            found        = true;
                            Columns[idx] = column;
                            break;
                        }
                    }

                    if (!found)
                    {
                        Columns.Add(column);
                    }
                }

                for (var idx = 0; idx < Columns.Count; ++idx)
                {
                    var originalColumn = Columns[idx];
                    var updateColumn   = updateTableOp.UpdateColumns.SingleOrDefault(c =>
                                                                                     c.Name.Equals(originalColumn.Name, StringComparison.InvariantCultureIgnoreCase));
                    if (updateColumn != null)
                    {
                        Columns[idx] = updateColumn;
                    }
                }

                foreach (var columnName in updateTableOp.RemoveColumns)
                {
                    var index = Columns.FindIndex(c =>
                                                  c.Name.Equals(columnName, StringComparison.InvariantCultureIgnoreCase));
                    if (index >= 0)
                    {
                        Columns.RemoveAt(index);
                    }
                }

                updateTableOp.Disabled = true;
                return(MergeResult.Continue);
            }

            case RenameColumnOperation renameColumnOp when ObjectName.Equals(renameColumnOp.TableObjectName,
                                                                             StringComparison.InvariantCultureIgnoreCase):
            {
                var column = FindColumn(renameColumnOp.Name);
                if (column != null)
                {
                    column.Name             = renameColumnOp.NewName;
                    renameColumnOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case AddDefaultConstraintOperation addDefaultConstraintOp when !addDefaultConstraintOp.WithValues:
            {
                var column = FindColumn(addDefaultConstraintOp.ColumnName);
                if (column != null)
                {
                    column.DefaultExpression        = addDefaultConstraintOp.Expression;
                    column.DefaultConstraintName    = addDefaultConstraintOp.Name;
                    addDefaultConstraintOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RemoveDefaultConstraintOperation removeDefaultConstraint:
            {
                var column = FindColumn(removeDefaultConstraint.ColumnName);
                if (column != null)
                {
                    column.DefaultExpression         = null;
                    removeDefaultConstraint.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case AddRowGuidColOperation otherAsRowGuidColOp:
            {
                var column = FindColumn(otherAsRowGuidColOp.ColumnName);
                if (column != null && column.DataType == DataType.UniqueIdentifier)
                {
                    column.RowGuidCol            = true;
                    otherAsRowGuidColOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RemoveRowGuidColOperation otherAsRemoveRowGuidColOp:
            {
                var column = FindColumn(otherAsRemoveRowGuidColOp.ColumnName);
                if (column != null && column.DataType == DataType.UniqueIdentifier)
                {
                    column.RowGuidCol = false;
                    otherAsRemoveRowGuidColOp.Disabled = true;
                    return(MergeResult.Continue);
                }

                break;
            }

            case RenameObjectOperation otherAsRenameObjectOp:
            {
                var column = Columns.FirstOrDefault(c => null != c.DefaultConstraintName &&
                                                    c.DefaultConstraintName.Equals(otherAsRenameObjectOp.Name, StringComparison.InvariantCultureIgnoreCase));
                if (null != column)
                {
                    column.DefaultConstraintName   = otherAsRenameObjectOp.NewName;
                    otherAsRenameObjectOp.Disabled = true;
                    return(MergeResult.Stop);
                }

                break;
            }
            }

            return(MergeResult.Continue);
        }
示例#33
0
        private static ObjectName SubstituteAliasedVariable(ObjectName v, IEnumerable<SelectColumn> columns)
        {
            var name = v;

            if (columns != null) {
                foreach (SelectColumn scol in columns) {
                    if (v.Equals(scol.Alias)) {
                        name =scol.InternalName.Clone();
                        break;
                    }
                }
            }

            return name;
        }
示例#34
0
        private bool RemoveNativeTableSequence(ObjectName tableName)
        {
            // If the Sequence or SequenceInfo tables don't exist then
            // We can't add or remove native tables
            if (tableName.Equals(SystemSchema.SequenceTableName) ||
                tableName.Equals(SystemSchema.SequenceInfoTableName) ||
                !Transaction.ObjectExists(SystemSchema.SequenceTableName) ||
                !Transaction.ObjectExists(SystemSchema.SequenceInfoTableName)) {
                return false;
            }

            // The SEQUENCE and SEQUENCE_INFO table
            var seq = Transaction.GetMutableTable(SystemSchema.SequenceTableName);
            var seqi = Transaction.GetMutableTable(SystemSchema.SequenceInfoTableName);

            var list = seqi.SelectRowsEqual(2, DataObject.VarChar(tableName.Name), 1, DataObject.VarChar(tableName.Parent.FullName));

            // Remove the corresponding entry in the SEQUENCE table
            foreach (var rowIndex in list) {
                var sid = seqi.GetValue(rowIndex, 0);
                var list2 = seq.SelectRowsEqual(0, sid);
                foreach (int rowIndex2 in list2) {
                    // Remove entry from the sequence table.
                    seq.RemoveRow(rowIndex2);
                }

                // Remove entry from the sequence info table
                seqi.RemoveRow(rowIndex);
            }

            return true;
        }
        /// <summary>
        /// Tries to get an object with the given name formed as table.
        /// </summary>
        /// <param name="transaction">The transaction object.</param>
        /// <param name="tableName">The name of the table to try to get.</param>
        /// <returns>
        /// Returns an instance of <see cref="ITable"/> if an object with the given name was
        /// found in the underlying transaction and it is of <see cref="DbObjectType.Table"/> and
        /// it is <c>not null</c>.
        /// </returns>
        public static ITable GetTable(this ITransaction transaction, ObjectName tableName)
        {
            tableName = ResolveReservedTableName(tableName);

            var tableStateHandler = transaction as ITableStateHandler;
            if (tableStateHandler != null) {
                if (tableName.Equals(SystemSchema.OldTriggerTableName, transaction.IgnoreIdentifiersCase()))
                    return tableStateHandler.TableState.OldDataTable;
                if (tableName.Equals(SystemSchema.NewTriggerTableName, transaction.IgnoreIdentifiersCase()))
                    return tableStateHandler.TableState.NewDataTable;
            }

            return (ITable) transaction.GetObject(DbObjectType.Table, tableName);
        }
示例#36
0
 public void SimpleName_NotEquals()
 {
     var objName1 = new ObjectName("id1");
     var objName2 = new ObjectName("id2");
     Assert.IsFalse(objName1.Equals(objName2));
 }
        public void RemoveNotificationListener(ObjectName name, NotificationCallback callback)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            var toRemove = _subscriptions.Keys.Where(x => callback.Equals(x.Callback) && name.Equals(x.ObjectName)).ToList();

            foreach (var key in toRemove)
            {
                var listener = _subscriptions[key];
                listener.Dispose();
                _subscriptions.Remove(key);
            }
        }
示例#38
0
        public int FindByName(ObjectName name)
        {
            if (HasOldTable &&
                name.Equals(SystemSchema.OldTriggerTableName))
                return 0;

            if (HasNewTable &&
                name.Equals(SystemSchema.NewTriggerTableName))
                return HasOldTable ? 1 : 0;

            return -1;
        }