예제 #1
0
        public JoinSequence GetFromPart()
        {
            JoinSequence fromPart = new JoinSequence(factory);

            fromPart.joins.AddRange(this.joins);
            fromPart.useThetaStyle = this.useThetaStyle;
            fromPart.rootAlias     = this.rootAlias;
            fromPart.rootJoinable  = this.rootJoinable;
            fromPart.selector      = this.selector;
            fromPart.next          = this.next == null ? null : this.next.GetFromPart();
            fromPart.isFromPart    = true;
            return(fromPart);
        }
예제 #2
0
        public JoinSequence Copy()
        {
            JoinSequence copy = new JoinSequence(factory);

            copy.joins.AddRange(this.joins);
            copy.useThetaStyle = this.useThetaStyle;
            copy.rootAlias     = this.rootAlias;
            copy.rootJoinable  = this.rootJoinable;
            copy.selector      = this.selector;
            copy.next          = this.next == null ? null : this.next.Copy();
            copy.isFromPart    = this.isFromPart;
            copy.conditions.Add(this.conditions.ToSqlString());
            return(copy);
        }
		public static string CreateCollectionSubquery(
			JoinSequence joinSequence,
			IDictionary 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);
			}
		}
예제 #4
0
		public void AddFromJoinOnly(string name, JoinSequence joinSequence)
		{
			AddJoin(name, joinSequence.GetFromPart());
		}
예제 #5
0
		internal void AddFrom(string name, string type, JoinSequence joinSequence)
		{
			AddType(name, type);
			AddFrom(name, joinSequence);
		}
예제 #6
0
		/// <remarks>Used for collection filters</remarks>
		protected void AddFromAssociation(string elementName, string collectionRole)
		{
			//q.addCollection(collectionName, collectionRole);
			IType collectionElementType = GetCollectionPersister(collectionRole).ElementType;
			if (!collectionElementType.IsEntityType)
			{
				throw new QueryException("collection of values in filter: " + elementName);
			}

			IQueryableCollection persister = GetCollectionPersister(collectionRole);
			string[] keyColumnNames = persister.KeyColumnNames;
			//if (keyColumnNames.Length!=1) throw new QueryException("composite-key collecion in filter: " + collectionRole);

			string collectionName;
			JoinSequence join = new JoinSequence(Factory);
			collectionName = persister.IsOneToMany ? elementName : CreateNameForCollection(collectionRole);
			join.SetRoot(persister, collectionName);
			if (!persister.IsOneToMany)
			{
				//many-to-many
				AddCollection(collectionName, collectionRole);

				try
				{
					join.AddJoin(
						(IAssociationType) persister.ElementType,
						elementName,
						JoinType.InnerJoin,
						persister.GetElementColumnNames(collectionName));
				}
				catch (MappingException me)
				{
					throw new QueryException(me);
				}
			}
			join.AddCondition(collectionName, keyColumnNames, " = ", true);
			EntityType elmType = (EntityType) collectionElementType;
			AddFrom(elementName, elmType.GetAssociatedEntityName(), join);
		}
예제 #7
0
		internal void AddPathAliasAndJoin(string path, string alias, JoinSequence joinSequence)
		{
			pathAliases.Add(path, alias);
			pathJoins.Add(path, joinSequence);
		}
		private FromElement CreateCollectionJoin(JoinSequence collectionJoinSequence, string tableAlias)
		{
			string text = _queryableCollection.TableName;
			IASTNode ast = CreateFromElement(text);
			FromElement destination = (FromElement)ast;
			IType elementType = _queryableCollection.ElementType;

			if (elementType.IsCollectionType)
			{
				throw new SemanticException("Collections of collections are not supported!");
			}

			destination.InitializeCollection(_fromClause, _classAlias, tableAlias);
			destination.Type = HqlSqlWalker.JOIN_FRAGMENT;		// Tag this node as a JOIN.
			destination.SetIncludeSubclasses(false);	// Don't include subclasses in the join.
			destination.CollectionJoin = true;		// This is a clollection join.
			destination.JoinSequence = collectionJoinSequence;
			destination.SetOrigin(_origin, false);
			destination.CollectionTableAlias = tableAlias;
			//		origin.addDestination( destination );
			// This was the cause of HHH-242
			//		origin.setType( FROM_FRAGMENT );			// Set the parent node type so that the AST is properly formed.
			_origin.Text = "";						// The destination node will have all the FROM text.
			_origin.CollectionJoin = true;			// The parent node is a collection join too (voodoo - see JoinProcessor)
			_fromClause.AddCollectionJoinFromElementByPath(_path, destination);
			_fromClause.Walker.AddQuerySpaces(_queryableCollection.CollectionSpaces);
			return destination;
		}
예제 #9
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);
			}
		}
예제 #10
0
		internal void AddFromClass(string name, IQueryable classPersister)
		{
			JoinSequence joinSequence = new JoinSequence(Factory)
				.SetRoot(classPersister, name);
			AddFrom(name, classPersister.EntityName, joinSequence);
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="q"></param>
		public void Start(QueryTranslator q)
		{
			if (!continuation)
			{
				Reset(q);
				path.Length = 0;
				joinSequence = new JoinSequence(q.Factory).SetUseThetaStyle(useThetaStyleJoin);
			}
		}
예제 #12
0
 public JoinSequence SetNext(JoinSequence next)
 {
     this.next = next;
     return(this);
 }
예제 #13
0
		internal void AddFromCollection(string name, string collectionRole, JoinSequence joinSequence)
		{
			//register collection role
			AddCollection(name, collectionRole);
			AddJoin(name, joinSequence);
		}
		private FromElement CreateJoin(
						string entityClass,
						string tableAlias,
						JoinSequence joinSequence,
						EntityType type,
						bool manyToMany)
		{
			//  origin, path, implied, columns, classAlias,
			IEntityPersister entityPersister = _fromClause.SessionFactoryHelper.RequireClassPersister(entityClass);
			FromElement destination = CreateAndAddFromElement(entityClass,
							_classAlias,
							entityPersister,
							type,
							tableAlias);
			return InitializeJoin(_path, destination, joinSequence, Columns, _origin, manyToMany);
		}
예제 #15
0
		public JoinSequence GetFromPart()
		{
			JoinSequence fromPart = new JoinSequence(factory);
			fromPart.joins.AddRange(this.joins);
			fromPart.useThetaStyle = this.useThetaStyle;
			fromPart.rootAlias = this.rootAlias;
			fromPart.rootJoinable = this.rootJoinable;
			fromPart.selector = this.selector;
			fromPart.next = this.next == null ? null : this.next.GetFromPart();
			fromPart.isFromPart = true;
			return fromPart;
		}
예제 #16
0
		public JoinSequence SetNext(JoinSequence next)
		{
			this.next = next;
			return this;
		}
예제 #17
0
		public JoinSequence Copy()
		{
			JoinSequence copy = new JoinSequence(factory);
			copy.joins.AddRange(this.joins);
			copy.useThetaStyle = this.useThetaStyle;
			copy.rootAlias = this.rootAlias;
			copy.rootJoinable = this.rootJoinable;
			copy.selector = this.selector;
			copy.next = this.next == null ? null : this.next.Copy();
			copy.isFromPart = this.isFromPart;
			copy.conditions.Add(this.conditions.ToSqlString());
			return copy;
		}
		private FromElement InitializeJoin(
						string path,
						FromElement destination,
						JoinSequence joinSequence,
						string[] columns,
						FromElement origin,
						bool manyToMany)
		{
			destination.Type = HqlSqlWalker.JOIN_FRAGMENT;
			destination.JoinSequence = joinSequence;
			destination.Columns = columns;
			destination.SetOrigin(origin, manyToMany);
			_fromClause.AddJoinByPathMap(path, destination);
			return destination;
		}
예제 #19
0
		internal void AddFrom(string name, JoinSequence joinSequence)
		{
			fromTypes.Add(name);
			AddJoin(name, joinSequence);
		}
예제 #20
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 || SqlStringHelper.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
			);
		}
예제 #21
0
		internal void AddJoin(string name, JoinSequence joinSequence)
		{
			if (!joins.ContainsKey(name))
			{
				joins.Add(name, joinSequence);
			}
		}
예제 #22
0
		private static SqlString ProcessFromFragment(SqlString frag, JoinSequence join) 
		{
			SqlString fromFragment = frag.Trim();
			// The FROM fragment will probably begin with ', '.  Remove this if it is present.
			if ( fromFragment.StartsWithCaseInsensitive( ", " ) ) {
				fromFragment = fromFragment.Substring( 2 );
			}
			return fromFragment;
		}
		private void PrepareForIndex(QueryTranslator q)
		{
			IQueryableCollection collPersister = q.GetCollectionPersister(collectionRole);

			if (!collPersister.HasIndex)
			{
				throw new QueryException("unindexed collection before []");
			}
			string[] indexCols = collPersister.IndexColumnNames;
			if (indexCols.Length != 1)
			{
				throw new QueryException("composite-index appears in []: " + path);
			}

			JoinSequence fromJoins = new JoinSequence(q.Factory)
				.SetUseThetaStyle(useThetaStyleJoin)
				.SetRoot(collPersister, collectionName)
				.SetNext(joinSequence.Copy());

			if (!continuation)
			{
				AddJoin(collectionName, collPersister.CollectionType);
			}
			joinSequence.AddCondition(new SqlString(collectionName + '.' + indexCols[0] + " = "));

			CollectionElement elem = new CollectionElement();
			elem.ElementColumns = collPersister.GetElementColumnNames(collectionName);
			elem.Type = collPersister.ElementType;
			elem.IsOneToMany = collPersister.IsOneToMany;
			elem.Alias = collectionName;
			elem.JoinSequence = joinSequence;
			collectionElements.Add(elem); //addlast
			SetExpectingCollectionIndex();

			q.AddCollection(collectionName, collectionRole);
			q.AddJoin(collectionName, fromJoins);
		}
		public FromElement CreateEntityJoin(
				string entityClass,
				string tableAlias,
				JoinSequence joinSequence,
				bool fetchFlag,
				bool inFrom,
				EntityType type)
		{
			FromElement elem = CreateJoin(entityClass, tableAlias, joinSequence, type, false);
			elem.Fetch = fetchFlag;

			//if (numberOfTables > 1 && _implied && !elem.UseFromFragment)
			// NH Different behavior: numberOfTables was removed because an
			// implicit join is an implicit join even if it not come from a
			// multi-table entity
			if (_implied && !elem.UseFromFragment)
			{
				if (Log.IsDebugEnabled)
				{
					Log.Debug("createEntityJoin() : Implied entity join");
				}
				elem.UseFromFragment = true;
			}

			// If this is an implied join in a FROM clause, then use ANSI-style joining, and set the
			// flag on the FromElement that indicates that it was implied in the FROM clause itself.
			if (_implied && inFrom)
			{
				joinSequence.SetUseThetaStyle(false);
				elem.UseFromFragment = true;
				elem.SetImpliedInFromClause(true);
			}
			if (elem.Walker.IsSubQuery)
			{
				// two conditions where we need to transform this to a theta-join syntax:
				//      1) 'elem' is the "root from-element" in correlated subqueries
				//      2) The DotNode.useThetaStyleImplicitJoins has been set to true
				//          and 'elem' represents an implicit join
				if (elem.FromClause != elem.Origin.FromClause || DotNode.UseThetaStyleImplicitJoins)
				{
					// the "root from-element" in correlated subqueries do need this piece
					elem.Type = HqlSqlWalker.FROM_FRAGMENT;
					joinSequence.SetUseThetaStyle(true);
					elem.UseFromFragment = false;
				}
			}

			return elem;
		}