protected override void doApply(Transaction transaction) { if(this.id.HasValue) { Dictionary<string, string> row = Config.instance.mainConnection.LoadByIds(transaction, this.tableSpec, new List<string>() { this.id.ToString() })[0]; Dictionary<string, string> processedData = new Dictionary<string,string>(); foreach(KeyValuePair<string, AbstractFieldValue> kvp in this.dataToUpdate) { processedData[kvp.Key] = kvp.Value.getStringRepresentation(row[kvp.Key]); } Config.instance.mainConnection.update( transaction, this.tableSpec, this.id.ToString(), processedData ); } else { Dictionary<string, string> processedData = new Dictionary<string,string>(); foreach(KeyValuePair<string, AbstractFieldValue> kvp in this.dataToInsert) { processedData[kvp.Key] = kvp.Value.getStringRepresentation(); } this.id = int.Parse(Config.instance.mainConnection.insert( transaction, this.tableSpec, processedData )); if(processedData.ContainsKey(this.tableSpec.idName)) { this.id = int.Parse(processedData[this.tableSpec.idName]); } } }
public void Apply(Transaction transaction) { if(!this.isApplied) { this.doApply(transaction); this.isApplied = true; } }
protected override void doApply(Transaction transaction) { Dictionary<string, string> row = Config.instance.mainConnection.LoadByIds(transaction, this.tableSpec, new List<string>() { this.id.ToString() })[0]; Dictionary<string, string> processedData = new Dictionary<string,string>(); foreach(KeyValuePair<string, AbstractFieldValue> kvp in this.data) { processedData[kvp.Key] = kvp.Value.getStringRepresentation(row[kvp.Key]); } Config.instance.mainConnection.update( transaction, this.tableSpec, this.id.ToString(), processedData ); }
protected override void doApply(Transaction transaction) { Dictionary<string, string> processedData = new Dictionary<string,string>(); foreach(KeyValuePair<string, AbstractFieldValue> kvp in this.data) { processedData[kvp.Key] = kvp.Value.getStringRepresentation(); } this.id = int.Parse(Config.instance.mainConnection.insert( transaction, this.tableSpec, processedData )); if(processedData.ContainsKey(this.tableSpec.idName)) { this.id = int.Parse(processedData[this.tableSpec.idName]); } }
public override void Lock(Transaction transaction) { List<string> ids = Config.instance.mainConnection.LoadIdsByConditions(transaction, this.tableSpec, this.condition, Diapasone.unlimited, new JoinSpec[0], new SortSpec[0], false); if(ids.Count > 1) { throw new CriticalException("Not unique"); } else if(ids.Count == 1) { this.id = int.Parse(ids[0]); Config.instance.mainConnection.lockRow(transaction, this.tableSpec, this.id.ToString()); } else { Config.instance.mainConnection.lockTable(transaction, this.tableSpec); ids = Config.instance.mainConnection.LoadIdsByConditions(transaction, this.tableSpec, this.condition, Diapasone.unlimited, new JoinSpec[0], new SortSpec[0], false); if(ids.Count > 1) { throw new CriticalException("Not unique"); } else if(ids.Count == 1) { this.id = int.Parse(ids[0]); } else { this.id = null; } } }
protected abstract void doApply(Transaction transaction);
public abstract void Lock(Transaction transaction);
public override void Lock(Transaction transaction) { Config.instance.mainConnection.lockTable(transaction, this.tableSpec); }
public override void Lock(Transaction transaction) { Config.instance.mainConnection.lockRow(transaction, this.tableSpec, this.id.ToString()); }
public void Apply(Transaction transaction) { lock(this.locker) { if(this.isAdding) throw new CriticalException("Cannot process while adding"); if(this.isProcessing || this.isProcessed) throw new CriticalException("ChangeSet is already processed"); this.isProcessing = true; } foreach(string table in tablesLockOrder) { foreach(AbstractChange change in (from AbstractChange _change in this.changesByTable[table] orderby _change.getId() select _change)) { change.Lock(transaction); } } foreach(KeyValuePair<string, HashSet<AbstractChange>> kvp in this.changesByTable) { foreach(AbstractChange change in kvp.Value) { this.ApplyToChange(transaction, change); } } this.isProcessed = true; }
private void ApplyToChange(Transaction transaction, AbstractChange change) { foreach(AbstractChange referenced in change.references) { if(!referenced.getId().HasValue) { this.ApplyToChange(transaction, referenced); } } change.Apply(transaction); }