public virtual int Update(AbstractBusinessObject ado, Type impltype) { if (!(ado.GetType() == impltype)) { return(0); } _updatecmd.Parameters.Clear(); UpdateParams(ado); return(ExecuteNonQuery(_updatecmd)); }
public Thrift.Protocol.TBase Convert(AbstractBusinessObject o) { CharBaseData data = o as CharBaseData; CharBaseInfo info = new CharBaseInfo(); info.CharId = data.CharId; info.CharName = data.CharName; info.Age = data.CharAge; info.Fame = data.Fame; info.Level = data.Level; info.Gender = data.Gender; //leo info.CharTalentMap = data.CharTalentMap; info.Role = data.CharRole; info.CharDeail = data.CharDeatail; return(info); }
protected abstract void UpdateParams(AbstractBusinessObject ado);
public virtual int Update(AbstractBusinessObject ado, Type impltype) { if (!(ado.GetType() == impltype)) return 0; _updatecmd.Parameters.Clear(); UpdateParams(ado); return ExecuteNonQuery(_updatecmd); }
public virtual IList <AbstractBusinessObject> Query(string tablename, Type boType, SACommand cmd) //string sql, SAParameterCollection criteria, { //SACommand objSql; //SADataReader dataReader; SADataAdapter adp = new SADataAdapter(); DataSet ds; ArrayList abos = new ArrayList(); // Getting rowcount //sql = "SELECT count(*) as Count FROM "+tablename+" where UserID = @userid"; //objSql = new SACommand(sql, conn); //objSql.Parameters.AddWithValue("@userid", UserID); //dataReader = ExecuteReader(objSql); //dataReader.Read(); //int rowcount = dataReader.GetInt32(0); //dataReader.Close(); //if (rowcount <= 0) // return null; if (BaseTableAdapter._trans != null) { cmd.Transaction = _trans; } try { // filling the DataSet with the DataAdapter adp.TableMappings.Add("Table", tablename); //add Parameters cmd.CommandType = CommandType.Text; adp.SelectCommand = cmd; ds = new DataSet(tablename); lock (BaseTableAdapter.conn) adp.Fill(ds); // Retrieve all the rows DataRowCollection rows = ds.Tables[0].Rows; if (rows.Count < 1) { return(null); } // Loop through the Columns in the DataSet and map that to the properties of the class IEnumerator columns = ds.Tables[0].Columns.GetEnumerator(); DataColumn datacolumn; DataRow datarow; string cname; object cvalue; ConstructorInfo cons = boType.GetConstructor(Type.EmptyTypes); PropertyInfo[] props = boType.GetProperties(); //( rows.Count _log.Log(String.Format("Querying cmd={0}", cmd.CommandText), "DB", 5); for (int r = 0; r < rows.Count; r++) { datarow = rows[r]; AbstractBusinessObject curr = (AbstractBusinessObject)cons.Invoke(null); columns.Reset(); while (columns.MoveNext()) { try { datacolumn = (DataColumn)columns.Current; cname = datacolumn.ColumnName; for (int i = 0; i < props.Length; i++) { if (props[i].Name.ToLower() == cname.ToLower()) { cvalue = Convert.ChangeType(datarow[datacolumn], props[i].PropertyType); props[i].SetValue(curr, cvalue, null); _log.Log(String.Format("\tName={0} Value={1}", cname, cvalue), "DB", 5); break; // break for loop } } } catch (InvalidCastException ivce) { // go to next column } } abos.Add(curr); } } catch (Exception ex) { string logoutput = String.Format("----Error in BaseTableAdapter, Query----\r\n{0}\r\n{1}", ex.Message, ex.StackTrace); _log.Log(logoutput, "DB", 3); _log.Log(logoutput); } finally { adp.Dispose(); } AbstractBusinessObject[] rc = (AbstractBusinessObject[])abos.ToArray(boType); return(rc); }
protected override void Beat() { List <TBase> updateList = null; while (true) { AbstractBusinessObject obj = UpdateManager.Instance.Poll(); if (obj == null) { break; } ICharDataConverter converter = ConverterManager.Instance.FindConverter(obj.GetType()); if (converter == null) { Debuger.LogError(string.Format("not found converter. type:{0}", obj.GetType())); continue; } TBase info = converter.Convert(obj); obj.ResetModify(); if (info == null) { Debuger.LogError(string.Format("convert result is null. type:{0}", obj.GetType())); continue; } if (updateList == null) { updateList = new List <TBase>(); } updateList.Add(info); } if (updateList != null) { CacheKeyInfo keyInfo = CacheKeyContants.CHAR_DATA_SNAPSHOT_KEY.BuildCacheInfo(PlayerManager.Instance.GetCharBaseData().CharId); CharacterDataSnapshot data = CacheManager.GetInsance().Get(keyInfo) as CharacterDataSnapshot; if (data == null) { data = new CharacterDataSnapshot(); data.Version = 0L; data.DataList = updateList; } else { data.Version += 1; List <TBase> delList = new List <TBase>(); for (int i = 0; i < updateList.Count; i++) { TBase newTbase = updateList[i]; for (int j = 0; j < data.DataList.Count; j++) { if (newTbase.GetType() == data.DataList[j].GetType()) { data.DataList[j] = newTbase; delList.Add(newTbase); break; } } } foreach (TBase delTbase in delList) { updateList.Remove(delTbase); } if (updateList.Count > 0) { data.DataList.AddRange(updateList); } } CacheManager.GetInsance().Set(keyInfo, data); } }