Exemple #1
0
        public SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary <string, IFilter> enabledFilters)
        {
            string entityName         = criteriaQuery.GetEntityName(criteria, propertyName);
            string actualPropertyName = criteriaQuery.GetPropertyName(propertyName);
            string sqlAlias           = criteriaQuery.GetSQLAlias(criteria, propertyName);

            ISessionFactoryImplementor factory             = criteriaQuery.Factory;
            IQueryableCollection       collectionPersister = GetQueryableCollection(entityName, actualPropertyName, factory);

            string[] collectionKeys = collectionPersister.KeyColumnNames;
            string[] ownerKeys      = ((ILoadable)factory.GetEntityPersister(entityName)).IdentifierColumnNames;

            StringBuilder innerSelect = new StringBuilder();

            innerSelect.Append("(select 1 from ")
            .Append(collectionPersister.TableName)
            .Append(" where ")
            .Append(
                new ConditionalFragment().SetTableAlias(sqlAlias).SetCondition(ownerKeys, collectionKeys).ToSqlStringFragment());
            if (collectionPersister.HasWhere)
            {
                innerSelect.Append(" and (")
                .Append(collectionPersister.GetSQLWhereString(collectionPersister.TableName))
                .Append(") ");
            }

            innerSelect.Append(")");

            return(new SqlString(new string[] { ExcludeEmpty ? "exists" : "not exists", innerSelect.ToString() }));
        }
Exemple #2
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();
        }
        private void DereferenceCollection(String propertyName, String role, QueryTranslator q)
        {
            collectionRole = role;
            IQueryableCollection collPersister = q.GetCollectionPersister(role);

            string[] colNames = collPersister.KeyColumnNames;
            string   name     = q.CreateNameForCollection(role);

            AddJoin(collPersister.TableName, name, colNames);

            if (collPersister.HasWhere)
            {
                join.AddCondition(collPersister.GetSQLWhereString(name));
            }
            collectionName      = name;
            collectionOwnerName = currentName;
            currentName         = name;
            currentProperty     = propertyName;
            componentPath       = null;
            //componentPath = new StringBuilder();
            currentPropertyMapping = new CollectionPropertyMapping(collPersister);
        }
		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();
		}