/// <summary> /// Submit the specified row collection with 'Update' statements. /// </summary> public void Update(RowCollection collection, bool onlyUpdated = false) { // ensure the Table is initialized if (_initialize) { Initialize(); } object[] values = new object[collection.Columns.Count]; // only update rows that have changed? if (onlyUpdated) { bool[] updated = new bool[collection.Columns.Count]; // iterate the updated rows collection foreach (IRow row in collection.Rows) { if (row.Updated) { // build an update query for the each row Query builder = new Query(this); builder.Add(Cql.Update); // get the current values and updated flags for the cells row.GetValues(values); row.GetUpdated(updated); // add the updated columns and values to the builder for (int i = values.Length - 1; i >= 0; --i) { if (updated[i]) { builder.Add(collection.Columns[i]); builder.Add(values[i]); } } // add the identifier columns for (int i = values.Length - 1; i >= 0; --i) { if (collection.Columns[i].IsIdentifier) { // add the 'WHERE' command for the identifier builder.Add(Cql.Where); builder.Add(collection.Columns[i]); builder.Add(Cql.Equal); builder.Add(values[i]); } } row.Updated = false; // execute the query builder.ExecuteAsync(); } } } else { // iterate the rows collection foreach (IRow row in collection.Rows) { // build an update query for the each row Query builder = new Query(this); builder.Add(Cql.Update); // get the current values and updated flags for the cells row.GetValues(values); // add the updated columns and values to the builder for (int i = values.Length - 1; i >= 0; --i) { builder.Add(collection.Columns[i]); builder.Add(values[i]); } // add the 'WHERE' portion of the statement builder.Add(Cql.Where); // add the identifying columns for (int i = values.Length - 1; i >= 0; --i) { if (collection.Columns[i].IsIdentifier) { builder.Add(collection.Columns[i]); builder.Add(values[i]); } } row.Updated = false; // execute the query builder.ExecuteAsync(); } } }
/// <summary> /// Add a row collection that could potentially be updated. /// </summary> internal void AddCollection(RowCollection collection) { _lock.Take(); _currentCollections.Add(collection); _lock.Release(); }