public QueryLoader(QueryTranslatorImpl queryTranslator, ISessionFactoryImplementor factory, SelectClause selectClause)
			: base(factory)
		{
			_queryTranslator = queryTranslator;

			Initialize(selectClause);
			PostInstantiate();
		}
Exemple #2
0
        public void ValidateTypes(SelectClause selectClause)
        {
            IType[] selectTypes = selectClause.QueryReturnTypes;

            if (selectTypes.Length != _types.Length)
            {
                throw new QueryException("number of select types did not match those for insert");
            }

            for (int i = 0; i < _types.Length; i++)
            {
                if (!AreCompatible(_types[i], selectTypes[i]))
                {
                    throw new QueryException(
                              "insertion type [" + _types[i] + "] and selection type [" +
                              selectTypes[i] + "] at position " + i + " are not compatible"
                              );
                }
            }

            // otherwise, everything ok.
        }
		private void Initialize(SelectClause selectClause)
		{
			IList<FromElement> fromElementList = selectClause.FromElementsForLoad;

			_hasScalars = selectClause.IsScalarSelect;
			_scalarColumnNames = selectClause.ColumnNames;
			//sqlResultTypes = selectClause.getSqlResultTypes();
			_queryReturnTypes = selectClause.QueryReturnTypes;

			_selectNewTransformer = HolderInstantiator.CreateSelectNewTransformer(selectClause.Constructor, selectClause.IsMap, selectClause.IsList);
			_queryReturnAliases = selectClause.QueryReturnAliases;

			IList<FromElement> collectionFromElements = selectClause.CollectionFromElements;
			if (collectionFromElements != null && collectionFromElements.Count != 0)
			{
				int length = collectionFromElements.Count;
				_collectionPersisters = new IQueryableCollection[length];
				_collectionOwners = new int[length];
				_collectionSuffixes = new string[length];

				for (int i = 0; i < length; i++)
				{
					FromElement collectionFromElement = collectionFromElements[i];
					_collectionPersisters[i] = collectionFromElement.QueryableCollection;
					_collectionOwners[i] = fromElementList.IndexOf(collectionFromElement.Origin);
					//				collectionSuffixes[i] = collectionFromElement.getColumnAliasSuffix();
					//				collectionSuffixes[i] = Integer.toString( i ) + "_";
					_collectionSuffixes[i] = collectionFromElement.CollectionSuffix;
				}
			}

			int size = fromElementList.Count;
			_entityPersisters = new IQueryable[size];
			_entityEagerPropertyFetches = new bool[size];
			_entityAliases = new String[size];
			_sqlAliases = new String[size];
			_sqlAliasSuffixes = new String[size];
			_includeInSelect = new bool[size];
			_owners = new int[size];
			_ownerAssociationTypes = new EntityType[size];

			for (int i = 0; i < size; i++)
			{
				FromElement element = fromElementList[i];
				_entityPersisters[i] = (IQueryable) element.EntityPersister;

				if (_entityPersisters[i] == null)
				{
					throw new InvalidOperationException("No entity persister for " + element);
				}

				_entityEagerPropertyFetches[i] = element.IsAllPropertyFetch;
				_sqlAliases[i] = element.TableAlias;
				_entityAliases[i] = element.ClassAlias;
				_sqlAliasByEntityAlias.Add(_entityAliases[i], _sqlAliases[i]);
				// TODO should we just collect these like with the collections above?
				_sqlAliasSuffixes[i] = (size == 1) ? "" : i + "_";
				//			sqlAliasSuffixes[i] = element.getColumnAliasSuffix();
				_includeInSelect[i] = !element.IsFetch;
				if (_includeInSelect[i])
				{
					_selectLength++;
				}

				_owners[i] = -1; //by default
				if (element.IsFetch)
				{
					if (element.IsCollectionJoin || element.QueryableCollection != null)
					{
						// This is now handled earlier in this method.
					}
					else if (element.DataType.IsEntityType)
					{
						var entityType = (EntityType) element.DataType;
						if (entityType.IsOneToOne)
						{
							_owners[i] = fromElementList.IndexOf(element.Origin);
						}
						_ownerAssociationTypes[i] = entityType;
					}
				}
			}

			//NONE, because its the requested lock mode, not the actual! 
			_defaultLockModes = ArrayHelper.Fill(LockMode.None, size);
		}
		public void ValidateTypes(SelectClause selectClause)
		{
			IType[] selectTypes = selectClause.QueryReturnTypes;

			if (selectTypes.Length != _types.Length)
			{
				throw new QueryException("number of select types did not match those for insert");
			}

			for (int i = 0; i < _types.Length; i++)
			{
				if (!AreCompatible(_types[i], selectTypes[i]))
				{
					throw new QueryException(
							"insertion type [" + _types[i] + "] and selection type [" +
							selectTypes[i] + "] at position " + i + " are not compatible"
					);
				}
			}

			// otherwise, everything ok.
		}
		private void CreateSelectClauseFromFromClause(IASTNode qn)
		{
			// TODO - check this.  Not *exactly* the same logic as the Java original
			qn.InsertChild(0, (IASTNode)adaptor.Create(SELECT_CLAUSE, "{derived select clause}"));

			_selectClause = ( SelectClause ) qn.GetChild(0);
			_selectClause.InitializeDerivedSelectClause( _currentFromClause );

			if ( log.IsDebugEnabled ) 
			{
				log.Debug( "Derived SELECT clause created." );
			}
		}
		private void UseSelectClause(IASTNode select)
		{
			_selectClause = (SelectClause) select;
			_selectClause.InitializeExplicitSelectClause(_currentFromClause);
		}
		public override object Create(IToken payload)
		{
			if (payload == null)
			{
				return base.Create(payload);
			}

			object ret;

			switch (payload.Type)
			{
				case HqlSqlWalker.SELECT:
				case HqlSqlWalker.QUERY:
					ret = new QueryNode(payload);
					break;
				case HqlSqlWalker.UPDATE:
					ret = new UpdateStatement(payload);
					break;
				case HqlSqlWalker.DELETE:
					ret = new DeleteStatement(payload);
					break;
				case HqlSqlWalker.INSERT:
					ret = new InsertStatement(payload);
					break;
				case HqlSqlWalker.INTO:
					ret = new IntoClause(payload);
					break;
				case HqlSqlWalker.FROM:
					ret = new FromClause(payload);
					break;
				case HqlSqlWalker.FROM_FRAGMENT:
					ret = new FromElement(payload);
					break;
				case HqlSqlWalker.IMPLIED_FROM:
					ret = new ImpliedFromElement(payload);
					break;
				case HqlSqlWalker.DOT:
					ret = new DotNode(payload);
					break;
				case HqlSqlWalker.INDEX_OP:
					ret = new IndexNode(payload);
					break;
					// Alias references and identifiers use the same node class.
				case HqlSqlWalker.ALIAS_REF:
				case HqlSqlWalker.IDENT:
					ret = new IdentNode(payload);
					break;
				case HqlSqlWalker.SQL_TOKEN:
					ret = new SqlFragment(payload);
					break;
				case HqlSqlWalker.METHOD_CALL:
					ret = new MethodNode(payload);
					break;
				case HqlSqlWalker.ELEMENTS:
				case HqlSqlWalker.INDICES:
					ret = new CollectionFunction(payload);
					break;
				case HqlSqlWalker.SELECT_CLAUSE:
					ret = new SelectClause(payload);
					break;
				case HqlSqlWalker.SELECT_EXPR:
					ret = new SelectExpressionImpl(payload);
					break;
				case HqlSqlWalker.AGGREGATE:
					ret = new AggregateNode(payload);
					break;
				case HqlSqlWalker.COUNT:
					ret = new CountNode(payload);
					break;
				case HqlSqlWalker.CONSTRUCTOR:
					ret = new ConstructorNode(payload);
					break;
				case HqlSqlWalker.NUM_INT:
				case HqlSqlWalker.NUM_FLOAT:
				case HqlSqlWalker.NUM_LONG:
				case HqlSqlWalker.NUM_DOUBLE:
                case HqlSqlWalker.NUM_DECIMAL:
                case HqlSqlWalker.QUOTED_String:
					ret = new LiteralNode(payload);
					break;
				case HqlSqlWalker.TRUE:
				case HqlSqlWalker.FALSE:
					ret = new BooleanLiteralNode(payload);
					break;
				case HqlSqlWalker.JAVA_CONSTANT:
					ret = new JavaConstantNode(payload);
					break;
				case HqlSqlWalker.ORDER:
					ret = new OrderByClause(payload);
					break;
				case HqlSqlWalker.PLUS:
				case HqlSqlWalker.MINUS:
				case HqlSqlWalker.STAR:
				case HqlSqlWalker.DIV:
				case HqlSqlWalker.BAND:
				case HqlSqlWalker.BOR:
				case HqlSqlWalker.BXOR:
					ret = new BinaryArithmeticOperatorNode(payload);
					break;
				case HqlSqlWalker.UNARY_MINUS:
				case HqlSqlWalker.UNARY_PLUS:
				case HqlSqlWalker.BNOT:
					ret = new UnaryArithmeticNode(payload);
					break;
				case HqlSqlWalker.CASE2:
					ret = new Case2Node(payload);
					break;
				case HqlSqlWalker.CASE:
					ret = new CaseNode(payload);
					break;
				case HqlSqlWalker.PARAM:
				case HqlSqlWalker.NAMED_PARAM:
					ret = new ParameterNode(payload);
					break;
				case HqlSqlWalker.EQ:
				case HqlSqlWalker.NE:
				case HqlSqlWalker.LT:
				case HqlSqlWalker.GT:
				case HqlSqlWalker.LE:
				case HqlSqlWalker.GE:
				case HqlSqlWalker.LIKE:
				case HqlSqlWalker.NOT_LIKE:
					ret = new BinaryLogicOperatorNode(payload);
					break;
				case HqlSqlWalker.IN:
				case HqlSqlWalker.NOT_IN:
					ret = new InLogicOperatorNode(payload);
					break;
				case HqlSqlWalker.BETWEEN:
				case HqlSqlWalker.NOT_BETWEEN:
					ret = new BetweenOperatorNode(payload);
					break;
				case HqlSqlWalker.IS_NULL:
					ret = new IsNullLogicOperatorNode(payload);
					break;
				case HqlSqlWalker.IS_NOT_NULL:
					ret = new IsNotNullLogicOperatorNode(payload);
					break;
				case HqlSqlWalker.EXISTS:
					ret = new UnaryLogicOperatorNode(payload);
					break;
				default:
					ret = new SqlNode(payload);
					break;
			}

			Initialise(ret);
			return ret;
		}
        public override object Create(IToken payload)
        {
            if (payload == null)
            {
                return(base.Create(payload));
            }

            object ret;

            switch (payload.Type)
            {
            case HqlSqlWalker.SELECT:
            case HqlSqlWalker.QUERY:
                ret = new QueryNode(payload);
                break;

            case HqlSqlWalker.UPDATE:
                ret = new UpdateStatement(payload);
                break;

            case HqlSqlWalker.DELETE:
                ret = new DeleteStatement(payload);
                break;

            case HqlSqlWalker.INSERT:
                ret = new InsertStatement(payload);
                break;

            case HqlSqlWalker.INTO:
                ret = new IntoClause(payload);
                break;

            case HqlSqlWalker.FROM:
                ret = new FromClause(payload);
                break;

            case HqlSqlWalker.FROM_FRAGMENT:
                ret = new FromElement(payload);
                break;

            case HqlSqlWalker.IMPLIED_FROM:
                ret = new ImpliedFromElement(payload);
                break;

            case HqlSqlWalker.DOT:
                ret = new DotNode(payload);
                break;

            case HqlSqlWalker.INDEX_OP:
                ret = new IndexNode(payload);
                break;

            // Alias references and identifiers use the same node class.
            case HqlSqlWalker.ALIAS_REF:
            case HqlSqlWalker.IDENT:
                ret = new IdentNode(payload);
                break;

            case HqlSqlWalker.SQL_TOKEN:
                ret = new SqlFragment(payload);
                break;

            case HqlSqlWalker.METHOD_CALL:
                ret = new MethodNode(payload);
                break;

            case HqlSqlWalker.ELEMENTS:
            case HqlSqlWalker.INDICES:
                ret = new CollectionFunction(payload);
                break;

            case HqlSqlWalker.SELECT_CLAUSE:
                ret = new SelectClause(payload);
                break;

            case HqlSqlWalker.SELECT_EXPR:
                ret = new SelectExpressionImpl(payload);
                break;

            case HqlSqlWalker.AGGREGATE:
                ret = new AggregateNode(payload);
                break;

            case HqlSqlWalker.COUNT:
                ret = new CountNode(payload);
                break;

            case HqlSqlWalker.CONSTRUCTOR:
                ret = new ConstructorNode(payload);
                break;

            case HqlSqlWalker.NUM_INT:
            case HqlSqlWalker.NUM_FLOAT:
            case HqlSqlWalker.NUM_LONG:
            case HqlSqlWalker.NUM_DOUBLE:
            case HqlSqlWalker.QUOTED_String:
                ret = new LiteralNode(payload);
                break;

            case HqlSqlWalker.TRUE:
            case HqlSqlWalker.FALSE:
                ret = new BooleanLiteralNode(payload);
                break;

            case HqlSqlWalker.JAVA_CONSTANT:
                ret = new JavaConstantNode(payload);
                break;

            case HqlSqlWalker.ORDER:
                ret = new OrderByClause(payload);
                break;

            case HqlSqlWalker.PLUS:
            case HqlSqlWalker.MINUS:
            case HqlSqlWalker.STAR:
            case HqlSqlWalker.DIV:
            case HqlSqlWalker.BAND:
            case HqlSqlWalker.BOR:
            case HqlSqlWalker.BXOR:
                ret = new BinaryArithmeticOperatorNode(payload);
                break;

            case HqlSqlWalker.UNARY_MINUS:
            case HqlSqlWalker.UNARY_PLUS:
            case HqlSqlWalker.BNOT:
                ret = new UnaryArithmeticNode(payload);
                break;

            case HqlSqlWalker.CASE2:
                ret = new Case2Node(payload);
                break;

            case HqlSqlWalker.CASE:
                ret = new CaseNode(payload);
                break;

            case HqlSqlWalker.PARAM:
            case HqlSqlWalker.NAMED_PARAM:
                ret = new ParameterNode(payload);
                break;

            case HqlSqlWalker.EQ:
            case HqlSqlWalker.NE:
            case HqlSqlWalker.LT:
            case HqlSqlWalker.GT:
            case HqlSqlWalker.LE:
            case HqlSqlWalker.GE:
            case HqlSqlWalker.LIKE:
            case HqlSqlWalker.NOT_LIKE:
                ret = new BinaryLogicOperatorNode(payload);
                break;

            case HqlSqlWalker.IN:
            case HqlSqlWalker.NOT_IN:
                ret = new InLogicOperatorNode(payload);
                break;

            case HqlSqlWalker.BETWEEN:
            case HqlSqlWalker.NOT_BETWEEN:
                ret = new BetweenOperatorNode(payload);
                break;

            case HqlSqlWalker.IS_NULL:
                ret = new IsNullLogicOperatorNode(payload);
                break;

            case HqlSqlWalker.IS_NOT_NULL:
                ret = new IsNotNullLogicOperatorNode(payload);
                break;

            case HqlSqlWalker.EXISTS:
                ret = new UnaryLogicOperatorNode(payload);
                break;

            default:
                ret = new SqlNode(payload);
                break;
            }

            Initialise(ret);
            return(ret);
        }