private void InitStatementString(SqlString projection, SqlString condition,
                                         SqlString orderBy, string groupBy, SqlString having, LockMode lockMode)
        {
            int joins = CountEntityPersisters(associations);

            Suffixes = BasicLoader.GenerateSuffixes(joins + 1);
            JoinFragment ojf = MergeOuterJoins(associations);

            SqlString selectClause = projection
                                     ??
                                     new SqlString(persister.SelectFragment(alias, Suffixes[joins]) + SelectString(associations));

            SqlSelectBuilder select = new SqlSelectBuilder(Factory)
                                      .SetLockMode(lockMode)
                                      .SetSelectClause(selectClause)
                                      .SetFromClause(Dialect.AppendLockHint(lockMode, persister.FromTableFragment(alias)) + persister.FromJoinFragment(alias, true, true))
                                      .SetWhereClause(condition)
                                      .SetOuterJoins(ojf.ToFromFragmentString, ojf.ToWhereFragmentString + WhereFragment)
                                      .SetOrderByClause(OrderBy(associations, orderBy))
                                      .SetGroupByClause(groupBy)
                                      .SetHavingClause(having);

            if (Factory.Settings.IsCommentsEnabled)
            {
                select.SetComment(Comment);
            }

            SqlString = select.ToSqlString();
        }
Beispiel #2
0
        protected void InitPersisters(IList <OuterJoinableAssociation> associations, LockMode lockMode)
        {
            int joins       = CountEntityPersisters(associations);
            int collections = CountCollectionPersisters(associations);

            collectionOwners     = collections == 0 ? null : new int[collections];
            collectionPersisters = collections == 0 ? null : new ICollectionPersister[collections];
            collectionSuffixes   = BasicLoader.GenerateSuffixes(joins + 1, collections);

            persisters            = new ILoadable[joins];
            aliases               = new String[joins];
            owners                = new int[joins];
            ownerAssociationTypes = new EntityType[joins];
            lockModeArray         = ArrayHelper.Fill(lockMode, joins);

            int i = 0;
            int j = 0;

            foreach (OuterJoinableAssociation oj in associations)
            {
                if (!oj.IsCollection)
                {
                    persisters[i]            = (ILoadable)oj.Joinable;
                    aliases[i]               = oj.RHSAlias;
                    owners[i]                = oj.GetOwner(associations);
                    ownerAssociationTypes[i] = (EntityType)oj.JoinableType;
                    i++;
                }
                else
                {
                    IQueryableCollection collPersister = (IQueryableCollection)oj.Joinable;

                    if (oj.JoinType == JoinType.LeftOuterJoin)
                    {
                        //it must be a collection fetch
                        collectionPersisters[j] = collPersister;
                        collectionOwners[j]     = oj.GetOwner(associations);
                        j++;
                    }

                    if (collPersister.IsOneToMany)
                    {
                        persisters[i] = (ILoadable)collPersister.ElementPersister;
                        aliases[i]    = oj.RHSAlias;
                        i++;
                    }
                }
            }

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

            if (collectionOwners != null && ArrayHelper.IsAllNegative(collectionOwners))
            {
                collectionOwners = null;
            }
        }
Beispiel #3
0
        protected void InitPersisters(IList <OuterJoinableAssociation> associations, LockMode lockMode)
        {
            int joins       = CountEntityPersisters(associations);
            int collections = CountCollectionPersisters(associations);

            collectionOwners     = collections == 0 ? null : new int[collections];
            collectionPersisters = collections == 0 ? null : new ICollectionPersister[collections];
            collectionSuffixes   = BasicLoader.GenerateSuffixes(joins + 1, collections);

            persisters           = new ILoadable[joins];
            EagerPropertyFetches = new bool[joins];
            ChildFetchEntities   = new bool[joins];
            aliases = new String[joins];
            owners  = new int[joins];
            ownerAssociationTypes = new EntityType[joins];
            lockModeArray         = ArrayHelper.Fill(lockMode, joins);

            int i = 0;
            int j = 0;

            foreach (OuterJoinableAssociation oj in associations)
            {
                if (oj.SelectMode == SelectMode.JoinOnly)
                {
                    continue;
                }

                if (!oj.IsCollection)
                {
                    owners[i] = oj.GetOwner(associations);
                    ownerAssociationTypes[i] = (EntityType)oj.JoinableType;

                    FillEntityPersisterProperties(i, oj, (ILoadable)oj.Joinable);
                    i++;
                }
                else
                {
                    IQueryableCollection collPersister = (IQueryableCollection)oj.Joinable;
                    if (oj.ShouldFetchCollectionPersister())
                    {
                        //it must be a collection fetch
                        collectionPersisters[j] = collPersister;
                        collectionOwners[j]     = oj.GetOwner(associations);
                        j++;
                    }

                    if (collPersister.IsOneToMany)
                    {
                        FillEntityPersisterProperties(i, oj, (ILoadable)collPersister.ElementPersister);
                        i++;
                    }
                }
            }

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

            if (collectionOwners != null && ArrayHelper.IsAllNegative(collectionOwners))
            {
                collectionOwners = null;
            }
        }