Example #1
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;
        }
Example #2
0
 internal int IndexOfReference(TElem listener)
 {
     return(Index.IndexOfReference(_listeners, listener));
 }
Example #3
0
 internal IndexTree(Index index) : base(TreeAccessMethod.KEY_SEARCH_AND_INDEX)
 {
     _index = index;
 }
Example #4
0
 /// <remarks>Only call from inside a lock</remarks>
 internal void Add(TElem listener)
 {
     Debug.Assert(null != listener, "null listener");
     Debug.Assert(!Index.ContainsReference(_listeners, listener), "already contains reference");
     _listeners.Add(listener);
 }