示例#1
0
        public virtual DBCommandResult <T> Select(DBCommand <T> aCommand, CachePreference aCachePreferences)
        {
            int      _count = Count(aCommand, aCachePreferences);
            List <T> _data  = GetData(aCommand, aCachePreferences);

            return(new DBCommandResultImpl <T>(_data, _count, aCommand.Pager));
        }
示例#2
0
        public int Count <T>(SqlCriteria aCriteria, CachePreference aPreferences) where T : class, new()
        {
            int count = 0;
            var query = QueryFactory.CreateSelectQuery();

            query.SetStatement(
                s =>
            {
                s.AddField(Factory.GetExpressionHelper <T>().GetCountField <T>());
                s.AddFrom(Loader.GetClassMap <T>().GetTableName());
            });

            if (aCriteria == null)
            {
                aCriteria = Factory.CreateCriteria();
            }

            if (aPreferences == null)
            {
                aPreferences = new CachePreferenceImpl();
            }

            query.SetCriteria(aCriteria).SetCache(aPreferences);

            IntBinder binder = new IntBinder();

            binder.OnBind = delegate(IntResult aResult)
            {
                count = aResult.value;
            };
            Connetion.execute(query, binder);
            return(count);
        }
示例#3
0
 public virtual DataTable GetDByCriteria(SqlCriteria aCriteria = null, CachePreference aCachePreferences = null, OnRowSelect onSelect = null)
 {
     if (aCriteria == null)
     {
         aCriteria = GetCriteria();
     }
     return(ExecuteSelectQuery(GetQuery(aCachePreferences).SetCriteria(aCriteria), onSelect));
 }
示例#4
0
        public virtual int Count(DBCommand <T> aCommand, CachePreference aCachePreferences)
        {
            var _query    = GetQuery(aCachePreferences);
            var _criteria = _query.GetCriteria();

            ApplyFiltersForCriteria(_criteria, aCommand);
            return(GetCount(_criteria));
        }
示例#5
0
        public T GetById <T>(Object anID, CachePreference aPreferences = null) where T : class, new()
        {
            T            data     = new T();
            ClassMap <T> classmap = Loader.GetClassMap <T>();
            IdentityMap  identity = classmap.Identity;

            ValueExtractor.SetValue(identity.Member.Name, data, anID);
            return(Select <T>(GetQuery <T>(aPreferences).SetMaximum(1).SetCriteria(GetByIdCriteria <T>(data)), null).Single());
        }
示例#6
0
        private SelectQuery <T> GetQuery <T>(CachePreference aPreferences) where T : class, new()
        {
            if (aPreferences == null)
            {
                aPreferences = new CachePreferenceImpl();
            }

            return(Factory.GetQueryFactory().CreateSelectQuery <T>().SetCache(aPreferences));
        }
示例#7
0
        public virtual List <T> Get(SqlCriteria aCriteria = null, CachePreference aCachePreferences = null, OnEntitySelect <T> onSelect = null)
        {
            if (aCriteria == null)
            {
                aCriteria = GetCriteria();
            }

            return(ExecuteSelectQuery(GetQuery(aCachePreferences).SetCriteria(aCriteria), onSelect));
        }
示例#8
0
        public SelectQuery <T> GetQuery(CachePreference aPreference)
        {
            if (aPreference == null)
            {
                aPreference = new CachePreferenceImpl();
            }

            return(factory.GetQueryFactory().CreateSelectQuery <T>().SetCache(aPreference));
        }
示例#9
0
        public T GetSingle <T>(SqlCriteria aCriteria, CachePreference aPreferences) where T : class, new()
        {
            if (aCriteria == null)
            {
                aCriteria = Factory.CreateCriteria();
            }
            var _results = Select <T>(GetQuery <T>(aPreferences).SetCriteria(aCriteria).SetMaximum(1), null);

            return(_results.Count > 0 ? _results.First() : null);
        }
示例#10
0
        private List <T> GetData(DBCommand <T> aCommand, CachePreference aCachePreferences)
        {
            var _query    = GetQuery(aCachePreferences);
            var _criteria = _query.GetCriteria();

            ApplyFiltersForCriteria(_criteria, aCommand);
            ApplyOrderForQuery(_criteria, aCommand);
            ApplyPagerForQuery(_query, aCommand);
            return(ExecuteSelectQuery(_query, delegate(T aT, int index) { }));
        }
示例#11
0
        public virtual T GetById(object anId, CachePreference aCachePreferences)
        {
            T data = null;

            DBHelper.Execute(
                delegate(DbSession aSession)
            {
                data = aSession.GetById <T>(anId, aCachePreferences);
            });
            return(data);
        }
示例#12
0
        public virtual T GetSingle(SqlCriteria aSqlCriteria, CachePreference aCachePreference)
        {
            T data = null;

            DBHelper.Execute(
                delegate(DbSession aSession)
            {
                data = aSession.GetSingle <T>(aSqlCriteria, aCachePreference);
            });
            return(data);
        }
示例#13
0
        public virtual List <T> SelectList(DBCommand <T> aCommand, CachePreference aCachePreferences)
        {
            var _query    = GetQuery(aCachePreferences);
            var _criteria = _query.GetCriteria();

            ApplyFiltersForCriteria(_criteria, aCommand);
            ApplyOrderForQuery(_criteria, aCommand);
            if (aCommand.Pager != null && aCommand.Pager.RowCount > 0)
            {
                ApplyPagerForQuery(_query, aCommand);
            }
            return(ExecuteSelectQuery(_query, delegate(T aT, int index) { }));
        }
示例#14
0
        public void Add(string aKey, object aValue, AspNetNotication aNotification)
        {
            CacheSpec       cacheSpecs = aNotification.GetCacheSpec();
            CachePreference pref       = cacheSpecs.GetCachePreferences();

            cache.Add(
                aKey, aValue,
                aNotification.GetDependency(),
                DateTime.Now.AddSeconds(pref.CacheDuration),
                System.Web.Caching.Cache.NoSlidingExpiration,
                CacheItemPriority.Normal,
                new CacheItemRemovedCallback(this.CacheItemRemovedCallback)
                );
            CachedKeys[aKey] = null;
        }
示例#15
0
        private int GetCount(SqlCriteria aCriteria = null, String aSqlQuery = null, CachePreference aCachePreferences = null)
        {
            int count = 0;

            if (aSqlQuery != null)
            {
                aCriteria.AddSql(aSqlQuery);
            }

            DBHelper.Execute(
                delegate(DbSession aSession)
            {
                count = aSession.Count <T>(aCriteria, aCachePreferences);
            });

            return(count);
        }
示例#16
0
        private IExecutor GetExecuteQuery(HasCache aCache, HasMaximum aMaximum)
        {
            CachePreference pref = aCache.GetCachePreferences();

            if (!pref.Cachable)
            {
                return(new DefaultExecutor());
            }
            if (pref.CacheDuration <= 0)
            {
                return(new DefaultExecutor());
            }
            if (!pref.IsCacheDependency)
            {
                return(new CacheExecutor(aCache.GetCachePreferences()));
            }

            return(new DependencyExecutor(aCache.GetCachePreferences(), aMaximum.GetMaximum()));
        }
示例#17
0
 public SelectQuery SetCache(CachePreference aCache)
 {
     preferences = aCache;
     return(this);
 }
示例#18
0
 public virtual DataTable GetDPager <E>(int aMinimum = 0, int aMaximum = 10, T aCriteriaModel = null, System.Linq.Expressions.Expression <Func <T, E> > aOrderBy = null, bool isAscending = true, String aSqlQuery = null, CachePreference aCachePreferences = null, OnRowSelect onSelect = null)
 {
     return(ExecuteSelectQuery(GetModelOrderQueryWithSql(aCriteriaModel, aOrderBy, isAscending, aSqlQuery, aCachePreferences).SetMaximum(aMaximum).SetMinimum(aMinimum), onSelect));
 }
示例#19
0
 public virtual List <T> Get <E>(T aCriteriaModel = null, System.Linq.Expressions.Expression <Func <T, E> > aOrderBy = null, bool isAscending = true, CachePreference aCachePreferences = null, OnEntitySelect <T> onSelect = null)
 {
     return(ExecuteSelectQuery(GetModelOrderQueryWithSql(aCriteriaModel, aOrderBy, isAscending, null, aCachePreferences), onSelect));
 }
示例#20
0
 public CacheExecutor(CachePreference aPreference)
     : base(aPreference)
 {
 }
示例#21
0
 public virtual List <T> GetTop <E>(int aTop, T aCriteriaModel = null, System.Linq.Expressions.Expression <Func <T, E> > aOrderBy = null, bool isAscending = true, String aSqlQuery = null, CachePreference aCachePreferences = null, OnEntitySelect <T> onSelect = null)
 {
     return(ExecuteSelectQuery(GetModelOrderQueryWithSql(aCriteriaModel, aOrderBy, isAscending, aSqlQuery, aCachePreferences).SetMaximum(aTop), onSelect));
 }
示例#22
0
 public virtual int GetCount(T aCriteriaModel, String sqlQuery, CachePreference aCachePreferences)
 {
     return(GetCount(GetDataModelCriteria(aCriteriaModel, false), sqlQuery, aCachePreferences));
 }
示例#23
0
 public virtual int GetCount(SqlCriteria aCriteria, CachePreference aCachePreferences)
 {
     return(GetCount(aCriteria, null, aCachePreferences));
 }
示例#24
0
 public SelectQuery <T> SetCache(CachePreference aCache)
 {
     query.SetCache(aCache);
     return(this);
 }
示例#25
0
 public AbstractCacheExecutor(CachePreference aPreference)
 {
     CacheSpecs = new CacheSpecImpl(aPreference);
     Cache      = Database.Current.Factory.GetCache();
     Generator  = Database.Current.Factory.GetKeyGenerator();
 }
示例#26
0
 public SelectQuery()
 {
     preferences = new CachePreferenceImpl();
 }
示例#27
0
        public T GetById <T>(T aModel, CachePreference aPreferences = null) where T : class, new()
        {
            var query = GetQuery <T>(aPreferences).SetMaximum(1).SetCriteria(GetByIdCriteria(aModel));

            return(Select <T>(query, null).Single());
        }
示例#28
0
        public List <T> Get <T>(SqlCriteria aCriteria = null, OnEntitySelect <T> onExecute = null, CachePreference aPreferences = null) where T : class, new()
        {
            if (aCriteria == null)
            {
                aCriteria = Factory.CreateCriteria();
            }

            return(Select <T>(GetQuery <T>(aPreferences).SetCriteria(aCriteria), new TemplateBinder <T>(), onExecute));
        }
示例#29
0
        protected SelectQuery <T> GetModelOrderQueryWithSql <E>(T aCriteriaModel, System.Linq.Expressions.Expression <Func <T, E> > aOrderBy, bool isAscending, String sqlQuery, CachePreference aCachePreferences = null)
        {
            var query    = GetQuery(aCachePreferences).SetCriteria(GetDataModelCriteria(aCriteriaModel, false));
            var criteria = query.GetCriteria();

            if (!String.IsNullOrEmpty(sqlQuery))
            {
                criteria.AddSql(sqlQuery);
            }
            if (aOrderBy != null)
            {
                if (!isAscending)
                {
                    criteria.AddOrder(ExpressionHelper.OrderDes(aOrderBy));
                }
                else
                {
                    criteria.AddOrder(ExpressionHelper.OrderAsc(aOrderBy));
                }
            }
            return(query);
        }
示例#30
0
        public virtual T GetSingle(T aCriteriaModel, bool isIdIncluded, CachePreference aCachePreference)
        {
            SqlCriteria _cri = GetDataModelCriteria(aCriteriaModel, isIdIncluded);

            return(GetSingle(_cri, aCachePreference));
        }