public void Update() { var status = _c.GetEntityStatus(); if (!status.NeedsUpdate()) { return; } using (var cn = _cf.GetConnection()) { cn.Open(); var select = SelectStatement(status); var update = UpdateStatement(status); var trans = cn.BeginTransaction(); try { foreach (var batch in Read(cn, select).Partition(_master.UpdateSize)) { var expanded = batch.ToArray(); cn.Execute(update, expanded, trans); } trans.Commit(); } catch (Exception ex) { _c.Error("error executing: {0} {1}", select, ex.Message); _c.Error(ex, ex.Message); _c.Warn("rolling back"); trans.Rollback(); } } }
public void Update() { if (_master == null) { _output.Error("The master isn't set, which indicates your arrangement has errors."); return; } var status = _output.GetEntityStatus(); if (!status.NeedsUpdate()) { return; } using (var cn = _cf.GetConnection()) { cn.Open(); var sql = _queryWriter.Write(status); try { var rowCount = cn.Execute(sql, new { TflBatchId = _output.Entity.BatchId, MasterTflBatchId = _master.BatchId }, null, 0, System.Data.CommandType.Text); _output.Info(rowCount + " updates to master"); } catch (DbException ex) { _output.Error("error executing: {0}", sql); _output.Error(ex, ex.Message); } } }
public void Update() { var status = _c.GetEntityStatus(); if (!status.NeedsUpdate()) { return; } using (var cn = _cf.GetConnection()) { cn.Open(); var select = SelectStatement(status); var update = UpdateStatement(status); var trans = cn.BeginTransaction(); try { var rows = new List <ExpandoObject>(); using (var reader = cn.ExecuteReader(select, new { TflBatchId = _c.Entity.BatchId, MasterTflBatchId = _master.BatchId }, trans, 0, CommandType.Text)) { while (reader.Read()) { var obj = new ExpandoObject(); var dict = (IDictionary <string, object>)obj; for (var i = 0; i < reader.FieldCount; i++) { dict[reader.GetName(i)] = reader.GetValue(i); } dict[_master.TflBatchId().FieldName()] = _c.Entity.BatchId; rows.Add(obj); } } if (rows.Any()) { foreach (var batch in rows.Partition(_master.UpdateSize)) { var expanded = batch.ToArray(); cn.Execute(update, expanded, trans); _c.Increment(expanded.Length); } } trans.Commit(); } catch (Exception ex) { _c.Error("error executing: {0} {1}", select, ex.Message); _c.Error(ex, ex.Message); _c.Warn("rolling back"); trans.Rollback(); } } }