Example #1
0
        protected override string GenerateTableAlias(int n, string path, IJoinable joinable)
        {
            // TODO: deal with side-effects (changes to includeInSelectList, userAliasList, resultTypeList)!!!

            // for collection-of-entity, we are called twice for given "path"
            // once for the collection Joinable, once for the entity Joinable.
            // the second call will/must "consume" the alias + perform side effects according to consumesEntityAlias()
            // for collection-of-other, however, there is only one call
            // it must "consume" the alias + perform side effects, despite what consumeEntityAlias() return says
            //
            // note: the logic for adding to the userAliasList is still strictly based on consumesEntityAlias return value

            bool shouldCreateUserAlias = joinable.ConsumesEntityAlias();

            if (!shouldCreateUserAlias && joinable.IsCollection)
            {
                // is it a collection-of-other (component or value) ?
                var elementType = ((ICollectionPersister)joinable).ElementType;
                if (elementType != null)
                {
                    shouldCreateUserAlias = elementType.IsComponentType || !elementType.IsEntityType;
                }
            }

            string sqlAlias = null;

            if (shouldCreateUserAlias)
            {
                ICriteria subcriteria = translator.GetCriteria(path);
                sqlAlias = subcriteria == null ? null : translator.GetSQLAlias(subcriteria);

                if (joinable.ConsumesEntityAlias() && !translator.HasProjection)
                {
                    includeInResultRowList.Add(subcriteria != null && subcriteria.Alias != null);

                    if (sqlAlias != null)
                    {
                        if (subcriteria.Alias != null)
                        {
                            userAliasList.Add(subcriteria.Alias);                             //alias may be null
                            resultTypeList.Add(translator.ResultType(subcriteria));
                        }
                    }
                }
            }

            if (sqlAlias == null)
            {
                sqlAlias = base.GenerateTableAlias(n + translator.SQLAliasCount, path, joinable);
            }

            return(sqlAlias);
        }
Example #2
0
        protected override string GenerateTableAlias(int n, string path, IJoinable joinable)
        {
            bool shouldCreateUserAlias = joinable.ConsumesEntityAlias();

            if (shouldCreateUserAlias == false && joinable.IsCollection)
            {
                var elementType = ((ICollectionPersister)joinable).ElementType;
                if (elementType != null)
                {
                    shouldCreateUserAlias = elementType.IsComponentType;
                }
            }
            if (shouldCreateUserAlias)
            {
                ICriteria subcriteria = translator.GetCriteria(path);
                string    sqlAlias    = subcriteria == null ? null : translator.GetSQLAlias(subcriteria);
                if (sqlAlias != null)
                {
                    userAliasList.Add(subcriteria.Alias); //alias may be null
                    return(sqlAlias);                     //EARLY EXIT
                }

                userAliasList.Add(null);
            }
            return(base.GenerateTableAlias(n + translator.SQLAliasCount, path, joinable));
        }
Example #3
0
        /// <summary>
        /// Generate a select list of columns containing all properties of the entity classes
        /// </summary>
        public string SelectString(IList <OuterJoinableAssociation> associations)
        {
            if (associations.Count == 0)
            {
                return(string.Empty);
            }
            else
            {
                SqlStringBuilder buf = new SqlStringBuilder(associations.Count * 3);

                int entityAliasCount     = 0;
                int collectionAliasCount = 0;

                for (int i = 0; i < associations.Count; i++)
                {
                    OuterJoinableAssociation join = associations[i];
                    OuterJoinableAssociation next = (i == associations.Count - 1) ? null : associations[i + 1];

                    IJoinable joinable     = join.Joinable;
                    string    entitySuffix = (suffixes == null || entityAliasCount >= suffixes.Length) ? null : suffixes[entityAliasCount];

                    string collectionSuffix = (collectionSuffixes == null || collectionAliasCount >= collectionSuffixes.Length)
                                                                                                                                                        ? null
                                                                                                                                                        : collectionSuffixes[collectionAliasCount];

                    string selectFragment =
                        joinable.SelectFragment(next == null ? null : next.Joinable, next == null ? null : next.RHSAlias, join.RHSAlias,
                                                entitySuffix, collectionSuffix, join.JoinType == JoinType.LeftOuterJoin);

                    if (selectFragment.Trim().Length > 0)
                    {
                        buf.Add(StringHelper.CommaSpace)
                        .Add(selectFragment);
                    }
                    if (joinable.ConsumesEntityAlias())
                    {
                        entityAliasCount++;
                    }

                    if (joinable.ConsumesCollectionAlias() && join.JoinType == JoinType.LeftOuterJoin)
                    {
                        collectionAliasCount++;
                    }
                }

                return(buf.ToSqlString().ToString());
            }
        }
Example #4
0
        private void IncludeInResultIfNeeded(IJoinable joinable, ICriteria subcriteria, string sqlAlias)
        {
            if (joinable.ConsumesEntityAlias() && !translator.HasProjection)
            {
                includeInResultRowList.Add(subcriteria != null && subcriteria.Alias != null);

                if (sqlAlias != null)
                {
                    if (subcriteria.Alias != null)
                    {
                        userAliasList.Add(subcriteria.Alias);                         //alias may be null
                        resultTypeList.Add(translator.ResultType(subcriteria));
                    }
                }
            }
        }
Example #5
0
        /// <summary>
        /// Generate a select list of columns containing all properties of the entity classes
        /// </summary>
        public string SelectString(IList <OuterJoinableAssociation> associations)
        {
            if (associations.Count == 0)
            {
                return(string.Empty);
            }
            else
            {
                SqlStringBuilder buf = new SqlStringBuilder(associations.Count * 3);

                int entityAliasCount     = 0;
                int collectionAliasCount = 0;

                for (int i = 0; i < associations.Count; i++)
                {
                    OuterJoinableAssociation join = associations[i];
                    OuterJoinableAssociation next = (i == associations.Count - 1) ? null : associations[i + 1];

                    IJoinable joinable     = join.Joinable;
                    string    entitySuffix = (suffixes == null || entityAliasCount >= suffixes.Length) ? null : suffixes[entityAliasCount];

                    string collectionSuffix = (collectionSuffixes == null || collectionAliasCount >= collectionSuffixes.Length)
                                                                                                                                                        ? null
                                                                                                                                                        : collectionSuffixes[collectionAliasCount];

                    string selectFragment =
                        GetSelectFragment(join, entitySuffix, collectionSuffix, next);

                    if (!string.IsNullOrWhiteSpace(selectFragment))
                    {
                        buf.Add(StringHelper.CommaSpace)
                        .Add(selectFragment);
                    }
                    if (joinable.ConsumesEntityAlias() && join.SelectMode != SelectMode.JoinOnly)
                    {
                        entityAliasCount++;
                    }

                    if (joinable.ConsumesCollectionAlias() && join.ShouldFetchCollectionPersister())
                    {
                        collectionAliasCount++;
                    }
                }

                return(buf.ToSqlString().ToString());
            }
        }
        private void IncludeInResultIfNeeded(IJoinable joinable, ICriteria subcriteria, string sqlAlias, string path)
        {
            if (joinable.ConsumesEntityAlias() && !translator.HasProjection)
            {
                var includedInSelect = translator.RootCriteria.GetSelectMode(path) != SelectMode.JoinOnly;
                includeInResultRowList.Add(subcriteria != null && subcriteria.Alias != null && includedInSelect);

                if (sqlAlias != null && includedInSelect)
                {
                    if (subcriteria.Alias != null)
                    {
                        userAliasList.Add(subcriteria.Alias);                         //alias may be null
                        resultTypeList.Add(translator.ResultType(subcriteria));
                    }
                }
            }
        }
        protected override string GenerateTableAlias(int n, string path, IJoinable joinable)
        {
            // TODO: deal with side-effects (changes to includeInSelectList, userAliasList, resultTypeList)!!!
            bool shouldCreateUserAlias = joinable.ConsumesEntityAlias();

            if (shouldCreateUserAlias == false && joinable.IsCollection)
            {
                var elementType = ((ICollectionPersister)joinable).ElementType;
                if (elementType != null)
                {
                    shouldCreateUserAlias = elementType.IsComponentType;
                }
            }
            if (shouldCreateUserAlias)
            {
                ICriteria subcriteria = translator.GetCriteria(path);
                string    sqlAlias    = subcriteria == null ? null : translator.GetSQLAlias(subcriteria);
                if (sqlAlias != null)
                {
                    if (!translator.HasProjection)
                    {
                        includeInResultRowList.Add(subcriteria.Alias != null);
                        if (subcriteria.Alias != null)
                        {
                            userAliasList.Add(subcriteria.Alias);                             //alias may be null
                            resultTypeList.Add(translator.ResultType(subcriteria));
                        }
                    }
                    return(sqlAlias);                    //EARLY EXIT
                }
                else
                {
                    if (!translator.HasProjection)
                    {
                        includeInResultRowList.Add(false);
                    }
                }
            }
            return(base.GenerateTableAlias(n + translator.SQLAliasCount, path, joinable));
        }
Example #8
0
 protected override string GenerateTableAlias(int n, string path, IJoinable joinable)
 {
     if (joinable.ConsumesEntityAlias())
     {
         ICriteria subcriteria = translator.GetCriteria(path);
         String sqlAlias = subcriteria == null ? null : translator.GetSQLAlias(subcriteria);
         if (sqlAlias != null)
         {
             userAliasList.Add(subcriteria.Alias); //alias may be null
             return sqlAlias; //EARLY EXIT
         }
         else
         {
             userAliasList.Add(null);
         }
     }
     return base.GenerateTableAlias(n + translator.SQLAliasCount, path, joinable);
 }
		protected override string GenerateTableAlias(int n, string path, IJoinable joinable)
		{
			bool shouldCreateUserAlias = joinable.ConsumesEntityAlias(); 
			if(shouldCreateUserAlias == false  && joinable.IsCollection)
			{
				var elementType = ((ICollectionPersister)joinable).ElementType;
				if (elementType != null)
					shouldCreateUserAlias = elementType.IsComponentType;
			}
			if (shouldCreateUserAlias)
			{
				ICriteria subcriteria = translator.GetCriteria(path);
				string sqlAlias = subcriteria == null ? null : translator.GetSQLAlias(subcriteria);
				if (sqlAlias != null)
				{
					userAliasList.Add(subcriteria.Alias); //alias may be null
					return sqlAlias; //EARLY EXIT
				}

				userAliasList.Add(null);
			}
			return base.GenerateTableAlias(n + translator.SQLAliasCount, path, joinable);
		}
		protected override string GenerateTableAlias(int n, string path, IJoinable joinable)
		{
			// TODO: deal with side-effects (changes to includeInSelectList, userAliasList, resultTypeList)!!!
			bool shouldCreateUserAlias = joinable.ConsumesEntityAlias(); 
			if(shouldCreateUserAlias == false  && joinable.IsCollection)
			{
				var elementType = ((ICollectionPersister)joinable).ElementType;
				if (elementType != null)
					shouldCreateUserAlias = elementType.IsComponentType;
			}
			if (shouldCreateUserAlias)
			{
				ICriteria subcriteria = translator.GetCriteria(path);
				string sqlAlias = subcriteria == null ? null : translator.GetSQLAlias(subcriteria);
				if (sqlAlias != null)
				{
					if (!translator.HasProjection)
					{
						includeInResultRowList.Add(subcriteria.Alias != null);
						if (subcriteria.Alias!=null)
						{
							userAliasList.Add(subcriteria.Alias); //alias may be null
							resultTypeList.Add(translator.ResultType(subcriteria));
						}
					}
					return sqlAlias; //EARLY EXIT
				}
				else
				{
					if (!translator.HasProjection)
						includeInResultRowList.Add(false);
				}
			}
			return base.GenerateTableAlias(n + translator.SQLAliasCount, path, joinable);
		}
		protected override string GenerateTableAlias(int n, string path, IJoinable joinable)
		{
			// TODO: deal with side-effects (changes to includeInSelectList, userAliasList, resultTypeList)!!!

			// for collection-of-entity, we are called twice for given "path"
			// once for the collection Joinable, once for the entity Joinable.
			// the second call will/must "consume" the alias + perform side effects according to consumesEntityAlias()
			// for collection-of-other, however, there is only one call 
			// it must "consume" the alias + perform side effects, despite what consumeEntityAlias() return says
			// 
			// note: the logic for adding to the userAliasList is still strictly based on consumesEntityAlias return value

			bool shouldCreateUserAlias = joinable.ConsumesEntityAlias();
			if (!shouldCreateUserAlias && joinable.IsCollection)
			{
				// is it a collection-of-other (component or value) ?
				var elementType = ((ICollectionPersister) joinable).ElementType;
				if (elementType != null)
					shouldCreateUserAlias = elementType.IsComponentType || !elementType.IsEntityType;
			}

			string sqlAlias = null;

			if (shouldCreateUserAlias)
			{
				ICriteria subcriteria = translator.GetCriteria(path);
				sqlAlias = subcriteria == null ? null : translator.GetSQLAlias(subcriteria);

				if (joinable.ConsumesEntityAlias() && !translator.HasProjection)
				{
					includeInResultRowList.Add(subcriteria != null && subcriteria.Alias != null);

					if (sqlAlias != null)
					{
						if (subcriteria.Alias != null)
						{
							userAliasList.Add(subcriteria.Alias); //alias may be null
							resultTypeList.Add(translator.ResultType(subcriteria));
						}
					}
				}
			}

			if (sqlAlias == null)
				sqlAlias = base.GenerateTableAlias(n + translator.SQLAliasCount, path, joinable);

			return sqlAlias;
		}