public static void InsertModel(ModelBase item, out Exception e, out int id) { lock (m_lock) { id = -1; e = null; Boolean isCache = true; DbTableAttribute attribute = Attribute.GetCustomAttribute(item.GetType(), typeof(DbTableAttribute)) as DbTableAttribute; if (attribute.CacheMode == CacheMode.CacheInClient || attribute.CacheMode == CacheMode.NoCache) { isCache = false; } try { ModelMapping mp = new ModelMapping(item.GetType()); // 插入后获得的MaxRid应该减1为最新插入元素的Rid int maxid = ModelFactoryCollection.GetMaxRid(mp); item.Rid = maxid; ModelFactoryCollection.InsertModel(item, mp, out e); if (e == null && isCache) { id = maxid; ModelCacheManager.Instance.Save(item); } else { return; } } catch (Exception ex) { e = ex; } } }
/// <summary> /// /// </summary> public ModelEnumerator(Type type, string where) { m_type = type; m_readerList = new List <IEnumerator <ModelBase> >(); foreach (ModelFactory factory in ModelFactoryCollection.GetFactories(type)) { IEnumerable <ModelBase> reader = new ModelDatabaseReader(type, factory, where); m_readerList.Add(reader.GetEnumerator()); } m_listEnumerator = m_readerList.GetEnumerator(); m_listEnumerator.MoveNext(); }
public static void BuildFactories(Type modelType) { string value = ConfigurationManager.AppSettings[modelType.FullName]; if (value == null) { return; } ModelFactoryCollection collection = new ModelFactoryCollection(modelType); string[] ss1 = value.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); int minRid = 0; int maxRid = 0; // Console.Write(value); foreach (string s1 in ss1) { string[] ss2 = s1.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries); ModelFactory factory = ModelFactory.CreateFactory(value); if (ss2.Length == 1) { factory.MinRid = minRid; factory.MaxRid = int.MaxValue; factory.Initialize(ss2[0]); collection.Add(factory); break; } else if (ss2.Length == 2) { if (!int.TryParse(ss2[0], out maxRid)) { throw new ModelServiceException("配置文件格式错误,key={0}", modelType.Name); } if (maxRid < minRid) { throw new ModelServiceException("配置文件格式错误,key={0}", modelType.Name); } factory.MinRid = minRid; factory.MaxRid = maxRid; minRid = maxRid; factory.Initialize(ss2[1]); collection.Add(factory); } } s_dictionary.Add(modelType, collection); }
private static void InternalLoad(Type type) { DateTime time = DateTime.Now; Console.Write("加载{0}到存根:", type.Name); int count = 0; ModelFactoryCollection.BuildFactories(type); ModelEnumerator reader = new ModelEnumerator(type); ModelCacheManager.Instance.CreateModelCollection(type); foreach (ModelBase model in reader) { ModelCacheManager.Instance.Save(model); count++; } Console.Write("{0}个记录 用时", count); Console.WriteLine(DateTime.Now.Subtract(time)); }
public static void AppendModel(ModelBase item, out Exception e) { e = null; try { ModelMapping mp = new ModelMapping(item.GetType()); ModelFactoryCollection.AppendModel(item, mp, out e); if (e == null) { ModelCacheManager.Instance.Save(item); } else { return; } } catch (Exception ex) { e = ex; } }
public static void CloseAllConnection() { ModelFactoryCollection.CloseAllConnection(); }