public void Update(IStorageObject obj) { DbEventArgs args; if (obj.ModifiedValues.Count != 0) { string[] strArray = obj.ModifiedValues.Keys.ToArray <string>(); string updateSQL = this.SqlFormatter.GetUpdateSQL(obj); Debug.WriteLine("GetUpdateSQL: " + updateSQL); this.DbOperator.ExecuteNonQuery(updateSQL); Action item = delegate { args = new DbEventArgs(this, DbOperationAction.Update); obj.OnWrote(this, args); }; if (this.DbOperator.IsBeginTransaction) { this.transActions.Add(item); } else { item(); } } }
public void Retrieve(IStorageObject obj, IDataReader reader) { this.Read(obj, reader); DbEventArgs e = new DbEventArgs(this, DbOperationAction.Select); obj.OnRead(this, e); }
public void Insert(IStorageObject obj) { DbEventArgs args; string insertSQL = this.SqlFormatter.GetInsertSQL(obj); Type type = obj.GetType(); int num = this.DbOperator.ExecuteScalar <int>(insertSQL); DynamicPropertyInfo autoIncrementDynamicPropertyInfo = DbObjectTools.GetAutoIncrementDynamicPropertyInfo(DbObjectTools.GetDbObjectInfo(type)); if ((autoIncrementDynamicPropertyInfo != null) & (num != 0)) { obj.SetValue(autoIncrementDynamicPropertyInfo.PropertyName, num); } Action item = delegate { args = new DbEventArgs(this, DbOperationAction.Insert); obj.OnWrote(this, args); }; if (this.DbOperator.IsBeginTransaction) { this.transActions.Add(item); } else { item(); } }
public void Delete(IStorageObject obj) { string deleteSQL = this.SqlFormatter.GetDeleteSQL(obj); this.DbOperator.ExecuteNonQuery(deleteSQL); DbEventArgs e = new DbEventArgs(this, DbOperationAction.Delete); obj.OnWrote(this, e); }
public virtual void OnWrote(object sender, DbEventArgs e) { this.State.ObjectWrote = true; this.State.ModifiedValues.Clear(); this.State.UpdateInitialValues(this); this.previousState = DbObjectTools.Clone <DbObjectState>(this.State); e.Operator.TranscationRollback -= new EventHandler(this.OnTranscationRollback); e.Operator.TranscationRollback += new EventHandler(this.OnTranscationRollback); e.Operator.TranscationCommit -= new EventHandler(this.OnTranscationCommit); e.Operator.TranscationCommit += new EventHandler(this.OnTranscationCommit); }
public bool Retrieve(IStorageObject obj, string keyName, object keyValue) { bool flag = false; string sql = this.SqlFormatter.GetSelectSQL(obj.GetType(), keyName, keyValue); Debug.WriteLine("SelectSQL: " + sql); using (IDataReader reader = this.DbOperator.Query(sql)) { if (reader.Read()) { this.Read(obj, reader); DbEventArgs e = new DbEventArgs(this, DbOperationAction.Select); obj.OnRead(this, e); flag = true; } } return(flag); }
public T Retrieve <T>(string condition) where T : IStorageObject, new() { T local = default(T); Type type = typeof(T); string selectSQL = this.SqlFormatter.GetSelectSQL <T>(condition); Debug.WriteLine("SelectSQL: " + selectSQL); using (IDataReader reader = this.DbOperator.Query(selectSQL)) { if (reader.Read()) { local = (T)Activator.CreateInstance(type); this.Read(local, reader); DbEventArgs e = new DbEventArgs(this, DbOperationAction.Select); local.OnRead(this, e); } } return(local); }
public virtual void OnRead(object sender, DbEventArgs e) { this.State.ObjectRead = true; this.State.ModifiedValues.Clear(); this.State.UpdateInitialValues(this); }