public void AddQuery(HbmQuery querySchema) { string queryName = querySchema.name; string queryText = querySchema.GetText(); log.DebugFormat("Named query: {0} -> {1}", queryName, queryText); bool cacheable = querySchema.cacheable; string region = querySchema.cacheregion; int timeout = string.IsNullOrEmpty(querySchema.timeout) ? RowSelection.NoValue : int.Parse(querySchema.timeout); int fetchSize = querySchema.fetchsizeSpecified ? querySchema.fetchsize : -1; bool readOnly = querySchema.readonlySpecified ? querySchema.@readonly : false; string comment = querySchema.comment; FlushMode flushMode = FlushModeConverter.GetFlushMode(querySchema); CacheMode?cacheMode = (querySchema.cachemodeSpecified) ? querySchema.cachemode.ToCacheMode() : null; IDictionary <string, string> parameterTypes = new LinkedHashMap <string, string>(); var namedQuery = new NamedQueryDefinition(queryText, cacheable, region, timeout, fetchSize, flushMode, cacheMode, readOnly, comment, parameterTypes); mappings.AddQuery(queryName, namedQuery); }
private void InitQuery(IQuery query, NamedQueryDefinition nqd) { using (new SessionIdLoggingContext(SessionId)) { query.SetCacheable(nqd.IsCacheable); query.SetCacheRegion(nqd.CacheRegion); if (nqd.Timeout != -1) { query.SetTimeout(nqd.Timeout); } if (nqd.FetchSize != -1) { query.SetFetchSize(nqd.FetchSize); } if (nqd.CacheMode.HasValue) { query.SetCacheMode(nqd.CacheMode.Value); } query.SetReadOnly(nqd.IsReadOnly); if (nqd.Comment != null) { query.SetComment(nqd.Comment); } query.SetFlushMode(nqd.FlushMode); } }
public virtual IQuery GetNamedQuery(string queryName) { using (new SessionIdLoggingContext(SessionId)) { CheckAndUpdateSessionStatus(); NamedQueryDefinition nqd = factory.GetNamedQuery(queryName); IQuery query; if (nqd != null) { string queryString = nqd.QueryString; query = new QueryImpl(queryString, nqd.FlushMode, this, GetHQLQueryPlan(queryString.ToQueryExpression(), false).ParameterMetadata); query.SetComment("named HQL query " + queryName); } else { NamedSQLQueryDefinition nsqlqd = factory.GetNamedSQLQuery(queryName); if (nsqlqd == null) { throw new MappingException("Named query not known: " + queryName); } query = new SqlQueryImpl(nsqlqd, this, factory.QueryPlanCache.GetSQLParameterMetadata(nsqlqd.QueryString)); query.SetComment("named native SQL query " + queryName); nqd = nsqlqd; } InitQuery(query, nqd); return(query); } }
private void SetDefaultProperties(ISessionFactoryImplementor factory) { NamedQueryDefinition nqd = factory.GetNamedQuery(queryName) ?? factory.GetNamedSQLQuery(queryName); if (!cacheableWasSet) { cacheable = nqd.IsCacheable; } if (!cacheRegionWasSet) { cacheRegion = nqd.CacheRegion; } if (!timeoutWasSet && nqd.Timeout != -1) { selection.Timeout = nqd.Timeout; } if (!fetchSizeWasSet && nqd.FetchSize != -1) { selection.FetchSize = nqd.FetchSize; } if (!cacheModeWasSet && nqd.CacheMode.HasValue) { cacheMode = nqd.CacheMode.Value; } if (!readOnlyWasSet) { readOnly = nqd.IsReadOnly; } if (!commentWasSet && nqd.Comment != null) { comment = nqd.Comment; } if (!flushModeWasSet) { flushMode = nqd.FlushMode; } }
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); }
public void AddQuery(string name, NamedQueryDefinition query) { CheckQueryExists(name); queries[name] = query; }