Пример #1
0
 internal void ConstraintIndexClear()
 {
     if (null != _constraintIndex)
     {
         _constraintIndex.RemoveRef();
         _constraintIndex = null;
     }
 }
Пример #2
0
        internal void UnregisterListChangedEvent()
        {
            Index index = _index;

            _index = null;

            if (index != null)
            {
                lock (index) {
                    index.ListChangedRemove(this);
                    if (index.RemoveRef() <= 1)
                    {
                        index.RemoveRef();
                    }
                }
            }
        }
Пример #3
0
        internal void MergeRows(DataRow[] rows)
        {
            DataTable dst                = null;
            DataTable src                = null;
            DataKey   srcKey             = new DataKey();
            Index     ndx                = null;
            bool      enforceConstraints = this.dataSet.EnforceConstraints;

            this.dataSet.EnforceConstraints = false;
            for (int i = 0; i < rows.Length; i++)
            {
                DataRow row = rows[i];
                if (row == null)
                {
                    throw ExceptionBuilder.ArgumentNull("rows[" + i + "]");
                }
                if (row.Table == null)
                {
                    throw ExceptionBuilder.ArgumentNull("rows[" + i + "].Table");
                }
                if (row.Table.DataSet != this.dataSet)
                {
                    if (src != row.Table)
                    {
                        src = row.Table;
                        dst = this.MergeSchema(row.Table);
                        if (dst == null)
                        {
                            this.dataSet.EnforceConstraints = enforceConstraints;
                            return;
                        }
                        if (dst.primaryKey != null)
                        {
                            srcKey = this.GetSrcKey(src, dst);
                        }
                        if (srcKey.HasValue)
                        {
                            if (ndx != null)
                            {
                                ndx.RemoveRef();
                                ndx = null;
                            }
                            ndx = new Index(dst, dst.primaryKey.Key.GetIndexDesc(), DataViewRowState.OriginalRows | DataViewRowState.Added, null);
                            ndx.AddRef();
                            ndx.AddRef();
                        }
                    }
                    if ((row.newRecord != -1) || (row.oldRecord != -1))
                    {
                        DataRow targetRow = null;
                        if ((0 < dst.Rows.Count) && (ndx != null))
                        {
                            targetRow = dst.FindMergeTarget(row, srcKey, ndx);
                        }
                        targetRow = dst.MergeRow(row, targetRow, this.preserveChanges, ndx);
                        if ((targetRow.Table.dependentColumns != null) && (targetRow.Table.dependentColumns.Count > 0))
                        {
                            targetRow.Table.EvaluateExpressions(targetRow, DataRowAction.Change, null);
                        }
                    }
                }
            }
            if (ndx != null)
            {
                ndx.RemoveRef();
                ndx = null;
            }
            this.dataSet.EnforceConstraints = enforceConstraints;
        }
Пример #4
0
        internal void MergeRows(DataRow[] rows)
        {
            DataTable src       = null;
            DataTable dst       = null;
            DataKey   key       = default(DataKey);
            Index     ndxSearch = null;

            bool fEnforce = dataSet.EnforceConstraints;

            dataSet.EnforceConstraints = false;

            for (int i = 0; i < rows.Length; i++)
            {
                DataRow row = rows[i];

                if (row == null)
                {
                    throw ExceptionBuilder.ArgumentNull("rows[" + i + "]");
                }
                if (row.Table == null)
                {
                    throw ExceptionBuilder.ArgumentNull("rows[" + i + "].Table");
                }

                //somebody is doing an 'automerge'
                if (row.Table.DataSet == dataSet)
                {
                    continue;
                }

                if (src != row.Table)                       // row.Table changed from prev. row.
                {
                    src = row.Table;
                    dst = MergeSchema(row.Table);
                    if (dst == null)
                    {
                        Debug.Assert(MissingSchemaAction.Ignore == missingSchemaAction, "MergeSchema failed");
                        dataSet.EnforceConstraints = fEnforce;
                        return;
                    }
                    if (dst.primaryKey != null)
                    {
                        key = GetSrcKey(src, dst);
                    }
                    if (key.HasValue)
                    {
                        // Getting our own copy instead. ndxSearch = dst.primaryKey.Key.GetSortIndex();
                        // IMO, Better would be to reuse index
                        // ndxSearch = dst.primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added );
                        if (null != ndxSearch)
                        {
                            ndxSearch.RemoveRef();
                            ndxSearch = null;
                        }
                        ndxSearch = new Index(dst, dst.primaryKey.Key.GetIndexDesc(), DataViewRowState.OriginalRows | DataViewRowState.Added, (IFilter)null);
                        ndxSearch.AddRef(); // need to addref twice, otherwise it will be collected
                        ndxSearch.AddRef(); // in past first adref was done in const
                    }
                }

                if (row.newRecord == -1 && row.oldRecord == -1)
                {
                    continue;
                }

                DataRow targetRow = null;
                if (0 < dst.Rows.Count && ndxSearch != null)
                {
                    targetRow = dst.FindMergeTarget(row, key, ndxSearch);
                }

                targetRow = dst.MergeRow(row, targetRow, preserveChanges, ndxSearch);

                if (targetRow.Table.dependentColumns != null && targetRow.Table.dependentColumns.Count > 0)
                {
                    targetRow.Table.EvaluateExpressions(targetRow, DataRowAction.Change, null);
                }
            }
            if (null != ndxSearch)
            {
                ndxSearch.RemoveRef();
                ndxSearch = null;
            }

            dataSet.EnforceConstraints = fEnforce;
        }