public CriteriaLoader(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria,
							  string rootEntityName, IDictionary<string, IFilter> enabledFilters)
			: base(factory, enabledFilters)
		{
			translator = new CriteriaQueryTranslator(factory, rootCriteria, rootEntityName, CriteriaQueryTranslator.RootSqlAlias);

			querySpaces = translator.GetQuerySpaces();

			CriteriaJoinWalker walker =
				new CriteriaJoinWalker(persister, translator, factory, rootCriteria, rootEntityName, enabledFilters);

			InitFromWalker(walker);

			userAliases = walker.UserAliases;
			resultTypes = walker.ResultTypes;
			includeInResultRow = walker.IncludeInResultRow;
			resultRowLength = ArrayHelper.CountTrue(IncludeInResultRow);
			// fill caching objects only if there is a projection
			if (translator.HasProjection)
			{
				cachedProjectedColumnAliases = translator.ProjectedColumnAliases;
			}

			PostInstantiate();
		}
		public CriteriaLoader(
			IOuterJoinLoadable persister,
			ISessionFactoryImplementor factory,
			CriteriaImpl rootCriteria,
			System.Type rootEntityName, // TODO H3: change to string rootEntityName
			IDictionary enabledFilters)
			: base(factory, enabledFilters)
		{
			translator = new CriteriaQueryTranslator(
				factory,
				rootCriteria,
				rootEntityName,
				CriteriaQueryTranslator.RootSqlAlias);

			querySpaces = translator.GetQuerySpaces();

			CriteriaJoinWalker walker = new CriteriaJoinWalker(
				persister,
				translator,
				factory,
				rootCriteria,
				rootEntityName,
				enabledFilters);

			InitFromWalker(walker);

			userAliases = walker.UserAliases;
			resultTypes = walker.ResultTypes;

			PostInstantiate();
		}
Example #3
0
        public CriteriaJoinWalker(IOuterJoinLoadable persister,CriteriaQueryTranslator translator,
            ISessionFactoryImplementor factory, CriteriaImpl criteria, string rootEntityName,
            IDictionary<string, IFilter> enabledFilters)
            : base(translator.RootSQLAlias, persister, factory, enabledFilters)
        {
            this.translator = translator;

            querySpaces = translator.GetQuerySpaces();

            if (translator.HasProjection)
            {
                resultTypes = translator.ProjectedTypes;

                InitProjection(
                    translator.GetSelect(enabledFilters),
                    translator.GetWhereCondition(enabledFilters),
                    translator.GetOrderBy(),
                    translator.GetGroupBy().ToString(),
                    LockMode.None
                    );
            }
            else
            {
                resultTypes = new IType[] {TypeFactory.ManyToOne(persister.EntityName)};

                InitAll(translator.GetWhereCondition(enabledFilters), translator.GetOrderBy(), LockMode.None);
            }

            userAliasList.Add(criteria.Alias); //root entity comes *last*
            userAliases = ArrayHelper.ToStringArray(userAliasList);
        }
        private void InitStatementString(IOuterJoinLoadable elementPersister, string alias, int batchSize, SqlString subquery)
        {
            int joins = CountEntityPersisters(associations);

            Suffixes = BasicLoader.GenerateSuffixes(joins + 1);

            int collectionJoins = CountCollectionPersisters(associations) + 1;

            CollectionSuffixes = BasicLoader.GenerateSuffixes(joins + 1, collectionJoins);

            SqlStringBuilder whereString = WhereString(oneToManyPersister.GenerateTableAliasForKeyColumns(alias), oneToManyPersister.KeyColumnNames, subquery, batchSize);
            string           filter      = oneToManyPersister.FilterFragment(alias, EnabledFilters);

            whereString.Insert(0, StringHelper.MoveAndToBeginning(filter));

            JoinFragment     ojf    = MergeOuterJoins(associations);
            SqlSelectBuilder select =
                new SqlSelectBuilder(Factory).SetSelectClause(
                    oneToManyPersister.SelectFragment(null, null, alias, Suffixes[joins], CollectionSuffixes[0], true)
                    + SelectString(associations)).SetFromClause(elementPersister.FromTableFragment(alias)
                                                                + oneToManyPersister.FromJoinFragment(alias, true, true)).SetWhereClause(
                    whereString.ToSqlString()).SetOuterJoins(ojf.ToFromFragmentString,
                                                             ojf.ToWhereFragmentString
                                                             + elementPersister.WhereJoinFragment(alias, true, true));

            select.SetOrderByClause(OrderBy(associations, oneToManyPersister.GetSQLOrderByString(alias)));

            if (Factory.Settings.IsCommentsEnabled)
            {
                select.SetComment("load one-to-many " + oneToManyPersister.Role);
            }

            SqlString = select.ToSqlString();
        }
Example #5
0
        public CriteriaJoinWalker(IOuterJoinLoadable persister, CriteriaQueryTranslator translator,
                                  ISessionFactoryImplementor factory, ICriteria criteria, string rootEntityName,
                                  IDictionary <string, IFilter> enabledFilters)
            : base(translator.RootSQLAlias, persister, factory, enabledFilters)
        {
            this.translator = translator;

            querySpaces = translator.GetQuerySpaces();

            if (translator.HasProjection)
            {
                resultTypes = translator.ProjectedTypes;

                InitProjection(
                    translator.GetSelect(enabledFilters),
                    translator.GetWhereCondition(enabledFilters),
                    translator.GetOrderBy(),
                    translator.GetGroupBy(),
                    translator.GetHavingCondition(enabledFilters),
                    enabledFilters,
                    LockMode.None);
            }
            else
            {
                resultTypes = new IType[] { TypeFactory.ManyToOne(persister.EntityName) };

                InitAll(translator.GetWhereCondition(enabledFilters), translator.GetOrderBy(), LockMode.None);
            }

            userAliasList.Add(criteria.Alias);             //root entity comes *last*
            userAliases = userAliasList.ToArray();
        }
Example #6
0
		private void InitStatementString(IOuterJoinLoadable elementPersister, string alias, int batchSize, SqlString subquery)
		{
			int joins = CountEntityPersisters(associations);
			Suffixes = BasicLoader.GenerateSuffixes(joins + 1);

			int collectionJoins = CountCollectionPersisters(associations) + 1;
			CollectionSuffixes = BasicLoader.GenerateSuffixes(joins + 1, collectionJoins);

			SqlStringBuilder whereString = WhereString(alias, oneToManyPersister.KeyColumnNames, subquery, batchSize);
			string filter = oneToManyPersister.FilterFragment(alias, EnabledFilters);
			whereString.Insert(0, StringHelper.MoveAndToBeginning(filter));

			JoinFragment ojf = MergeOuterJoins(associations);
			SqlSelectBuilder select =
				new SqlSelectBuilder(Factory).SetSelectClause(
					oneToManyPersister.SelectFragment(null, null, alias, Suffixes[joins], CollectionSuffixes[0], true)
					+ SelectString(associations)).SetFromClause(elementPersister.FromTableFragment(alias)
					                                            + elementPersister.FromJoinFragment(alias, true, true)).SetWhereClause(
					whereString.ToSqlString()).SetOuterJoins(ojf.ToFromFragmentString,
					                                         ojf.ToWhereFragmentString
					                                         + elementPersister.WhereJoinFragment(alias, true, true));

			select.SetOrderByClause(OrderBy(associations, oneToManyPersister.GetSQLOrderByString(alias)));

			if (Factory.Settings.IsCommentsEnabled)
			{
				select.SetComment("load one-to-many " + oneToManyPersister.Role);
			}

			SqlString = select.ToSqlString();
		}
		public AbstractEntityJoinWalker(IOuterJoinLoadable persister, ISessionFactoryImplementor factory,
																		IDictionary<string, IFilter> enabledFilters)
			: base(factory, enabledFilters)
		{
			this.persister = persister;
			alias = GenerateRootAlias(persister.EntityName);
		}
		public AbstractEntityLoader(IOuterJoinLoadable persister, IType uniqueKeyType, ISessionFactoryImplementor factory,
		                            IDictionary<string, IFilter> enabledFilters) : base(factory, enabledFilters)
		{
			this.uniqueKeyType = uniqueKeyType;
			entityName = persister.EntityName;
			this.persister = persister;
		}
Example #9
0
        /// <summary>
        /// Add on association (one-to-one, many-to-one, or a collection) to a list
        /// of associations to be fetched by outerjoin
        /// </summary>
        private void AddAssociationToJoinTree(IAssociationType type, string[] aliasedLhsColumns, string alias,
                                              string path, int currentDepth, JoinType joinType)
        {
            IJoinable joinable = type.GetAssociatedJoinable(Factory);

            string subalias = GenerateTableAlias(associations.Count + 1, path, joinable);

            OuterJoinableAssociation assoc =
                new OuterJoinableAssociation(type, alias, aliasedLhsColumns, subalias, joinType, GetWithClause(path), Factory, enabledFilters);

            assoc.ValidateJoin(path);
            AddAssociation(subalias, assoc);

            int nextDepth = currentDepth + 1;

            if (!joinable.IsCollection)
            {
                IOuterJoinLoadable pjl = joinable as IOuterJoinLoadable;
                if (pjl != null)
                {
                    WalkEntityTree(pjl, subalias, path, nextDepth);
                }
            }
            else
            {
                IQueryableCollection qc = joinable as IQueryableCollection;
                if (qc != null)
                {
                    WalkCollectionTree(qc, subalias, path, nextDepth);
                }
            }
        }
Example #10
0
        internal void AddExplicitEntityJoinAssociation(
            IOuterJoinLoadable persister,
            string tableAlias,
            JoinType joinType,
            string path,
            string pathAlias)
        {
            OuterJoinableAssociation assoc =
                InitAssociation(new OuterJoinableAssociation(
                                    persister.EntityType,
                                    string.Empty,
                                    Array.Empty <string>(),
                                    tableAlias,
                                    joinType,
                                    GetWithClause(path, pathAlias),
                                    Factory,
                                    enabledFilters,
                                    GetSelectMode(path))
            {
                ForceFilter = true
            },
                                path);

            AddAssociation(assoc);
        }
		public AbstractEntityJoinWalker(string alias, IOuterJoinLoadable persister, ISessionFactoryImplementor factory,
		                                IDictionary enabledFilters)
			: base(factory, enabledFilters)
		{
			this.persister = persister;
			this.alias = alias;
		}
Example #12
0
 protected AbstractEntityLoader(IOuterJoinLoadable persister, IType uniqueKeyType, ISessionFactoryImplementor factory,
                                IDictionary <string, IFilter> enabledFilters) : base(factory, enabledFilters)
 {
     UniqueKeyType  = uniqueKeyType;
     entityName     = persister.EntityName;
     this.persister = persister;
 }
		/// <summary>
		/// Get the columns of the owning entity which are to 
		/// be used in the join
		/// </summary>
		public static string[] GetLHSColumnNames(
			IAssociationType type,
			int property,
			int begin,
			IOuterJoinLoadable lhsPersister,
			IMapping mapping
			)
		{
			if (type.UseLHSPrimaryKey)
			{
				//return lhsPersister.getSubclassPropertyColumnNames(property);
				return lhsPersister.IdentifierColumnNames;
			}
			else
			{
				string propertyName = type.LHSPropertyName;
				if (propertyName == null)
				{
					//slice, to get the columns for this component
					//property
					return ArrayHelper.Slice(
						lhsPersister.GetSubclassPropertyColumnNames(property),
						begin,
						type.GetColumnSpan(mapping)
						);
				}
				else
				{
					//property-refs for associations defined on a
					//component are not supported, so no need to slice
					return lhsPersister.GetPropertyColumnNames(propertyName);
				}
			}
		}
		public EntityLoader(
			IOuterJoinLoadable persister,
			string[] uniqueKey,
			IType uniqueKeyType,
			int batchSize,
			LockMode lockMode,
			ISessionFactoryImplementor factory,
			IDictionary enabledFilters)
			: base(persister, uniqueKeyType, factory, enabledFilters)
		{
			JoinWalker walker = new EntityJoinWalker(
				persister,
				uniqueKey,
				uniqueKeyType,
				batchSize,
				lockMode,
				factory,
				enabledFilters
				);
			InitFromWalker(walker);

			PostInstantiate();

			batchLoader = batchSize > 1;

			log.Debug("Static select for entity " + entityName + ": " + SqlString);
		}
Example #15
0
        public CriteriaLoader(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria,
                              string rootEntityName, IDictionary <string, IFilter> enabledFilters)
            : base(factory, enabledFilters)
        {
            translator = new CriteriaQueryTranslator(factory, rootCriteria, rootEntityName, CriteriaQueryTranslator.RootSqlAlias);

            querySpaces = translator.GetQuerySpaces();

            CriteriaJoinWalker walker =
                new CriteriaJoinWalker(persister, translator, factory, rootCriteria, rootEntityName, enabledFilters);

            InitFromWalker(walker);

            _uncacheableCollectionPersisters = translator.UncacheableCollectionPersisters;
            userAliases               = walker.UserAliases;
            ResultTypes               = walker.ResultTypes;
            includeInResultRow        = walker.IncludeInResultRow;
            resultRowLength           = ArrayHelper.CountTrue(IncludeInResultRow);
            childFetchEntities        = walker.ChildFetchEntities;
            EntityFetchLazyProperties = walker.EntityFetchLazyProperties;
            // fill caching objects only if there is a projection
            if (translator.HasProjection)
            {
                cachedProjectedColumnAliases = translator.ProjectedColumnAliases;
            }

            PostInstantiate();
        }
		public AbstractEntityJoinWalker(string rootSqlAlias, IOuterJoinLoadable persister, ISessionFactoryImplementor factory,
																		IDictionary<string, IFilter> enabledFilters)
			: base(factory, enabledFilters)
		{
			this.persister = persister;
			alias = rootSqlAlias;
		}
 public AbstractEntityJoinWalker(string rootSqlAlias, IOuterJoinLoadable persister, ISessionFactoryImplementor factory,
                                 IDictionary <string, IFilter> enabledFilters)
     : base(factory, enabledFilters)
 {
     this.persister = persister;
     alias          = rootSqlAlias;
 }
Example #18
0
 /// <summary>
 /// Get the aliased columns of the owning entity which are to 
 /// be used in the join
 /// </summary>
 public static string[] GetAliasedLHSColumnNames(
     IAssociationType type,
     string alias,
     int property,
     int begin,
     IOuterJoinLoadable lhsPersister,
     IMapping mapping
     )
 {
     if (type.UseLHSPrimaryKey)
     {
         return StringHelper.Qualify(alias, lhsPersister.IdentifierColumnNames);
     }
     else
     {
         string propertyName = type.LHSPropertyName;
         if (propertyName == null)
         {
             return ArrayHelper.Slice(
                 lhsPersister.ToColumns(alias, property),
                 begin,
                 type.GetColumnSpan(mapping)
                 );
         }
         else
         {
             return ((IPropertyMapping) lhsPersister).ToColumns(alias, propertyName); //bad cast
         }
     }
 }
Example #19
0
        /// <summary>
        /// For an entity class, return a list of associations to be fetched by outerjion
        /// </summary>
        /// <param name="persister"></param>
        /// <param name="alias"></param>
        /// <param name="factory"></param>
        /// <returns></returns>
        public IList WalkTree(IOuterJoinLoadable persister, string alias, ISessionFactoryImplementor factory)
        {
            IList associations = new ArrayList();

            WalkClassTree(persister, alias, associations, new HashedSet(), string.Empty, 0, factory);
            return(associations);
        }
 public AbstractEntityJoinWalker(IOuterJoinLoadable persister, ISessionFactoryImplementor factory,
                                 IDictionary <string, IFilter> enabledFilters)
     : base(factory, enabledFilters)
 {
     this.persister = persister;
     alias          = GenerateRootAlias(persister.EntityName);
 }
Example #21
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            ISessionFactoryImplementor factory = criteriaQuery.Factory;

            var innerQuery = new CriteriaQueryTranslator(
                factory,
                criteriaImpl,                 //implicit polymorphism not supported (would need a union)
                criteriaImpl.EntityOrClassName,
                criteriaQuery.GenerateSQLAlias(),
                criteriaQuery);

            types = innerQuery.HasProjection ? innerQuery.ProjectedTypes : null;

            if (innerQuery.HasProjection == false)
            {
                throw new QueryException("Cannot use subqueries on a criteria without a projection.");
            }

            IOuterJoinLoadable persister = (IOuterJoinLoadable)factory.GetEntityPersister(criteriaImpl.EntityOrClassName);

            //patch to generate joins on subqueries
            //stolen from CriteriaLoader
            CriteriaJoinWalker walker =
                new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.EntityOrClassName, enabledFilters);

            parameters = innerQuery.GetQueryParameters();             // parameters can be inferred only after initialize the walker

            SqlString sql = walker.SqlString;

            if (criteriaImpl.FirstResult != 0 || criteriaImpl.MaxResults != RowSelection.NoValue)
            {
                int?      offset          = Loader.Loader.GetOffsetUsingDialect(parameters.RowSelection, factory.Dialect);
                int?      limit           = Loader.Loader.GetLimitUsingDialect(parameters.RowSelection, factory.Dialect);
                Parameter offsetParameter = offset.HasValue ? innerQuery.CreateSkipParameter(offset.Value) : null;
                Parameter limitParameter  = limit.HasValue ? innerQuery.CreateTakeParameter(limit.Value) : null;
                sql = factory.Dialect.GetLimitString(sql, offset, limit, offsetParameter, limitParameter);
            }

            SqlStringBuilder buf = new SqlStringBuilder().Add(ToLeftSqlString(criteria, criteriaQuery));

            if (op != null)
            {
                buf.Add(" ").Add(op).Add(" ");
            }

            if (quantifier != null && prefixOp)
            {
                buf.Add(quantifier).Add(" ");
            }

            buf.Add("(").Add(sql).Add(")");

            if (quantifier != null && prefixOp == false)
            {
                buf.Add(" ").Add(quantifier);
            }

            return(buf.ToSqlString());
        }
		public EntityLoader(
			IOuterJoinLoadable persister,
			LockMode lockMode,
			ISessionFactoryImplementor factory,
			IDictionary enabledFilters)
			: this(persister, 1, lockMode, factory, enabledFilters)
		{
		}
Example #23
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            InitializeInnerQueryAndParameters(criteriaQuery);

            if (innerQuery.HasProjection == false)
            {
                throw new QueryException("Cannot use subqueries on a criteria without a projection.");
            }

            ISessionFactoryImplementor factory = criteriaQuery.Factory;

            IOuterJoinLoadable persister = (IOuterJoinLoadable)factory.GetEntityPersister(criteriaImpl.EntityOrClassName);

            //patch to generate joins on subqueries
            //stolen from CriteriaLoader
            CriteriaJoinWalker walker =
                new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.EntityOrClassName, enabledFilters);

            parameters = innerQuery.GetQueryParameters();             // parameters can be inferred only after initialize the walker

            SqlString sql = walker.SqlString;

            if (criteriaImpl.FirstResult != 0 || criteriaImpl.MaxResults != RowSelection.NoValue)
            {
                int?      offset          = Loader.Loader.GetOffsetUsingDialect(parameters.RowSelection, factory.Dialect);
                int?      limit           = Loader.Loader.GetLimitUsingDialect(parameters.RowSelection, factory.Dialect);
                Parameter offsetParameter = offset.HasValue ? innerQuery.CreateSkipParameter(offset.Value) : null;
                Parameter limitParameter  = limit.HasValue ? innerQuery.CreateTakeParameter(limit.Value) : null;
                sql = factory.Dialect.GetLimitString(sql, offset, limit, offsetParameter, limitParameter);
            }

            // during CriteriaImpl.Clone we are doing a shallow copy of each criterion.
            // this is not a problem for common criterion but not for SubqueryExpression because here we are holding the state of inner CriteriaTraslator (ICriteriaQuery).
            // After execution (ToSqlString) we have to clean the internal state because the next execution may be performed in a different tree reusing the same istance of SubqueryExpression.
            innerQuery = null;

            SqlStringBuilder buf = new SqlStringBuilder().Add(ToLeftSqlString(criteria, criteriaQuery));

            if (op != null)
            {
                buf.Add(" ").Add(op).Add(" ");
            }

            if (quantifier != null && prefixOp)
            {
                buf.Add(quantifier).Add(" ");
            }

            buf.Add("(").Add(sql).Add(")");

            if (quantifier != null && prefixOp == false)
            {
                buf.Add(" ").Add(quantifier);
            }

            return(buf.ToSqlString());
        }
Example #24
0
 /// <summary>
 /// Get the columns of the owning entity which are to 
 /// be used in the join
 /// </summary>
 public static string[] GetLHSColumnNames(
     IAssociationType type,
     int property,
     IOuterJoinLoadable lhsPersister,
     IMapping mapping
     )
 {
     return GetLHSColumnNames(type, property, 0, lhsPersister, mapping);
 }
        public CriteriaLoader(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl criteria)
            : base(persister, factory)
        {
            this.criteria = criteria;

            AddAllToPropertySpaces(persister.PropertySpaces);

            resultTypes    = new IType[1];
            resultTypes[0] = NHibernateUtil.Entity(persister.MappedClass);

            SqlStringBuilder condition = new SqlStringBuilder(10);

            bool foundCriterion = false;

            foreach (CriteriaImpl.CriterionEntry ee in criteria.IterateExpressionEntries())
            {
                if (foundCriterion)
                {
                    condition.Add(" and ");
                }

                SqlString sqlString = ee.Criterion.ToSqlString(
                    factory,
                    criteria.GetPersistentClass(ee.Alias),
                    ee.Alias,
                    criteria.AliasClasses);
                condition.Add(sqlString);

                foundCriterion = true;
            }

            if (!foundCriterion)
            {
                condition.Add("1=1");                   // TODO: fix this ugliness
            }

            StringBuilder orderBy    = new StringBuilder(30);
            bool          foundOrder = false;

            foreach (Order ord in criteria.IterateOrderings())
            {
                if (foundOrder)
                {
                    orderBy.Append(StringHelper.CommaSpace);
                }
                orderBy.Append(ord.ToSqlString(factory, criteria.CriteriaClass, Alias));
                foundOrder = true;
            }

            IList associations = WalkTree(persister, Alias, factory);

            InitClassPersisters(associations);
            InitStatementString(associations, condition.ToSqlString(), orderBy.ToString(), factory);

            PostInstantiate();
        }
Example #26
0
        /// <summary>
        /// Is this an association that we cannot possibly load by outer
        /// join, no matter what the mapping or subclass specifies?
        /// </summary>
        /// <param name="persister"></param>
        /// <param name="type"></param>
        /// <param name="propertyNumber"></param>
        /// <returns></returns>
        private bool IsJoinedFetchAlwaysDisabled(IOuterJoinLoadable persister, IAssociationType type, int propertyNumber)
        {
            //NOTE: workaround for problem with 1-to-1 defined on a subclass "accidently" picking up an object
            //TODO: really, this should use the "key" columns of the subclass table, then we don't need this check!
            //      (I *think*)

            return(type.IsEntityType &&
                   ((EntityType)type).IsOneToOne &&
                   persister.IsDefinedOnSubclass(propertyNumber));
        }
		private void WalkCompositeComponentIdTree(IOuterJoinLoadable persister, string alias, string path)
		{
			IType type = persister.IdentifierType;
			string propertyName = persister.IdentifierPropertyName;
			if (type != null && type.IsComponentType && !(type is EmbeddedComponentType))
			{
				ILhsAssociationTypeSqlInfo associationTypeSQLInfo = JoinHelper.GetIdLhsSqlInfo(alias, persister, Factory);
				WalkComponentTree((IAbstractComponentType)type, 0, alias, SubPath(path, propertyName), 0, associationTypeSQLInfo);
			}
		}
Example #28
0
        public CascadeEntityLoader(IOuterJoinLoadable persister, CascadingAction action, ISessionFactoryImplementor factory)
            : base(persister, persister.IdentifierType, factory, new CollectionHelper.EmptyMapClass<string, IFilter>())
        {
            JoinWalker walker = new CascadeEntityJoinWalker(persister, action, factory);
            InitFromWalker(walker);

            PostInstantiate();

            log.Debug(string.Format("Static select for action {0} on entity {1}: {2}", action, entityName, SqlString));
        }
		public CriteriaLoader( IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl criteria )
			: base( persister, factory )
		{
			this.criteria = criteria;

			AddAllToPropertySpaces( persister.PropertySpaces );

			resultTypes = new IType[ 1 ];
			resultTypes[ 0 ] = NHibernateUtil.Entity( persister.MappedClass );

			SqlStringBuilder condition = new SqlStringBuilder( 10 );

			bool foundCriterion = false;

			foreach( CriteriaImpl.CriterionEntry ee in criteria.IterateExpressionEntries() )
			{
				if( foundCriterion )
				{
					condition.Add( " and " );
				}

				SqlString sqlString = ee.Criterion.ToSqlString(
					factory,
					criteria.GetPersistentClass( ee.Alias ),
					ee.Alias,
					criteria.AliasClasses );
				condition.Add( sqlString );

				foundCriterion = true;
			}

			if( !foundCriterion )
			{
				condition.Add( "1=1" ); // TODO: fix this ugliness
			}

			StringBuilder orderBy = new StringBuilder( 30 );
			bool foundOrder = false;

			foreach( Order ord in criteria.IterateOrderings() )
			{
				if( foundOrder )
				{
					orderBy.Append( StringHelper.CommaSpace );
				}
				orderBy.Append( ord.ToSqlString( factory, criteria.CriteriaClass, Alias ) );
				foundOrder = true;
			}

			IList associations = WalkTree( persister, Alias, factory );
			InitClassPersisters( associations );
			InitStatementString( associations, condition.ToSqlString(), orderBy.ToString(), factory );

			PostInstantiate();
		}
        public CascadeEntityJoinWalker(IOuterJoinLoadable persister, CascadingAction action,
                                       ISessionFactoryImplementor factory)
            : base(persister, factory, CollectionHelper.EmptyDictionary <string, IFilter>())
        {
            cascadeAction = action;
            SqlStringBuilder whereCondition = WhereString(Alias, persister.IdentifierColumnNames, 1)
                                              //include the discriminator and class-level where, but not filters
                                              .Add(persister.FilterFragment(Alias, CollectionHelper.EmptyDictionary <string, IFilter>()));

            InitAll(whereCondition.ToSqlString(), SqlString.Empty, LockMode.Read);
        }
        public CascadeEntityLoader(IOuterJoinLoadable persister, CascadingAction action, ISessionFactoryImplementor factory)
            : base(persister, persister.IdentifierType, factory, CollectionHelper.EmptyDictionary <string, IFilter>())
        {
            JoinWalker walker = new CascadeEntityJoinWalker(persister, action, factory);

            InitFromWalker(walker);

            PostInstantiate();

            log.Debug("Static select for action {0} on entity {1}: {2}", action, entityName, SqlString);
        }
Example #32
0
        private void WalkCompositeComponentIdTree(IOuterJoinLoadable persister, string alias, string path)
        {
            IType  type         = persister.IdentifierType;
            string propertyName = persister.IdentifierPropertyName;

            if (type != null && type.IsComponentType)
            {
                ILhsAssociationTypeSqlInfo associationTypeSQLInfo = JoinHelper.GetIdLhsSqlInfo(alias, persister, Factory);
                WalkComponentTree((IAbstractComponentType)type, 0, alias, SubPath(path, propertyName), 0, associationTypeSQLInfo);
            }
        }
		public CascadeEntityJoinWalker(IOuterJoinLoadable persister, CascadingAction action,
		                               ISessionFactoryImplementor factory)
			: base(persister, factory, new CollectionHelper.EmptyMapClass<string, IFilter>())
		{
			cascadeAction = action;
			SqlStringBuilder whereCondition = WhereString(Alias, persister.IdentifierColumnNames, 1)
				//include the discriminator and class-level where, but not filters
				.Add(persister.FilterFragment(Alias, new CollectionHelper.EmptyMapClass<string, IFilter>()));

			InitAll(whereCondition.ToSqlString(), SqlString.Empty, LockMode.Read);
		}
Example #34
0
 private static string[] GetForeignKeyColumns(IOuterJoinLoadable persister, IAssociationType associationType, string[] propertyColumns)
 {
     if (associationType.UsePrimaryKeyAsForeignKey)
     {
         return(persister.IdentifierColumnNames);
     }
     else
     {
         return(propertyColumns);
     }
 }
		public EntityJoinWalker(IOuterJoinLoadable persister, string[] uniqueKey, int batchSize, LockMode lockMode,
		                        ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters)
			: base(persister, factory, enabledFilters)
		{
			this.lockMode = lockMode;

			SqlStringBuilder whereCondition = WhereString(Alias, uniqueKey, batchSize)
				//include the discriminator and class-level where, but not filters
				.Add(persister.FilterFragment(Alias, new CollectionHelper.EmptyMapClass<string, IFilter>()));

			InitAll(whereCondition.ToSqlString(), SqlString.Empty, lockMode);
		}
Example #36
0
        public EntityJoinWalker(IOuterJoinLoadable persister, string[] uniqueKey, int batchSize, LockMode lockMode,
                                ISessionFactoryImplementor factory, IDictionary <string, IFilter> enabledFilters)
            : base(persister, factory, enabledFilters)
        {
            this.lockMode = lockMode;

            SqlStringBuilder whereCondition = WhereString(Alias, uniqueKey, batchSize)
                                              //include the discriminator and class-level where, but not filters
                                              .Add(persister.FilterFragment(Alias, CollectionHelper.EmptyDictionary <string, IFilter>()));

            InitAll(whereCondition.ToSqlString(), SqlString.Empty, lockMode);
        }
Example #37
0
 private static string[] GetAliasedForeignKeyColumns(IOuterJoinLoadable persister, string alias, IAssociationType associationType, string[] aliasedPropertyColumns)
 {
     if (associationType.UsePrimaryKeyAsForeignKey)
     {
         // a one-to-one association or collection
         return(StringHelper.Qualify(alias, persister.IdentifierColumnNames));
     }
     else
     {
         // a many-to-one association
         return(aliasedPropertyColumns);
     }
 }
Example #38
0
        public override SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            InitializeInnerQueryAndParameters(criteriaQuery);

            if (innerQuery.HasProjection == false)
            {
                throw new QueryException("Cannot use subqueries on a criteria without a projection.");
            }

            ISessionFactoryImplementor factory = criteriaQuery.Factory;

            IOuterJoinLoadable persister = (IOuterJoinLoadable)factory.GetEntityPersister(criteriaImpl.EntityOrClassName);

            //buffer needs to be before CriteriaJoinWalker for sake of parameter order
            SqlStringBuilder buf = new SqlStringBuilder().Add(ToLeftSqlString(criteria, criteriaQuery));

            //patch to generate joins on subqueries
            //stolen from CriteriaLoader
            CriteriaJoinWalker walker =
                new CriteriaJoinWalker(persister, innerQuery, factory, criteriaImpl, criteriaImpl.EntityOrClassName, enabledFilters);

            SqlString sql = walker.SqlString;

            if (criteriaImpl.FirstResult != 0 || criteriaImpl.MaxResults != RowSelection.NoValue)
            {
                int firstResults         = Loader.Loader.GetFirstRow(parameters.RowSelection);
                int maxResults           = Loader.Loader.GetMaxOrLimit(factory.Dialect, parameters.RowSelection);
                int?offsetParameterIndex = criteriaQuery.CreatePagingParameter(firstResults);
                int?limitParameterIndex  = criteriaQuery.CreatePagingParameter(maxResults);
                sql = factory.Dialect.GetLimitString(sql, firstResults, maxResults, offsetParameterIndex, limitParameterIndex);
            }

            if (op != null)
            {
                buf.Add(" ").Add(op).Add(" ");
            }

            if (quantifier != null && prefixOp)
            {
                buf.Add(quantifier).Add(" ");
            }

            buf.Add("(").Add(sql).Add(")");

            if (quantifier != null && prefixOp == false)
            {
                buf.Add(" ").Add(quantifier);
            }

            return(buf.ToSqlString());
        }
        public EntityLoader(IOuterJoinLoadable persister, string[] uniqueKey, IType uniqueKeyType, int batchSize,
                            LockMode lockMode, ISessionFactoryImplementor factory, IDictionary <string, IFilter> enabledFilters)
            : base(persister, uniqueKeyType, factory, enabledFilters)
        {
            JoinWalker walker = new EntityJoinWalker(persister, uniqueKey, batchSize, lockMode, factory, enabledFilters);

            InitFromWalker(walker);

            PostInstantiate();

            batchLoader = batchSize > 1;

            log.Debug("Static select for entity {0}: {1}", entityName, SqlString);
        }
		public EntityLoader( IOuterJoinLoadable persister, string[] uniqueKey, IType uniqueKeyType, int batchSize, ISessionFactoryImplementor factory )
			: base( persister, factory )
		{
			this.uniqueKeyType = uniqueKeyType;

			IList associations = WalkTree( persister, Alias, factory );
			InitClassPersisters( associations );
			SqlString whereString = WhereString( factory, Alias, uniqueKey, uniqueKeyType, batchSize ).ToSqlString();
			RenderStatement( associations, whereString, factory );

			PostInstantiate();

			batchLoader = batchSize > 1;
		}
        private void InitStatementString(
            IQueryableCollection collPersister,
            IOuterJoinLoadable persister,
            string alias,
            IList associations,
            int batchSize,
            ISessionFactoryImplementor factory
            )
        {
            int joins = associations.Count;

            Suffixes = GenerateSuffixes(joins + 1);

            SqlStringBuilder whereSqlString = WhereString(factory, alias, collPersister.KeyColumnNames, collPersister.KeyType, batchSize);

            if (collectionPersister.HasWhere)
            {
                whereSqlString
                .Add(" and ")
                .Add(collectionPersister.GetSQLWhereString(alias));
            }

            JoinFragment ojf = MergeOuterJoins(associations);

            SqlSelectBuilder select = new SqlSelectBuilder(factory)
                                      .SetSelectClause(
                collectionPersister.SelectFragment(alias, Suffixes[joins], true).ToString() +
                SelectString(associations, factory)
                )
                                      .SetFromClause(
                persister.FromTableFragment(alias).Append(
                    persister.FromJoinFragment(alias, true, true)
                    )
                )
                                      .SetWhereClause(whereSqlString.ToSqlString())
                                      .SetOuterJoins(
                ojf.ToFromFragmentString,
                ojf.ToWhereFragmentString.Append(
                    persister.WhereJoinFragment(alias, true, true)
                    )
                );

            if (collectionPersister.HasOrdering)
            {
                select.SetOrderByClause(collectionPersister.GetSQLOrderByString(alias));
            }

            SqlString = select.ToSqlString();
        }
Example #42
0
        public override string SelectFragment(IJoinable rhs, string rhsAlias, string lhsAlias, string entitySuffix,
                                              string collectionSuffix, bool includeCollectionColumns)
        {
            StringBuilder buf = new StringBuilder();

            if (includeCollectionColumns)
            {
                buf.Append(SelectFragment(lhsAlias, collectionSuffix)).Append(StringHelper.CommaSpace);
            }

            IOuterJoinLoadable ojl = (IOuterJoinLoadable)ElementPersister;

            return(buf.Append(ojl.SelectFragment(lhsAlias, entitySuffix))             //use suffix for the entity columns
                   .ToString());
        }
Example #43
0
        private void WalkEntityAssociationTree(IAssociationType associationType, IOuterJoinLoadable persister,
                                               int propertyNumber, string alias, string path, bool nullable, int currentDepth,
                                               ILhsAssociationTypeSqlInfo associationTypeSQLInfo)
        {
            string[] aliasedLhsColumns = associationTypeSQLInfo.GetAliasedColumnNames(associationType, 0);
            string[] lhsColumns        = associationTypeSQLInfo.GetColumnNames(associationType, 0);
            string   lhsTable          = associationTypeSQLInfo.GetTableName(associationType);

            string subpath = SubPath(path, persister.GetSubclassPropertyName(propertyNumber));

            JoinType joinType = GetJoinType(associationType, persister.GetFetchMode(propertyNumber), subpath, lhsTable,
                                            lhsColumns, nullable, currentDepth, persister.GetCascadeStyle(propertyNumber));

            AddAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, subpath, currentDepth, joinType);
        }
Example #44
0
        public override SqlString SelectFragment(string alias, string suffix, bool includeCollectionColumns)
        {
            IOuterJoinLoadable ojl = (IOuterJoinLoadable)ElementPersister;

            if (includeCollectionColumns)
            {
                // Super impl will ignore suffix for collection columns!
                return(SelectFragment(alias).Append(StringHelper.CommaSpace).Append(ojl.SelectFragment(alias, suffix)));
            }
            else
            {
                // Use suffix for the entity columns.
                return(ojl.SelectFragment(alias, suffix));
            }
        }
Example #45
0
		public CollectionElementLoader(IQueryableCollection collectionPersister, ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters)
			: base(factory, enabledFilters)
		{
			keyType = collectionPersister.KeyType;
			indexType = collectionPersister.IndexType;
			persister = (IOuterJoinLoadable)collectionPersister.ElementPersister;
			entityName = persister.EntityName;

			JoinWalker walker = new EntityJoinWalker(persister, ArrayHelper.Join(collectionPersister.KeyColumnNames, collectionPersister.IndexColumnNames), 1, LockMode.None, factory, enabledFilters);
			InitFromWalker(walker);

			PostInstantiate();

			log.Debug("Static select for entity " + entityName + ": " + SqlString);
		}
		public EntityLoader(
			IOuterJoinLoadable persister,
			int batchSize,
			LockMode lockMode,
			ISessionFactoryImplementor factory,
			IDictionary enabledFilters)
			: this(
				persister,
				persister.IdentifierColumnNames,
				persister.IdentifierType,
				batchSize,
				lockMode,
				factory,
				enabledFilters)
		{
		}
        public EntityLoader(IOuterJoinLoadable persister, string[] uniqueKey, IType uniqueKeyType, int batchSize, ISessionFactoryImplementor factory)
            : base(persister, factory)
        {
            this.uniqueKeyType = uniqueKeyType;

            IList associations = WalkTree(persister, Alias, factory);

            InitClassPersisters(associations);
            SqlString whereString = WhereString(factory, Alias, uniqueKey, uniqueKeyType, batchSize).ToSqlString();

            RenderStatement(associations, whereString, factory);

            PostInstantiate();

            batchLoader = batchSize > 1;
        }
        public OneToManyLoader(IQueryableCollection collPersister, int batchSize, ISessionFactoryImplementor factory)
            : base(factory.Dialect)
        {
            collectionPersister = collPersister;
            idType = collectionPersister.KeyType;

            IOuterJoinLoadable persister = ( IOuterJoinLoadable )collPersister.ElementPersister;

            string alias        = GenerateRootAlias(collPersister.Role);
            IList  associations = WalkTree(persister, alias, factory);

            InitStatementString(collPersister, persister, alias, associations, batchSize, factory);
            InitClassPersisters(persister, associations);

            PostInstantiate();
        }
Example #49
0
        /// <summary>
        /// For an entity class, add to a list of associations to be fetched by outerjoin
        /// </summary>
        /// <param name="persister"></param>
        /// <param name="alias"></param>
        /// <param name="associations"></param>
        /// <param name="visitedPersisters"></param>
        /// <param name="path"></param>
        /// <param name="currentDepth"></param>
        /// <param name="factory"></param>
        private void WalkClassTree(
            IOuterJoinLoadable persister,
            string alias,
            IList associations,
            ISet visitedPersisters,
            string path,
            int currentDepth,
            ISessionFactoryImplementor factory)
        {
            int n = persister.CountSubclassProperties();

            for (int i = 0; i < n; i++)
            {
                IType type = persister.GetSubclassPropertyType(i);
                if (type.IsAssociationType)
                {
                    WalkAssociationTree(
                        ( IAssociationType )type,
                        persister,
                        i,
                        alias,
                        associations,
                        visitedPersisters,
                        path,
                        currentDepth,
                        factory
                        );
                }
                else if (type.IsComponentType)
                {
                    WalkComponentTree(
                        ( IAbstractComponentType )type,
                        i,
                        persister.GetSubclassPropertyColumnNames(i),
                        persister.ToColumns(alias, i),
                        persister,
                        alias,
                        associations,
                        visitedPersisters,
                        SubPath(path, persister.GetSubclassPropertyName(i)),
                        currentDepth,
                        factory
                        );
                }
            }
        }
Example #50
0
        private void WalkAssociationTree(
            IAssociationType associationType,
            IOuterJoinLoadable persister,
            int propertyNumber,
            string alias,
            IList associations,
            ISet visitedPersisters,
            string path,
            int currentDepth,
            ISessionFactoryImplementor factory)
        {
            string[] aliasedForeignKeyColumns = GetAliasedForeignKeyColumns(persister, alias, associationType, persister.ToColumns(alias, propertyNumber));
            string[] foreignKeyColumns        = GetForeignKeyColumns(persister, associationType, persister.GetSubclassPropertyColumnNames(propertyNumber));

            if (IsJoinedFetchAlwaysDisabled(persister, associationType, propertyNumber))
            {
                return;
            }

            string   subpath  = SubPath(path, persister.GetSubclassPropertyName(propertyNumber));
            JoinType joinType = GetJoinType(
                associationType,
                persister.EnableJoinedFetch(propertyNumber),
                subpath,
                persister.GetSubclassPropertyTableName(propertyNumber),
                foreignKeyColumns,
                factory
                );

            if (joinType != JoinType.None)
            {
                WalkAssociationTree(
                    associationType,
                    aliasedForeignKeyColumns,
                    persister,
                    alias,
                    associations,
                    visitedPersisters,
                    subpath,
                    currentDepth,
                    joinType,
                    factory
                    );
            }
        }
		public OneToManyJoinWalker(IQueryableCollection oneToManyPersister, int batchSize, SqlString subquery,
		                           ISessionFactoryImplementor factory, IDictionary<string, IFilter> enabledFilters)
			: base(factory, enabledFilters)
		{
			this.oneToManyPersister = oneToManyPersister;
			elementPersister = (IOuterJoinLoadable)oneToManyPersister.ElementPersister;
			string alias = GenerateRootAlias(oneToManyPersister.Role);

			WalkEntityTree(elementPersister, alias);

			IList<OuterJoinableAssociation> allAssociations = new List<OuterJoinableAssociation>(associations);
			allAssociations.Add(
				new OuterJoinableAssociation(oneToManyPersister.CollectionType, null, null, alias, JoinType.LeftOuterJoin, null, Factory,
				                             new CollectionHelper.EmptyMapClass<string, IFilter>()));

			InitPersisters(allAssociations, LockMode.None);
			InitStatementString(elementPersister, alias, batchSize, subquery);
		}
Example #52
0
        public CriteriaLoader(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria,
                              string rootEntityName, IDictionary <string, IFilter> enabledFilters)
            : base(factory, enabledFilters)
        {
            translator = new CriteriaQueryTranslator(factory, rootCriteria, rootEntityName, CriteriaQueryTranslator.RootSqlAlias);

            querySpaces = translator.GetQuerySpaces();

            CriteriaJoinWalker walker =
                new CriteriaJoinWalker(persister, translator, factory, rootCriteria, rootEntityName, enabledFilters);

            InitFromWalker(walker);

            userAliases = walker.UserAliases;
            resultTypes = walker.ResultTypes;

            PostInstantiate();
        }
		public static IUniqueEntityLoader CreateBatchingEntityLoader(IOuterJoinLoadable persister, int maxBatchSize,
																	 LockMode lockMode, ISessionFactoryImplementor factory,
																	 IDictionary<string, IFilter> enabledFilters)
		{
			if (maxBatchSize > 1)
			{
				int[] batchSizesToCreate = ArrayHelper.GetBatchSizes(maxBatchSize);
				Loader[] loadersToCreate = new Loader[batchSizesToCreate.Length];
				for (int i = 0; i < batchSizesToCreate.Length; i++)
				{
					loadersToCreate[i] = new EntityLoader(persister, batchSizesToCreate[i], lockMode, factory, enabledFilters);
				}
				return new BatchingEntityLoader(persister, batchSizesToCreate, loadersToCreate);
			}
			else
			{
				return new EntityLoader(persister, lockMode, factory, enabledFilters);
			}
		}
		private void InitClassPersisters( IOuterJoinLoadable persister, IList associations )
		{
			int joins = associations.Count;
			lockModeArray = CreateLockModeArray( joins + 1, LockMode.None );

			classPersisters = new ILoadable[joins + 1];
			Owners = new int[ joins + 1 ];
			for( int i = 0; i < joins; i++ )
			{
				OuterJoinableAssociation oj = ( OuterJoinableAssociation ) associations[ i ];
				Persisters[ i ] = (ILoadable) oj.Joinable;
				Owners[ i ] = ToOwner( oj, joins, oj.IsOneToOne );
			}
			classPersisters[ joins ] = persister;
			Owners[ joins ] = -1;

			if ( ArrayHelper.IsAllNegative( Owners ) )
			{
				Owners = null;
			}
		}
		public CriteriaJoinWalker(IOuterJoinLoadable persister, CriteriaQueryTranslator translator,
		                          ISessionFactoryImplementor factory, ICriteria criteria, string rootEntityName,
		                          IDictionary<string, IFilter> enabledFilters)
			: base(translator.RootSQLAlias, persister, factory, enabledFilters)
		{
			this.translator = translator;

			querySpaces = translator.GetQuerySpaces();

			if (translator.HasProjection)
			{
				InitProjection(
					translator.GetSelect(enabledFilters),
					translator.GetWhereCondition(enabledFilters),
					translator.GetOrderBy(),
					translator.GetGroupBy(),
					translator.GetHavingCondition(enabledFilters),
					enabledFilters, 
					LockMode.None);

				resultTypes = translator.ProjectedTypes;
				userAliases = translator.ProjectedAliases;
				includeInResultRow = new bool[resultTypes.Length];
				ArrayHelper.Fill(IncludeInResultRow, true);
			}
			else
			{
				InitAll(translator.GetWhereCondition(enabledFilters), translator.GetOrderBy(), LockMode.None);

				resultTypes = new IType[] { TypeFactory.ManyToOne(persister.EntityName) };

				// root entity comes last
				userAliasList.Add(criteria.Alias); //root entity comes *last*
				resultTypeList.Add(translator.ResultType(criteria));
				includeInResultRowList.Add(true);
				userAliases = userAliasList.ToArray();
				resultTypes = resultTypeList.ToArray();
				includeInResultRow = includeInResultRowList.ToArray();
			}
		}
Example #56
0
		/// <summary>
		/// For an entity class, add to a list of associations to be fetched
		/// by outerjoin
		/// </summary>
		protected virtual void WalkEntityTree(IOuterJoinLoadable persister, string alias, string path, int currentDepth)
		{
			int n = persister.CountSubclassProperties();
			for (int i = 0; i < n; i++)
			{
				IType type = persister.GetSubclassPropertyType(i);
				ILhsAssociationTypeSqlInfo associationTypeSQLInfo = JoinHelper.GetLhsSqlInfo(alias, i, persister, Factory);
				if (type.IsAssociationType)
				{
					WalkEntityAssociationTree((IAssociationType) type, persister, i, alias, path,
					                          persister.IsSubclassPropertyNullable(i), currentDepth, associationTypeSQLInfo);
				}
				else if (type.IsComponentType)
				{
					WalkComponentTree((IAbstractComponentType) type, 0, alias, SubPath(path, persister.GetSubclassPropertyName(i)),
					                  currentDepth, associationTypeSQLInfo);
				}
			}
		}
Example #57
0
		private void WalkEntityAssociationTree(IAssociationType associationType, IOuterJoinLoadable persister,
		                                       int propertyNumber, string alias, string path, bool nullable, int currentDepth,
		                                       ILhsAssociationTypeSqlInfo associationTypeSQLInfo)
		{
			string[] aliasedLhsColumns = associationTypeSQLInfo.GetAliasedColumnNames(associationType, 0);
			string[] lhsColumns = associationTypeSQLInfo.GetColumnNames(associationType, 0);
			string lhsTable = associationTypeSQLInfo.GetTableName(associationType);

			string subpath = SubPath(path, persister.GetSubclassPropertyName(propertyNumber));

			JoinType joinType = GetJoinType(associationType, persister.GetFetchMode(propertyNumber), subpath, lhsTable,
			                                lhsColumns, nullable, currentDepth, persister.GetCascadeStyle(propertyNumber));

			AddAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, subpath, currentDepth, joinType);
		}
Example #58
0
		/// <summary>
		/// For a component, add to a list of associations to be fetched by outerjoin
		/// </summary>
		private void WalkComponentTree(IAbstractComponentType componentType, int propertyNumber, int begin,
			IOuterJoinLoadable persister, string alias, string path, int currentDepth)
		{
			IType[] types = componentType.Subtypes;
			string[] propertyNames = componentType.PropertyNames;
			for (int i = 0; i < types.Length; i++)
			{
				if (types[i].IsAssociationType)
				{
					IAssociationType associationType = (IAssociationType)types[i];
					string[] aliasedLhsColumns =
						JoinHelper.GetAliasedLHSColumnNames(associationType, alias, propertyNumber, begin, persister, Factory);

					string[] lhsColumns = JoinHelper.GetLHSColumnNames(associationType, propertyNumber, begin, persister, Factory);
					string lhsTable = JoinHelper.GetLHSTableName(associationType, propertyNumber, persister);

					string subpath = SubPath(path, propertyNames[i]);
					bool[] propertyNullability = componentType.PropertyNullability;

					JoinType joinType =
						GetJoinType(associationType, componentType.GetFetchMode(i), subpath, lhsTable, lhsColumns,
												propertyNullability == null || propertyNullability[i], currentDepth, componentType.GetCascadeStyle(i));

					AddAssociationToJoinTreeIfNecessary(associationType, aliasedLhsColumns, alias, subpath, currentDepth, joinType);
				}
				else if (types[i].IsComponentType)
				{
					string subpath = SubPath(path, propertyNames[i]);

					WalkComponentTree((IAbstractComponentType)types[i], propertyNumber, begin, persister, alias, subpath, currentDepth);
				}
				begin += types[i].GetColumnSpan(Factory);
			}
		}
Example #59
0
		/// <summary>
		/// For an entity class, return a list of associations to be fetched by outerjoin
		/// </summary>
		protected void WalkEntityTree(IOuterJoinLoadable persister, string alias)
		{
			WalkEntityTree(persister, alias, string.Empty, 0);
		}
		public EntityLoader( IOuterJoinLoadable persister, int batchSize, ISessionFactoryImplementor factory )
			: this( persister, persister.IdentifierColumnNames, persister.IdentifierType, batchSize, factory )
		{
		}