コード例 #1
0
		private void RenderPropertiesSelect(QuerySelect sql)
		{
			int size = returnedTypes.Count;
			for (int k = 0; k < size; k++)
			{
				string suffix = (size == 1) ? String.Empty : k.ToString() + StringHelper.Underscore;
				string name = (string) returnedTypes[k];
				sql.AddSelectFragmentString(new SqlString(persisters[k].PropertySelectFragment(name, suffix, false)));
			}
		}
コード例 #2
0
		private void RenderIdentifierSelect(QuerySelect sql)
		{
			int size = returnedTypes.Count;

			for (int k = 0; k < size; k++)
			{
				string name = returnedTypes[k];
				string suffix = size == 1 ? String.Empty : k.ToString() + StringHelper.Underscore;
				sql.AddSelectFragmentString(new SqlString(persisters[k].IdentifierSelectFragment(name, suffix)));
			}
		}
コード例 #3
0
			public void AddOrderBy(QuerySelect sql)
			{
				if (persisters == null)
				{
					return;
				}

				for (int i = 0; i < count; i++)
				{
					IQueryableCollection persister = (IQueryableCollection) persisters[i];
					if (persister.HasOrdering)
					{
						sql.AddOrderBy(persister.GetSQLOrderByString(names[i]));
					}
				}
			}
コード例 #4
0
		private void RenderSql()
		{
			int rtsize;
			if (returnedTypes.Count == 0 && scalarTypes.Count == 0)
			{
				//ie no select clause in HQL
				returnedTypes = fromTypes;
				rtsize = returnedTypes.Count;
			}
			else
			{
				rtsize = returnedTypes.Count;
				foreach (string entityName in entitiesToFetch)
				{
					returnedTypes.Add(entityName);
				}
			}

			int size = returnedTypes.Count;
			persisters = new IQueryable[size];
			names = new string[size];
			owners = new int[size];
			ownerAssociationTypes = new EntityType[size];
			suffixes = new string[size];
			includeInSelect = new bool[size];
			for (int i = 0; i < size; i++)
			{
				string name = returnedTypes[i];
				//if ( !IsName(name) ) throw new QueryException("unknown type: " + name);
				persisters[i] = GetPersisterForName(name);
				suffixes[i] = (size == 1) ? String.Empty : i.ToString() + StringHelper.Underscore;
				names[i] = name;
				includeInSelect[i] = !entitiesToFetch.Contains(name);
				if (includeInSelect[i])
				{
					selectLength++;
				}
				string oneToOneOwner;
				owners[i] = !oneToOneOwnerNames.TryGetValue(name, out oneToOneOwner) ? -1 : returnedTypes.IndexOf(oneToOneOwner);
				IAssociationType oat;
				if (uniqueKeyOwnerReferences.TryGetValue(name, out oat))
					ownerAssociationTypes[i] = (EntityType) oat;
			}

			fetchedCollections.InitializeCollectionOwnerColumns(returnedTypes);

			if (ArrayHelper.IsAllNegative(owners))
			{
				owners = null;
			}

			SqlString scalarSelect = RenderScalarSelect(); //Must be done here because of side-effect! yuck...

			int scalarSize = scalarTypes.Count;
			hasScalars = scalarTypes.Count != rtsize;

			returnTypes = new IType[scalarSize];
			for (int i = 0; i < scalarSize; i++)
			{
				returnTypes[i] = scalarTypes[i];
			}

			QuerySelect sql = new QuerySelect(Factory.Dialect);
			sql.Distinct = distinct;

			if (!shallowQuery)
			{
				RenderIdentifierSelect(sql);
				RenderPropertiesSelect(sql);
			}

			fetchedCollections.AddSelectFragmentString(sql);

			if (hasScalars || shallowQuery)
			{
				sql.AddSelectFragmentString(scalarSelect);
			}

			// TODO: for some dialects it would be appropriate to add the renderOrderByPropertiesSelect() to other select strings
			MergeJoins(sql.JoinFragment);

			// HQL functions in whereTokens, groupByTokens, havingTokens and orderByTokens aren't rendered
			RenderFunctions(whereTokens);
			sql.SetWhereTokens(whereTokens);

			RenderFunctions(groupByTokens);
			sql.SetGroupByTokens(groupByTokens);

			RenderFunctions(havingTokens);
			sql.SetHavingTokens(havingTokens);

			RenderFunctions(orderByTokens);
			sql.SetOrderByTokens(orderByTokens);

			fetchedCollections.AddOrderBy(sql);

			scalarColumnNames = GenerateColumnNames(returnTypes, Factory);

			// initialize the set of queried identifer spaces (ie. tables)
			foreach (string name in collections.Values)
			{
				ICollectionPersister p = GetCollectionPersister(name);
				AddQuerySpaces(p.CollectionSpaces);
			}
			foreach (string name in typeMap.Keys)
			{
				IQueryable p = GetPersisterForName(name);
				AddQuerySpaces(p.QuerySpaces);
			}

			sqlString = sql.ToQuerySqlString();

			try
			{
				if (holderClass != null)
				{
					holderConstructor = ReflectHelper.GetConstructor(holderClass, returnTypes);
				}
			}
			catch (Exception nsme)
			{
				throw new QueryException("could not find constructor for: " + holderClass.Name, nsme);
			}

			if (hasScalars)
			{
				actualReturnTypes = returnTypes;
			}
			else
			{
				actualReturnTypes = new IType[selectLength];
				int j = 0;
				for (int i = 0; i < persisters.Length; i++)
				{
					if (includeInSelect[i])
					{
						actualReturnTypes[j++] = NHibernateUtil.Entity(persisters[i].EntityName);
					}
				}
			}
		}
コード例 #5
0
			public void AddSelectFragmentString(QuerySelect sql)
			{
				if (persisters == null)
				{
					return;
				}

				for (int i = 0; i < count; i++)
				{
					sql.AddSelectFragmentString(new SqlString(
						((IQueryableCollection) persisters[i]).SelectFragment(
							(string) names[i], (string) suffixes[i])));
				}
			}