private FindMergeTarget ( DataRow row, DataKey key, Index ndx ) : DataRow | ||
row | DataRow | |
key | DataKey | |
ndx | Index | |
Результат | DataRow |
private void MergeTable(DataTable src, DataTable dst) { int rowsCount = src.Rows.Count; bool wasEmpty = dst.Rows.Count == 0; if (0 < rowsCount) { Index ndxSearch = null; DataKey key = null; ArrayList saveIndexes = dst.LiveIndexes; dst.indexes = new ArrayList(); if (!wasEmpty && dst.primaryKey != null) { key = GetSrcKey(src, dst); if (key != null) { ndxSearch = dst.primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added); } } for (int i = 0; i < rowsCount; i++) { DataRow sourceRow = src.Rows[i]; DataRow targetRow = null; if (ndxSearch != null) { targetRow = dst.FindMergeTarget(sourceRow, key, ndxSearch); } dst.MergeRow(sourceRow, targetRow, preserveChanges, ndxSearch); } dst.indexes = saveIndexes; dst.ResetIndexes(); } MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties); }
private void MergeTable(DataTable src, DataTable dst) { int rowsCount = src.Rows.Count; bool wasEmpty = dst.Rows.Count == 0; if (0 < rowsCount) { Index? ndxSearch = null; DataKey key = default(DataKey); dst.SuspendIndexEvents(); try { if (!wasEmpty && dst._primaryKey != null) { key = GetSrcKey(src, dst); if (key.HasValue) { ndxSearch = dst._primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added); } } // this improves performance by iterating over the rows instead of computing their position foreach (DataRow sourceRow in src.Rows) { DataRow?targetRow = null; if (ndxSearch != null) { targetRow = dst.FindMergeTarget(sourceRow, key, ndxSearch); } dst.MergeRow(sourceRow, targetRow, _preserveChanges, ndxSearch); } } finally { dst.RestoreIndexEvents(true); } } MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties); }
private void MergeTable(DataTable src, DataTable dst) { int count = src.Rows.Count; bool flag = dst.Rows.Count == 0; if (0 < count) { Index ndx = null; DataKey srcKey = new DataKey(); dst.SuspendIndexEvents(); try { if (!flag && (dst.primaryKey != null)) { srcKey = this.GetSrcKey(src, dst); if (srcKey.HasValue) { ndx = dst.primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added); } } foreach (DataRow row2 in src.Rows) { DataRow targetRow = null; if (ndx != null) { targetRow = dst.FindMergeTarget(row2, srcKey, ndx); } dst.MergeRow(row2, targetRow, this.preserveChanges, ndx); } } finally { dst.RestoreIndexEvents(true); } } this.MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties); }
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; }
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; }
private void MergeTable(DataTable src, DataTable dst) { int rowsCount = src.Rows.Count; bool wasEmpty = dst.Rows.Count == 0; if(0 < rowsCount) { Index ndxSearch = null; DataKey key = default(DataKey); dst.SuspendIndexEvents(); try { if(! wasEmpty && dst.primaryKey != null) { key = GetSrcKey(src, dst); if (key.HasValue) ndxSearch = dst.primaryKey.Key.GetSortIndex(DataViewRowState.OriginalRows | DataViewRowState.Added ); } // SQLBU 414992: Serious performance issue when calling Merge // this improves performance by iterating over the rows instead of computing their position foreach(DataRow sourceRow in src.Rows) { DataRow targetRow = null; if(ndxSearch != null) { targetRow = dst.FindMergeTarget(sourceRow, key, ndxSearch); } dst.MergeRow(sourceRow, targetRow, preserveChanges, ndxSearch); } } finally { dst.RestoreIndexEvents(true); } } MergeExtendedProperties(src.ExtendedProperties, dst.ExtendedProperties); }
internal void MergeRows(DataRow[] rows) { DataTable src = null; DataTable dst = null; DataKey key = null; Index ndxSearch = null; bool fEnforce = dataSet.EnforceConstraints; dataSet.EnforceConstraints = false; Hashtable saveTableIndexes = new Hashtable(); 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 != null) { ndxSearch = new Index(dst, dst.primaryKey.Key.GetIndexDesc(), DataViewRowState.OriginalRows | DataViewRowState.Added, (IFilter)null); } // Getting our own copy instead. ndxSearch = dst.primaryKey.Key.GetSortIndex(); } if (row.newRecord == -1 && row.oldRecord == -1) { continue; } DataRow targetRow = null; if (0 < dst.Rows.Count && ndxSearch != null) { targetRow = dst.FindMergeTarget(row, key, ndxSearch); } if (!saveTableIndexes.Contains(dst)) { saveTableIndexes[dst] = dst.LiveIndexes; saveTableIndexes[dst] = new ArrayList(); } dst.MergeRow(row, targetRow, preserveChanges, ndxSearch); } dataSet.EnforceConstraints = fEnforce; foreach (DataTable tab in saveTableIndexes.Keys) { tab.indexes = (ArrayList)saveTableIndexes[tab]; tab.ResetIndexes(); } }