Exemplo n.º 1
0
        public IQueryTranslator[] CreateQueryTranslators(string queryString, string collectionRole, bool shallow, IDictionary <string, IFilter> filters, ISessionFactoryImplementor factory)
        {
            var translators = QuerySplitter.ConcreteQueries(queryString, factory)
                              .Select(hql => new QueryTranslator(queryString, hql, filters, factory))
                              .ToArray();

            foreach (var translator in translators)
            {
                if (collectionRole == null)
                {
                    translator.Compile(factory.Settings.QuerySubstitutions, shallow);
                }
                else
                {
                    translator.Compile(collectionRole, factory.Settings.QuerySubstitutions, shallow);
                }
            }

            return(translators);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Splits the input query into two parts; supported and unsupported.
 /// </summary>
 /// <remarks>
 /// Windows Azure Table Storage only supports a subset of the LINQ operators. This
 /// method splits a single query into two parts at the first occurrence of an
 /// unsupported operation. This results in 3 scenarios.
 ///
 /// 1) The whole query is supported.
 ///     The <paramref name="query"/> will be returned and <paramref name="unsupportedQuery"/> will be <c>null</c>.
 /// 2) The query is split.
 ///     The supported query will be returned and <paramref name="unsupportedQuery"/> will be set.
 /// 3) The whole query is unsupported.
 ///     <c>null</c> will be returned and the <paramref name="unsupportedQuery"/> will be set to the <paramref name="query"/>.
 /// </remarks>
 /// <param name="query">The query to split</param>
 /// <param name="unsupportedQuery">The unsupported part of the query or <c>null</c> if the whole query is supported.</param>
 /// <returns>The supported part of the query or <c>null</c> if the whole query is unsupported.</returns>
 internal static IQueryable Split(IQueryable query, out IQueryable unsupportedQuery)
 {
     return(QuerySplitter.Split(query, out unsupportedQuery));
 }
Exemplo n.º 3
0
        protected internal HQLQueryPlan(string hql, string collectionRole, bool shallow,
                                        IDictionary <string, IFilter> enabledFilters, ISessionFactoryImplementor factory)
        {
            sourceQuery  = hql;
            this.shallow = shallow;

            enabledFilterNames = new HashedSet <string>(enabledFilters.Keys);

            HashedSet <string> combinedQuerySpaces = new HashedSet <string>();

            string[] concreteQueryStrings = QuerySplitter.ConcreteQueries(hql, factory);
            int      length = concreteQueryStrings.Length;

            translators = new IQueryTranslator[length];
            List <string> sqlStringList = new List <string>();

            for (int i = 0; i < length; i++)
            {
                if (collectionRole == null)
                {
                    translators[i] =
                        factory.Settings.QueryTranslatorFactory.CreateQueryTranslator(hql, concreteQueryStrings[i], enabledFilters,
                                                                                      factory);
                    translators[i].Compile(factory.Settings.QuerySubstitutions, shallow);
                }
                else
                {
                    translators[i] =
                        factory.Settings.QueryTranslatorFactory.CreateFilterTranslator(hql, concreteQueryStrings[i], enabledFilters,
                                                                                       factory);
                    ((IFilterTranslator)translators[i]).Compile(collectionRole, factory.Settings.QuerySubstitutions, shallow);
                }
                foreach (string qs in translators[i].QuerySpaces)
                {
                    combinedQuerySpaces.Add(qs);
                }
                sqlStringList.AddRange(translators[i].CollectSqlStrings);
            }

            sqlStrings  = sqlStringList.ToArray();
            querySpaces = combinedQuerySpaces;

            if (length == 0)
            {
                parameterMetadata = new ParameterMetadata(null, null);
                returnMetadata    = null;
            }
            else
            {
                parameterMetadata = BuildParameterMetadata(translators[0].GetParameterTranslations(), hql);
                if (translators[0].IsManipulationStatement)
                {
                    returnMetadata = null;
                }
                else
                {
                    if (length > 1)
                    {
                        int returns = translators[0].ReturnTypes.Length;
                        returnMetadata = new ReturnMetadata(translators[0].ReturnAliases, new IType[returns]);
                    }
                    else
                    {
                        returnMetadata = new ReturnMetadata(translators[0].ReturnAliases, translators[0].ReturnTypes);
                    }
                }
            }
        }