Beispiel #1
0
        public IQueryExpressionPlan GetHQLQueryPlan(IQueryExpression queryExpression, bool shallow, IDictionary <string, IFilter> enabledFilters)
        {
            var key  = new HQLQueryPlanKey(queryExpression, shallow, enabledFilters);
            var plan = (QueryExpressionPlan)planCache[key];

            if (plan == null)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("unable to locate HQL query plan in cache; generating (" + queryExpression.Key + ")");
                }
                plan = new QueryExpressionPlan(queryExpression, shallow, enabledFilters, factory);
                planCache.Put(key, plan);
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("located HQL query plan in cache (" + queryExpression.Key + ")");
                }
                plan = CopyIfRequired(plan, queryExpression);
            }

            return(plan);
        }
Beispiel #2
0
		public void ExecutesCustomSqlFunctionContains()
		{
		 string hql = @"from Customer c where contains(c.Name, :smth)";

		 HQLQueryPlan plan = new QueryExpressionPlan(new StringQueryExpression(hql), false, new CollectionHelper.EmptyMapClass<string, IFilter>(), sessions);

		 Assert.AreEqual(1, plan.ParameterMetadata.NamedParameterNames.Count);
		 Assert.AreEqual(1, plan.QuerySpaces.Count);
		 Assert.AreEqual(1, plan.SqlStrings.Length);
	  }
        public IQueryExpressionPlan GetHQLQueryPlan(IQueryExpression queryExpression, bool shallow, IDictionary <string, IFilter> enabledFilters)
        {
            var key  = new HQLQueryPlanKey(queryExpression, shallow, enabledFilters);
            var plan = (QueryExpressionPlan)planCache[key];

            if (plan == null)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("unable to locate HQL query plan in cache; generating (" + queryExpression.Key + ")");
                }
                plan = new QueryExpressionPlan(queryExpression, shallow, enabledFilters, factory);
                planCache.Put(key, plan);
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("located HQL query plan in cache (" + queryExpression.Key + ")");
                }
                var planExpression = plan.QueryExpression as NhLinqExpression;
                var expression     = queryExpression as NhLinqExpression;
                if (planExpression != null && expression != null)
                {
                    //NH-3413
                    //Here we have to use original expression.
                    //In most cases NH do not translate expression in second time, but
                    // for cases when we have list parameters in query, like @p1.Contains(...),
                    // it does, and then it uses parameters from first try.
                    //TODO: cache only required parts of QueryExpression

                    //NH-3436
                    // We have to return new instance plan with it's own query expression
                    // because other treads can override queryexpression of current plan during execution of query if we will use cached instance of plan
                    expression.CopyExpressionTranslation(planExpression);
                    plan = plan.Copy(expression);
                }
            }

            return(plan);
        }
        public IQueryExpressionPlan GetHQLQueryPlan(IQueryExpression queryExpression, bool shallow, IDictionary <string, IFilter> enabledFilters)
        {
            var key  = new HQLQueryPlanKey(queryExpression, shallow, enabledFilters);
            var plan = (QueryExpressionPlan)planCache[key];

            if (plan == null)
            {
                if (log.IsDebugEnabled())
                {
                    log.Debug("unable to locate HQL query plan in cache; generating ({0})", queryExpression.Key);
                }
                plan = new QueryExpressionPlan(queryExpression, shallow, enabledFilters, factory);
                // 6.0 TODO: add "CanCachePlan { get; }" to IQueryExpression interface
                if (!(queryExpression is NhLinqExpression linqExpression) || linqExpression.CanCachePlan)
                {
                    planCache.Put(key, plan);
                }
                else
                {
                    log.Debug("Query plan not cacheable");
                }
            }
Beispiel #5
0
        private static QueryExpressionPlan CopyIfRequired(QueryExpressionPlan plan, IQueryExpression queryExpression)
        {
            var planExpression = plan.QueryExpression as NhLinqExpression;
            var expression     = queryExpression as NhLinqExpression;

            if (planExpression != null && expression != null)
            {
                //NH-3413
                //Here we have to use original expression.
                //In most cases NH do not translate expression in second time, but
                // for cases when we have list parameters in query, like @p1.Contains(...),
                // it does, and then it uses parameters from first try.
                //TODO: cache only required parts of QueryExpression

                //NH-3436
                // We have to return new instance plan with it's own query expression
                // because other treads can override queryexpression of current plan during execution of query if we will use cached instance of plan
                expression.CopyExpressionTranslation(planExpression);
                plan = plan.Copy(expression);
            }

            return(plan);
        }
Beispiel #6
0
        public IQueryExpressionPlan GetHQLQueryPlan(IQueryExpression queryExpression, bool shallow, IDictionary <string, IFilter> enabledFilters)
        {
            var key  = new HQLQueryPlanKey(queryExpression, shallow, enabledFilters);
            var plan = (IQueryExpressionPlan)planCache[key];

            if (plan == null)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("unable to locate HQL query plan in cache; generating (" + queryExpression.Key + ")");
                }
                plan = new QueryExpressionPlan(queryExpression, shallow, enabledFilters, factory);
                planCache.Put(key, plan);
            }
            else
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("located HQL query plan in cache (" + queryExpression.Key + ")");
                }
                var planExpression = plan.QueryExpression as NhLinqExpression;
                var expression     = queryExpression as NhLinqExpression;
                if (planExpression != null && expression != null)
                {
                    //NH-3413
                    //Here we have to use original expression.
                    //In most cases NH do not translate expression in second time, but
                    // for cases when we have list parameters in query, like @p1.Contains(...),
                    // it does, and then it uses parameters from first try.
                    //TODO: cache only required parts of QueryExpression
                    planExpression._expression             = expression._expression;
                    planExpression._constantToParameterMap = expression._constantToParameterMap;
                }
            }

            return(plan);
        }