コード例 #1
0
		public void AddSqlQuery(HbmSqlQuery querySchema)
		{
			mappings.AddSecondPass(delegate
				{
					string queryName = querySchema.name;
					string queryText = querySchema.GetText();
					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 = null;
					bool callable = querySchema.callable;
					string resultSetRef = querySchema.resultsetref;

					FlushMode flushMode = FlushModeConverter.GetFlushMode(querySchema);
					CacheMode? cacheMode = (querySchema.cachemodeSpecified)
												? querySchema.cachemode.ToCacheMode()
												: null;

					IDictionary<string,string> parameterTypes = new LinkedHashMap<string,string>();
					IList<string> synchronizedTables = GetSynchronizedTables(querySchema);

					NamedSQLQueryDefinition namedQuery;

					if (string.IsNullOrEmpty(resultSetRef))
					{
						ResultSetMappingDefinition definition =
							new ResultSetMappingBinder(Mappings).Create(querySchema);

						namedQuery = new NamedSQLQueryDefinition(queryText,
							definition.GetQueryReturns(), synchronizedTables, cacheable, region, timeout,
							fetchSize, flushMode, cacheMode, readOnly, comment, parameterTypes, callable);
					}
					else
						// TODO: check there is no actual definition elemnents when a ref is defined
						namedQuery = new NamedSQLQueryDefinition(queryText,
							resultSetRef, synchronizedTables, cacheable, region, timeout, fetchSize,
							flushMode, cacheMode, readOnly, comment, parameterTypes, callable);

					log.DebugFormat("Named SQL query: {0} -> {1}", queryName, namedQuery.QueryString);
					mappings.AddSQLQuery(queryName, namedQuery);
				});
		}
コード例 #2
0
		public void AddSQLQuery(string name, NamedSQLQueryDefinition query)
		{
			CheckQueryExists(name);
			sqlqueries[name] = query;
		}
コード例 #3
0
		public void DoSecondPass(IDictionary persistentClasses)
		{
			String queryName = queryElem.Attributes["name"].Value;
			if (path != null)
			{
				queryName = path + '.' + queryName;
			}

			bool cacheable = "true".Equals(XmlHelper.GetAttributeValue(queryElem, "cacheable"));
			string region = XmlHelper.GetAttributeValue(queryElem, "cache-region");
			XmlAttribute tAtt = queryElem.Attributes["timeout"];
			int timeout = tAtt == null ? -1 : int.Parse(tAtt.Value);
			XmlAttribute fsAtt = queryElem.Attributes["fetch-size"];
			int fetchSize = fsAtt == null ? -1 : int.Parse(fsAtt.Value);
			XmlAttribute roAttr = queryElem.Attributes["read-only"];
			bool readOnly = roAttr != null && "true".Equals(roAttr.Value);
			XmlAttribute cacheModeAtt = queryElem.Attributes["cache-mode"];
			string cacheMode = cacheModeAtt == null ? null : cacheModeAtt.Value;
			XmlAttribute cmAtt = queryElem.Attributes["comment"];
			string comment = cmAtt == null ? null : cmAtt.Value;

			IList synchronizedTables = new ArrayList();

			foreach (XmlNode item in queryElem.SelectNodes(HbmConstants.nsSynchronize, nsmgr))
			{
				synchronizedTables.Add(XmlHelper.GetAttributeValue(item, "table"));
			}
			bool callable = "true".Equals(XmlHelper.GetAttributeValue(queryElem, "callable"));

			NamedSQLQueryDefinition namedQuery;
			XmlAttribute @ref = queryElem.Attributes["resultset-ref"];
			string resultSetRef = @ref == null ? null : @ref.Value;
			if (StringHelper.IsNotEmpty(resultSetRef))
			{
				namedQuery = new NamedSQLQueryDefinition(
					queryElem.InnerText,
					resultSetRef,
					synchronizedTables,
					cacheable,
					region,
					timeout,
					fetchSize,
					HbmBinder.GetFlushMode(XmlHelper.GetAttributeValue(queryElem, "flush-mode")),
					//HbmBinder.GetCacheMode(cacheMode),
					readOnly,
					comment,
					HbmBinder.GetParameterTypes(queryElem),
					callable
					);
				//TODO check there is no actual definition elemnents when a ref is defined
			}
			else
			{
				ResultSetMappingDefinition definition = BuildResultSetMappingDefinition(queryElem, path, mappings);
				namedQuery = new NamedSQLQueryDefinition(
					queryElem.InnerText,
					definition.GetQueryReturns(),
					synchronizedTables,
					cacheable,
					region,
					timeout,
					fetchSize,
					HbmBinder.GetFlushMode(XmlHelper.GetAttributeValue(queryElem, "flush-mode")),
					//HbmBinder.GetCacheMode(cacheMode),
					readOnly,
					comment,
					HbmBinder.GetParameterTypes(queryElem),
					callable
					);
			}

			log.Debug("Named SQL query: " + queryName + " -> " + namedQuery.QueryString);
			mappings.AddSQLQuery(queryName, namedQuery);
		}