示例#1
0
 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]);
         }
     }
 }
示例#2
0
 public void Apply(Transaction transaction)
 {
     if(!this.isApplied) {
         this.doApply(transaction);
         this.isApplied = true;
     }
 }
示例#3
0
 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
     );
 }
示例#4
0
 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]);
     }
 }
示例#5
0
 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;
         }
     }
 }
示例#6
0
 protected abstract void doApply(Transaction transaction);
示例#7
0
 public abstract void Lock(Transaction transaction);
示例#8
0
 public override void Lock(Transaction transaction)
 {
     Config.instance.mainConnection.lockTable(transaction, this.tableSpec);
 }
示例#9
0
 public override void Lock(Transaction transaction)
 {
     Config.instance.mainConnection.lockRow(transaction, this.tableSpec, this.id.ToString());
 }
示例#10
0
 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;
 }
示例#11
0
 private void ApplyToChange(Transaction transaction, AbstractChange change)
 {
     foreach(AbstractChange referenced in change.references) {
         if(!referenced.getId().HasValue) {
             this.ApplyToChange(transaction, referenced);
         }
     }
     change.Apply(transaction);
 }