Exemple #1
0
        public ISQLQuery SetResultSetMapping(string name)
        {
            ResultSetMappingDefinition mapping = Session.Factory.GetResultSetMapping(name);

            if (mapping == null)
            {
                throw new MappingException("Unknown SqlResultSetMapping [" + name + "]");
            }
            INativeSQLQueryReturn[] returns = mapping.GetQueryReturns();
            int length = returns.Length;

            for (int index = 0; index < length; index++)
            {
                queryReturns.Add(returns[index]);
            }
            return(this);
        }
Exemple #2
0
        /// <summary> Constructs a SQLQueryImpl given a sql query defined in the mappings. </summary>
        /// <param name="queryDef">The representation of the defined sql-query. </param>
        /// <param name="session">The session to which this SQLQueryImpl belongs. </param>
        /// <param name="parameterMetadata">Metadata about parameters found in the query. </param>
        internal SqlQueryImpl(NamedSQLQueryDefinition queryDef, ISessionImplementor session, ParameterMetadata parameterMetadata)
            : base(queryDef.QueryString, queryDef.FlushMode, session, parameterMetadata)
        {
            if (!string.IsNullOrEmpty(queryDef.ResultSetRef))
            {
                ResultSetMappingDefinition definition = session.Factory.GetResultSetMapping(queryDef.ResultSetRef);
                if (definition == null)
                {
                    throw new MappingException("Unable to find resultset-ref definition: " + queryDef.ResultSetRef);
                }
                queryReturns = new List <INativeSQLQueryReturn>(definition.GetQueryReturns());
            }
            else
            {
                queryReturns = new List <INativeSQLQueryReturn>(queryDef.QueryReturns);
            }

            querySpaces = queryDef.QuerySpaces;
            callable    = queryDef.IsCallable;
        }
Exemple #3
0
        private IDictionary <string, HibernateException> CheckNamedQueries()
        {
            IDictionary <string, HibernateException> errors = new Dictionary <string, HibernateException>();

            // Check named HQL queries
            log.Debug("Checking " + namedQueries.Count + " named HQL queries");
            foreach (var entry in namedQueries)
            {
                string queryName        = entry.Key;
                NamedQueryDefinition qd = entry.Value;
                // this will throw an error if there's something wrong.
                try
                {
                    log.Debug("Checking named query: " + queryName);
                    //TODO: BUG! this currently fails for named queries for non-POJO entities
                    queryPlanCache.GetHQLQueryPlan(qd.QueryString.ToQueryExpression(), false, new CollectionHelper.EmptyMapClass <string, IFilter>());
                }
                catch (QueryException e)
                {
                    errors[queryName] = e;
                }
                catch (MappingException e)
                {
                    errors[queryName] = e;
                }
            }

            log.Debug("Checking " + namedSqlQueries.Count + " named SQL queries");
            foreach (KeyValuePair <string, NamedSQLQueryDefinition> entry in namedSqlQueries)
            {
                string queryName           = entry.Key;
                NamedSQLQueryDefinition qd = entry.Value;
                // this will throw an error if there's something wrong.
                try
                {
                    log.Debug("Checking named SQL query: " + queryName);
                    // TODO : would be really nice to cache the spec on the query-def so as to not have to re-calc the hash;
                    // currently not doable though because of the resultset-ref stuff...
                    NativeSQLQuerySpecification spec;
                    if (qd.ResultSetRef != null)
                    {
                        ResultSetMappingDefinition definition = sqlResultSetMappings[qd.ResultSetRef];
                        if (definition == null)
                        {
                            throw new MappingException("Unable to find resultset-ref definition: " + qd.ResultSetRef);
                        }
                        spec = new NativeSQLQuerySpecification(qd.QueryString, definition.GetQueryReturns(), qd.QuerySpaces);
                    }
                    else
                    {
                        spec = new NativeSQLQuerySpecification(qd.QueryString, qd.QueryReturns, qd.QuerySpaces);
                    }
                    queryPlanCache.GetNativeSQLQueryPlan(spec);
                }
                catch (QueryException e)
                {
                    errors[queryName] = e;
                }
                catch (MappingException e)
                {
                    errors[queryName] = e;
                }
            }

            return(errors);
        }