Exemplo n.º 1
0
        public T LoadObject <T>(string alias, string tableName, string id, LoadType loadType, bool isNolock) where T : SRO, new()
        {
            if (string.IsNullOrEmpty(id))
            {
                LogProxy.WarnFormat(IDISNULL, typeof(T).ToString());
                return(default(T));
            }

            if (loadType == LoadType.CacheFirst)
            {
                T obj = LoadCacheObject <T>(id);

                if (obj != null)
                {
                    if (SynClientService == null)
                    {
                        return(obj);
                    }

                    long version;
                    bool isNeedSyn = SynClientService.Peek <T>(id, out version);
                    if (!isNeedSyn || obj.Version >= version)
                    {
                        return(obj);
                    }

                    bool isLazy = SynClientService.IsLazy <T>();
                    if (isLazy)
                    {
                        Thread t = new Thread(SynLoadObject <T>);
                        t.Start(new DbInfo(alias, tableName, id, isNolock));

                        return(obj);
                    }
                }
            }

            return(LoadObjectDataBaseDirect <T>(alias, tableName, id, isNolock));
        }