Esempio n. 1
0
 private void AddJoin(JoinSequence joinSequence, QueryTranslator q)
 {
     q.AddFromJoinOnly(pathExpressionParser.Name, joinSequence);
     try
     {
         AddToCurrentJoin(joinSequence.ToJoinFragment(q.EnabledFilters, true).ToWhereFragmentString);
     }
     catch (MappingException me)
     {
         throw new QueryException(me);
     }
 }
Esempio n. 2
0
        private void AddJoinNodes(QueryNode query, JoinSequence join, FromElement fromElement)
        {
            JoinFragment joinFragment = join.ToJoinFragment(
                _walker.EnabledFilters,
                fromElement.UseFromFragment || fromElement.IsDereferencedBySuperclassOrSubclassProperty,
                fromElement.WithClauseFragment,
                fromElement.WithClauseJoinAlias
                );

            SqlString frag      = joinFragment.ToFromFragmentString;
            SqlString whereFrag = joinFragment.ToWhereFragmentString;

            // If the from element represents a JOIN_FRAGMENT and it is
            // a theta-style join, convert its type from JOIN_FRAGMENT
            // to FROM_FRAGMENT
            if (fromElement.Type == HqlSqlWalker.JOIN_FRAGMENT &&
                (join.IsThetaStyle || StringHelper.IsNotEmpty(whereFrag)))
            {
                fromElement.Type = HqlSqlWalker.FROM_FRAGMENT;
                fromElement.JoinSequence.SetUseThetaStyle(true);                   // this is used during SqlGenerator processing
            }

            // If there is a FROM fragment and the FROM element is an explicit, then add the from part.
            if (fromElement.UseFromFragment /*&& StringHelper.isNotEmpty( frag )*/)
            {
                SqlString fromFragment = ProcessFromFragment(frag, join).Trim();
                if (log.IsDebugEnabled)
                {
                    log.Debug("Using FROM fragment [" + fromFragment + "]");
                }

                ProcessDynamicFilterParameters(
                    fromFragment,
                    fromElement,
                    _walker
                    );
            }

            _syntheticAndFactory.AddWhereFragment(
                joinFragment,
                whereFrag,
                query,
                fromElement,
                _walker
                );
        }
 public static string CreateCollectionSubquery(
     JoinSequence joinSequence,
     IDictionary <string, IFilter> enabledFilters,
     String[] columns)
 {
     try
     {
         JoinFragment join = joinSequence.ToJoinFragment(enabledFilters, true);
         return(new StringBuilder()
                .Append("select ")
                .Append(StringHelper.Join(", ", columns))
                .Append(" from ")
                .Append(join.ToFromFragmentString.Substring(2))                  // remove initial ", "
                .Append(" where ")
                .Append(join.ToWhereFragmentString.Substring(5))                 // remove initial " and "
                .ToString());
     }
     catch (MappingException me)
     {
         throw new QueryException(me);
     }
 }
Esempio n. 4
0
        public void Token(string token, QueryTranslator q)
        {
            if (token != null)
            {
                path.Append(token);
            }

            string alias = q.GetPathAlias(path.ToString());

            if (alias != null)
            {
                Reset(q);                       //reset the dotcount (but not the path)
                currentName            = alias; //after reset!
                currentPropertyMapping = q.GetPropertyMapping(currentName);
                if (!ignoreInitialJoin)
                {
                    JoinSequence ojf = q.GetPathJoin(path.ToString());
                    try
                    {
                        joinSequence.AddCondition(ojf.ToJoinFragment(q.EnabledFilters, true).ToWhereFragmentString);                         //after reset!
                    }
                    catch (MappingException me)
                    {
                        throw new QueryException(me);
                    }
                    // we don't need to worry about any condition in the ON clause
                    // here (toFromFragmentString), since anything in the ON condition
                    // is already applied to the whole query
                }
            }
            else if (".".Equals(token))
            {
                dotcount++;
            }
            else
            {
                if (dotcount == 0)
                {
                    if (!continuation)
                    {
                        if (!q.IsName(token))
                        {
                            throw new QueryException("undefined alias or unknown mapping: " + token);
                        }
                        currentName            = token;
                        currentPropertyMapping = q.GetPropertyMapping(currentName);
                    }
                }
                else if (dotcount == 1)
                {
                    if (currentName != null)
                    {
                        currentProperty = token;
                    }
                    else if (collectionName != null)
                    {
                        //IQueryableCollection p = q.GetCollectionPersister( collectionRole );
                        //DoCollectionProperty( token, p, collectionName );
                        continuation = false;
                    }
                    else
                    {
                        throw new QueryException("unexpected");
                    }
                }
                else
                {
                    // dotcount>=2

                    // Do the corresponding RHS
                    IType propertyType = PropertyType;

                    if (propertyType == null)
                    {
                        throw new QueryException("unresolved property: " + currentProperty);
                    }

                    if (propertyType.IsComponentType)
                    {
                        DereferenceComponent(token);
                    }
                    else if (propertyType.IsEntityType)
                    {
                        DereferenceEntity(token, (EntityType)propertyType, q);
                    }
                    else if (propertyType.IsCollectionType)
                    {
                        DereferenceCollection(token, ((CollectionType)propertyType).Role, q);
                    }
                    else if (token != null)
                    {
                        throw new QueryException("dereferenced: " + currentProperty);
                    }
                }
            }
        }