public override SqlStatement GetDeleteStatement(Condition iwc)
 {
     var sb = new UpdateStatementBuilder(Context.Info.From);
     sb.Values.Add(new KeyOpValue(_columnName, true, KvOpertation.None));
     sb.Where.Conditions = iwc && _colExp;
     return sb.ToSqlStatement(Context);
 }
Esempio n. 2
0
 public override void ProcessBelongsTo(UpdateStatementBuilder builder, MemberHandler m, object fk)
 {
     object v;
     if (_LoadedColumns.TryGetValue(m.Name, out v)) {
         if (NotEqual(v, fk)) {
             base.ProcessBelongsTo(builder, m, fk);
         }
     }
 }
Esempio n. 3
0
 public override void ProcessSimpleMember(UpdateStatementBuilder builder, MemberHandler m, object n)
 {
     object v;
     if (_LoadedColumns.TryGetValue(m.Name, out v)) {
         if (NotEqual(v, n)) {
             base.ProcessSimpleMember(builder, m, n);
         }
     }
 }
Esempio n. 4
0
 public override void ProcessLazyLoad(UpdateStatementBuilder builder, MemberHandler m, object value, Type type)
 {
     object v;
     if (_LoadedColumns.TryGetValue(m.Name, out v)) {
         if (!NotEqual(value, v)) {
             return;
         }
     }
     base.ProcessLazyLoad(builder, m, value, type);
 }
Esempio n. 5
0
 public override void AddColumn(ModelContext ctx, string columnName, object o)
 {
     base.AddColumn(ctx, columnName, null);
     if(o != null)
     {
         var stm = new UpdateStatementBuilder(ctx.Info.From);
         stm.Values.Add(new KeyOpValue(columnName, o, KvOpertation.None));
         var sql = stm.ToSqlStatement(ctx);
         ctx.Provider.ExecuteNonQuery(sql);
     }
 }
Esempio n. 6
0
 private int ProcessHasManyAndHasOne(IDbObject obj)
 {
     var result = 0;
     foreach (var member in Info.RelationMembers)
     {
         if (member.Is.HasMany || member.Is.HasOne)
         {
             var t = member.MemberInfo.MemberType.GetGenericArguments()[0];
             var ctx0 = ModelContext.GetInstance(t);
             ctx0.Operator.Fixer.TryFix();
             var sb = new UpdateStatementBuilder(ctx0.Info.From);
             var key = ctx0.Info.GetBelongsTo(Info.HandleType).Name;
             sb.Values.Add(new KeyOpValue(key, null, KvOpertation.None));
             sb.Where.Conditions = CK.K[key] == Handler.GetKeyValue(obj);
             var sql = sb.ToSqlStatement(ctx0);
             result += ctx0.Provider.ExecuteNonQuery(sql);
         }
     }
     return result;
 }
 public override SqlStatement GetUpdateStatement(object obj, Condition iwc)
 {
     var sb = new UpdateStatementBuilder(Context.Info.From);
     Context.Handler.SetValuesForUpdate(sb, obj);
     var lv = (int)Context.Info.LockVersion.GetValue(obj);
     sb.Where.Conditions = iwc && (CK.K[Context.Info.LockVersion.Name] == lv);
     bool find = false;
     foreach (var kv in sb.Values)
     {
         if (kv.Key == Context.Info.LockVersion.Name)
         {
             kv.Value = lv + 1;
             find = true;
             break;
         }
     }
     if (!find)
     {
         sb.Values.Add(new KeyOpValue(Context.Info.LockVersion.Name, lv + 1, KvOpertation.None));
     }
     return sb.ToSqlStatement(Context);
 }
Esempio n. 8
0
 public bool FindUpdateColumns(DbObjectSmartUpdate model, UpdateStatementBuilder builder)
 {
     var autoList = new List<KeyOpValue> ();
     foreach (var m in model.Context.Info.Members) {
         if (m.Is.DbGenerate || m.Is.HasOne || m.Is.HasMany ||
             m.Is.HasAndBelongsToMany || m.Is.CreatedOn || m.Is.Key) {
             continue;
         }
         if (m.Is.Count) {
             autoList.Add (new KeyOpValue(m.Name, 1, KvOpertation.Add));
             continue;
         }
         if (m.Is.UpdatedOn || m.Is.SavedOn) {
             autoList.Add (new KeyOpValue(m.Name, null, KvOpertation.Now));
             continue;
         }
         if (m.Is.SimpleField) {
             object n = m.GetValue(model);
             ProcessSimpleMember(builder, m, n);
         } else if (m.Is.LazyLoad) {
             var ll = (ILazyLoading)m.GetValue (model);
             if (ll.IsLoaded) {
                 var value = ll.Read ();
                 var type = m.MemberType.GetGenericArguments () [0];
                 ProcessLazyLoad(builder, m, value, type);
             }
         } else if (m.Is.BelongsTo) {
             var bt = (IBelongsTo)m.GetValue(model);
             var fk = bt.ForeignKey;
             ProcessBelongsTo(builder, m, fk);
         }
     }
     if (builder.Values.Count > 0) {
         builder.Values.AddRange (autoList);
         return true;
     }
     return false;
 }
Esempio n. 9
0
		internal protected bool FindUpdateColumns(UpdateStatementBuilder builder)
		{
			return _updateHelper.FindUpdateColumns(this, builder);
		}
Esempio n. 10
0
 public virtual void ProcessSimpleMember(UpdateStatementBuilder builder, MemberHandler m, object n)
 {
     builder.Values.Add(new KeyOpValue(m.Name, n, m.MemberType));
 }
Esempio n. 11
0
 public virtual void ProcessLazyLoad(UpdateStatementBuilder builder, MemberHandler m, object value, Type type)
 {
     builder.Values.Add (new KeyOpValue (m.Name, value, type));
 }
Esempio n. 12
0
 public virtual void ProcessBelongsTo(UpdateStatementBuilder builder, MemberHandler m, object fk)
 {
     builder.Values.Add(new KeyOpValue(m.Name, fk, fk == null ? typeof(long) : fk.GetType()));
 }
Esempio n. 13
0
 public virtual SqlStatement GetUpdateStatement(Condition iwc, object obj)
 {
     var isv = new UpdateStatementBuilder(this.Context.Info.From);
     foreach(var property in obj.GetType().GetProperties())
     {
         isv.Values.Add(new KeyOpValue(property.Name, property.GetValue(obj, null), KvOpertation.None));
     }
     isv.Where.Conditions = iwc;
     return isv.ToSqlStatement(this.Context);
 }
Esempio n. 14
0
        public virtual SqlStatement GetUpdateStatement(object obj, Condition iwc)
        {
            var isv = new UpdateStatementBuilder(this.Context.Info.From);
			var o = obj as DbObjectSmartUpdate;
			if (o != null) {
				if (!o.FindUpdateColumns (isv)) {
					return null;
				}
			} else {
				this.Context.Handler.SetValuesForUpdate(isv, obj);
			}
            isv.Where.Conditions = iwc;
            return isv.ToSqlStatement(this.Context);
        }