예제 #1
0
 public string RenderCollectionSelectFragment(int size, int k)
 {
     if (_queryableCollection == null)
     {
         return("");
     }
     else
     {
         if (_collectionSuffix == null)
         {
             _collectionSuffix = GenerateSuffix(size, k);
         }
         string fragment = _queryableCollection.SelectFragment(CollectionTableAlias, _collectionSuffix);
         return(TrimLeadingCommaAndSpaces(fragment));
     }
 }
        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();
        }
예제 #3
0
        private void InitStatementString(IQueryableCollection persister, string alias, IList associations, int batchSize, ISessionFactoryImplementor factory)
        {
            Suffixes = GenerateSuffixes(associations.Count);

            SqlStringBuilder whereString = WhereString(factory, alias, persister.KeyColumnNames, persister.KeyType, batchSize);

            if (persister.HasWhere)
            {
                whereString
                .Add(" and ")
                .Add(persister.GetSQLWhereString(alias));
            }

            JoinFragment     ojf    = MergeOuterJoins(associations);
            SqlSelectBuilder select = new SqlSelectBuilder(factory)
                                      .SetSelectClause(
                persister.SelectFragment(alias).Append(
                    SelectString(associations, factory)).ToString()
                )
                                      .SetFromClause(persister.TableName, alias)
                                      .SetWhereClause(whereString.ToSqlString())
                                      .SetOuterJoins(
                ojf.ToFromFragmentString,
                ojf.ToWhereFragmentString
                );

            if (persister.HasOrdering)
            {
                select.SetOrderByClause(persister.GetSQLOrderByString(alias));
            }
            SqlString = select.ToSqlString();
        }
예제 #4
0
        private void InitStatementString(string alias, int batchSize, SqlString subquery)
        {
            int joins           = CountEntityPersisters(associations);
            int collectionJoins = CountCollectionPersisters(associations) + 1;

            Suffixes           = BasicLoader.GenerateSuffixes(joins);
            CollectionSuffixes = BasicLoader.GenerateSuffixes(joins, collectionJoins);

            SqlStringBuilder whereString = WhereString(alias, collectionPersister.KeyColumnNames, subquery, batchSize);

            string manyToManyOrderBy = string.Empty;
            string filter            = collectionPersister.FilterFragment(alias, EnabledFilters);

            if (collectionPersister.IsManyToMany)
            {
                // from the collection of associations, locate OJA for the
                // ManyToOne corresponding to this persister to fully
                // define the many-to-many; we need that OJA so that we can
                // use its alias here
                // TODO : is there a better way here?
                IAssociationType associationType = (IAssociationType)collectionPersister.ElementType;
                foreach (OuterJoinableAssociation oja in associations)
                {
                    if (oja.JoinableType == associationType)
                    {
                        // we found it
                        filter            += collectionPersister.GetManyToManyFilterFragment(oja.RHSAlias, EnabledFilters);
                        manyToManyOrderBy += collectionPersister.GetManyToManyOrderByString(oja.RHSAlias);
                    }
                }
            }

            whereString.Insert(0, StringHelper.MoveAndToBeginning(filter));
            JoinFragment ojf = MergeOuterJoins(associations);

            SqlSelectBuilder select =
                new SqlSelectBuilder(Factory)
                .SetSelectClause(collectionPersister.SelectFragment(alias, CollectionSuffixes[0])
                                 + SelectString(associations))
                .SetFromClause(collectionPersister.TableName, alias)
                .SetWhereClause(whereString.ToSqlString())
                .SetOuterJoins(ojf.ToFromFragmentString, ojf.ToWhereFragmentString);

            select.SetOrderByClause(OrderBy(associations, MergeOrderings(collectionPersister.GetSQLOrderByString(alias), manyToManyOrderBy)));

            if (Factory.Settings.IsCommentsEnabled)
            {
                select.SetComment("load collection " + collectionPersister.Role);
            }

            SqlString = select.ToSqlString();
        }
		private void InitStatementString( IQueryableCollection persister, string alias, IList associations, int batchSize, ISessionFactoryImplementor factory )
		{
			Suffixes = GenerateSuffixes( associations.Count );

			SqlStringBuilder whereString = WhereString( factory, alias, persister.KeyColumnNames, persister.KeyType, batchSize );
			if( persister.HasWhere )
			{
				whereString
					.Add( " and " )
					.Add( persister.GetSQLWhereString( alias ) );
			}

			JoinFragment ojf = MergeOuterJoins( associations );
			SqlSelectBuilder select = new SqlSelectBuilder( factory )
				.SetSelectClause(
				persister.SelectFragment( alias ).Append(
					SelectString( associations, factory ) ).ToString()
				)
				.SetFromClause( persister.TableName, alias )
				.SetWhereClause( whereString.ToSqlString() )
				.SetOuterJoins(
				ojf.ToFromFragmentString,
				ojf.ToWhereFragmentString
				);

			if( persister.HasOrdering )
			{
				select.SetOrderByClause( persister.GetSQLOrderByString( alias ) );
			}
			SqlString = select.ToSqlString();
		}