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
        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);
                    }
                }
            }
        }