Exemple #1
0
        private int ResolveAsNakedPropertyRef()
        {
            FromElement fromElement = LocateSingleFromElement();

            if (fromElement == null)
            {
                return(Unknown);
            }

            IQueryable persister = fromElement.Queryable;

            if (persister == null)
            {
                return(Unknown);
            }

            IType propertyType = GetNakedPropertyType(fromElement);

            if (propertyType == null)
            {
                // assume this ident's text does *not* refer to a property on the given persister
                return(Unknown);
            }

            if ((propertyType.IsComponentType || propertyType.IsAssociationType))
            {
                return(ComponentRef);
            }

            FromElement = fromElement;

            string property = Text;

            string[] columns = Walker.IsSelectStatement
                                        ? persister.ToColumns(fromElement.TableAlias, property)
                                        : persister.ToColumns(property);

            string text = string.Join(", ", columns);

            Text = columns.Length == 1 ? text : "(" + text + ")";
            Type = HqlSqlWalker.SQL_TOKEN;

            // these pieces are needed for usage in select clause
            DataType          = propertyType;
            _nakedPropertyRef = true;

            return(PropertyRef);
        }
Exemple #2
0
 public BasicExecutor(IStatement statement, IQueryable persister)
     : base(statement, log)
 {
     this.persister = persister;
     try
     {
         var gen = new SqlGenerator(Factory, new CommonTreeNodeStream(statement));
         gen.statement();
         sql = gen.GetSQL();
         gen.ParseErrorHandler.ThrowQueryException();
         Parameters = gen.GetCollectedParameters();
     }
     catch (RecognitionException e)
     {
         throw QuerySyntaxException.Convert(e);
     }
 }
		public BasicExecutor(IStatement statement, IQueryable persister)
			: base(statement, log)
		{
			this.persister = persister;
			try
			{
				var gen = new SqlGenerator(Factory, new CommonTreeNodeStream(statement));
				gen.statement();
				sql = gen.GetSQL();
				gen.ParseErrorHandler.ThrowQueryException();
				Parameters = gen.GetCollectedParameters();
			}
			catch (RecognitionException e)
			{
				throw QuerySyntaxException.Convert(e);
			}
		}
Exemple #4
0
        private static IStatementExecutor BuildAppropriateStatementExecutor(IStatement statement)
        {
            HqlSqlWalker walker = statement.Walker;

            if (walker.StatementType == HqlSqlWalker.DELETE)
            {
                FromElement fromElement = walker.GetFinalFromClause().GetFromElement();
                IQueryable  persister   = fromElement.Queryable;
                if (persister.IsMultiTable)
                {
                    return(new MultiTableDeleteExecutor(statement));
                }
                else
                {
                    return(new BasicExecutor(statement, persister));
                }
            }
            else if (walker.StatementType == HqlSqlWalker.UPDATE)
            {
                FromElement fromElement = walker.GetFinalFromClause().GetFromElement();
                IQueryable  persister   = fromElement.Queryable;
                if (persister.IsMultiTable)
                {
                    // even here, if only properties mapped to the "base table" are referenced
                    // in the set and where clauses, this could be handled by the BasicDelegate.
                    // TODO : decide if it is better performance-wise to perform that check, or to simply use the MultiTableUpdateDelegate
                    return(new MultiTableUpdateExecutor(statement));
                }
                else
                {
                    return(new BasicExecutor(statement, persister));
                }
            }
            else if (walker.StatementType == HqlSqlWalker.INSERT)
            {
                return(new BasicExecutor(statement, ((InsertStatement)statement).IntoClause.Queryable));
            }
            else
            {
                throw new QueryException("Unexpected statement type");
            }
        }
Exemple #5
0
        public MultiTableDeleteExecutor(IStatement statement)
            : base(statement, log)
        {
            if (!Factory.Dialect.SupportsTemporaryTables)
            {
                throw new HibernateException("cannot perform multi-table deletes using dialect not supporting temp tables");
            }

            var deleteStatement = (DeleteStatement)statement;

            FromElement fromElement     = deleteStatement.FromClause.GetFromElement();
            string      bulkTargetAlias = fromElement.TableAlias;

            persister = fromElement.Queryable;

            idInsertSelect = GenerateIdInsertSelect(persister, bulkTargetAlias, deleteStatement.WhereClause);
            log.Debug("Generated ID-INSERT-SELECT SQL (multi-table delete) : {0}", idInsertSelect);

            string[]   tableNames  = persister.ConstraintOrderedTableNameClosure;
            string[][] columnNames = persister.ConstraintOrderedTableKeyColumnClosure;
            string     idSubselect = GenerateIdSubselect(persister);

            deletes = new SqlString[tableNames.Length];
            for (int i = tableNames.Length - 1; i >= 0; i--)
            {
                // TODO : an optimization here would be to consider cascade deletes and not gen those delete statements;
                //      the difficulty is the ordering of the tables here vs the cascade attributes on the persisters ->
                //          the table info gotten here should really be self-contained (i.e., a class representation
                //          defining all the needed attributes), then we could then get an array of those
                SqlDeleteBuilder delete = new SqlDeleteBuilder(Factory.Dialect, Factory)
                                          .SetTableName(tableNames[i])
                                          .SetWhere("(" + string.Join(", ", columnNames[i]) + ") IN (" + idSubselect + ")");
                if (Factory.Settings.IsCommentsEnabled)
                {
                    delete.SetComment("bulk delete");
                }

                deletes[i] = delete.ToSqlString();
            }
        }
		public MultiTableDeleteExecutor(IStatement statement)
			: base(statement, log)
		{
			if (!Factory.Dialect.SupportsTemporaryTables)
			{
				throw new HibernateException("cannot perform multi-table deletes using dialect not supporting temp tables");
			}

			var deleteStatement = (DeleteStatement) statement;

			FromElement fromElement = deleteStatement.FromClause.GetFromElement();
			string bulkTargetAlias = fromElement.TableAlias;
			persister = fromElement.Queryable;

			idInsertSelect = GenerateIdInsertSelect(persister, bulkTargetAlias, deleteStatement.WhereClause);
			log.Debug("Generated ID-INSERT-SELECT SQL (multi-table delete) : " + idInsertSelect);

			string[] tableNames = persister.ConstraintOrderedTableNameClosure;
			string[][] columnNames = persister.ContraintOrderedTableKeyColumnClosure;
			string idSubselect = GenerateIdSubselect(persister);

			deletes = new SqlString[tableNames.Length];
			for (int i = tableNames.Length - 1; i >= 0; i--)
			{
				// TODO : an optimization here would be to consider cascade deletes and not gen those delete statements;
				//      the difficulty is the ordering of the tables here vs the cascade attributes on the persisters ->
				//          the table info gotten here should really be self-contained (i.e., a class representation
				//          defining all the needed attributes), then we could then get an array of those
				SqlDeleteBuilder delete = new SqlDeleteBuilder(Factory.Dialect, Factory)
					.SetTableName(tableNames[i])
					.SetWhere("(" + StringHelper.Join(", ", columnNames[i]) + ") IN (" + idSubselect + ")");
				if (Factory.Settings.IsCommentsEnabled)
				{
					delete.SetComment("bulk delete");
				}

				deletes[i] = delete.ToSqlString();
			}
		}